Skip to content

Commit 5dea390

Browse files
support protocol version 2.0.0 for callback
1 parent b05d0b6 commit 5dea390

File tree

17 files changed

+97
-728
lines changed

17 files changed

+97
-728
lines changed

.pylintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ good-names=e,ex,f,fp,i,j,k,v,n,_
2222

2323
indent-string=' '
2424
max-line-length=88
25+
26+
[DESIGN]
27+
28+
max-attributes=12

codecov.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
threshold: 5%
6+
7+
patch: false

python/rpdk/typescript/codegen.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(self):
4848
self.package_name = None
4949
self.package_root = None
5050
self._use_docker = True
51+
self._protocol_version = "2.0.0"
5152
self._build_command = None
5253
self._lib_path = None
5354

@@ -59,20 +60,22 @@ def _init_from_project(self, project):
5960
self._build_command = project.settings.get("buildCommand", None)
6061
self._lib_path = project.settings.get("supportLibrary", self.SUPPORT_LIB_URI)
6162

62-
def _prompt_for_use_docker(self, project):
63+
def _init_settings(self, project):
64+
LOG.debug("Writing settings")
6365
self._use_docker = input_with_validation(
6466
"Use docker for platform-independent packaging (Y/n)?\n",
6567
validate_no,
6668
"This is highly recommended unless you are experienced \n"
6769
"with cross-platform Typescript packaging.",
6870
)
6971
project.settings["useDocker"] = self._use_docker
72+
project.settings["protocolVersion"] = self._protocol_version
7073

7174
def init(self, project):
7275
LOG.debug("Init started")
7376

7477
self._init_from_project(project)
75-
self._prompt_for_use_docker(project)
78+
self._init_settings(project)
7679

7780
project.runtime = self.RUNTIME
7881
project.entrypoint = self.ENTRY_POINT

python/rpdk/typescript/data/.npmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
optional = false
1+
optional = true

python/rpdk/typescript/templates/handlers.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
} from '{{lib_name}}';
1313
import { ResourceModel } from './models';
1414

15-
1615
// Use this logger to forward log messages to CloudWatch Logs.
1716
const LOGGER = console;
1817

@@ -44,7 +43,7 @@ class Resource extends BaseResource<ResourceModel> {
4443
if (session instanceof SessionProxy) {
4544
const client = session.client('S3');
4645
}
47-
// Setting Status to success will signal to cfn that the operation is complete
46+
// Setting Status to success will signal to CloudFormation that the operation is complete
4847
progress.status = OperationStatus.Success;
4948
} catch(err) {
5049
LOGGER.log(err);
@@ -98,7 +97,6 @@ class Resource extends BaseResource<ResourceModel> {
9897
const model: ResourceModel = request.desiredResourceState;
9998
const progress: ProgressEvent<ResourceModel> = ProgressEvent.builder()
10099
.status(OperationStatus.InProgress)
101-
.resourceModel(model)
102100
.build() as ProgressEvent<ResourceModel>;
103101
// TODO: put code here
104102
progress.status = OperationStatus.Success;

src/callback.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
export * from './callback';
21
export * as exceptions from './exceptions';
32
export * from './interface';
43
export * from './log-delivery';
54
export * from './metrics';
65
export * from './proxy';
76
export * from './resource';
8-
export * from './scheduler';
97
export * from './utils';

src/interface.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ export class BaseResourceHandlerRequest<T extends BaseModel> {
115115
}
116116

117117
export interface CfnResponse<T> {
118-
bearerToken: string;
119118
errorCode?: HandlerErrorCode;
120-
operationStatus: OperationStatus;
119+
status: OperationStatus;
121120
message: string;
122121
resourceModel?: T;
123122
resourceModels?: T[];

src/proxy.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class ProgressEvent<R extends BaseModel = BaseModel, T = Map<string, any>
9797
return null;
9898
}
9999

100-
public serialize(toTesponse = false, bearerToken?: string): Map<string, any> {
100+
public serialize(): Map<string, any> {
101101
// To match Java serialization, which drops 'null' values, and the
102102
// contract tests currently expect this also.
103103
const json: Map<string, any> = new Map<string, any>(Object.entries(this)); //JSON.parse(JSON.stringify(this)));
@@ -107,26 +107,17 @@ export class ProgressEvent<R extends BaseModel = BaseModel, T = Map<string, any>
107107
}
108108
});
109109
// Mutate to what's expected in the response.
110-
if (toTesponse) {
111-
json.set('bearerToken', bearerToken);
112-
json.set('operationStatus', json.get('status'));
113-
json.delete('status');
114-
if (this.resourceModel) {
115-
json.set('resourceModel', this.resourceModel.toObject());
116-
}
117-
if (this.resourceModels) {
118-
const models = this.resourceModels.map((resource: R) =>
119-
resource.toObject()
120-
);
121-
json.set('resourceModels', models);
122-
}
123-
json.delete('callbackDelaySeconds');
124-
if (json.has('callbackContext')) {
125-
json.delete('callbackContext');
126-
}
127-
if (this.errorCode) {
128-
json.set('errorCode', this.errorCode);
129-
}
110+
if (this.resourceModel) {
111+
json.set('resourceModel', this.resourceModel.toObject());
112+
}
113+
if (this.resourceModels) {
114+
const models = this.resourceModels.map((resource: R) =>
115+
resource.toObject()
116+
);
117+
json.set('resourceModels', models);
118+
}
119+
if (this.errorCode) {
120+
json.set('errorCode', this.errorCode);
130121
}
131122
return json;
132123
}

0 commit comments

Comments
 (0)