Skip to content

Commit 63f638e

Browse files
authored
Add support for Hook Annotations. (#452)
1 parent d5ad0b7 commit 63f638e

File tree

14 files changed

+207
-48
lines changed

14 files changed

+207
-48
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ repos:
4545
hooks:
4646
- id: bandit
4747
files: "^python/"
48+
additional_dependencies: [pbr]
4849
- repo: local
4950
hooks:
5051
- id: pylint-local

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>software.amazon.cloudformation</groupId>
55
<artifactId>aws-cloudformation-rpdk-java-plugin</artifactId>
6-
<version>2.2.3</version>
6+
<version>2.2.4</version>
77
<name>AWS CloudFormation RPDK Java Plugin</name>
88
<description>The CloudFormation Resource Provider Development Kit (RPDK) allows you to author your own resource providers that can be used by CloudFormation. This plugin library helps to provide runtime bindings for the execution of your providers by CloudFormation.
99
</description>

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def find_version(*file_paths):
3636
# package_data -> use MANIFEST.in instead
3737
include_package_data=True,
3838
zip_safe=True,
39-
install_requires=["cloudformation-cli>=0.2.23"],
39+
install_requires=["cloudformation-cli>=0.2.23", "setuptools"],
4040
python_requires=">=3.8",
4141
entry_points={"rpdk.v1.languages": ["java = rpdk.java.codegen:JavaLanguagePlugin"]},
4242
license="Apache License 2.0",

src/main/java/software/amazon/cloudformation/AbstractWrapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,12 @@ protected void writeResponse(final OutputStream outputStream, final ProgressEven
414414
response.setResult(null);
415415
}
416416

417+
if (response.getAnnotations() != null) {
418+
// Same as above: remove any non-resource specific fields
419+
// from response - in this case, expunge Hook Annotations.
420+
response.setAnnotations(null);
421+
}
422+
417423
String output = this.serializer.serialize(response);
418424
outputStream.write(output.getBytes(StandardCharsets.UTF_8));
419425
outputStream.flush();

src/main/java/software/amazon/cloudformation/HookAbstractWrapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ private HookProgressEvent<CallbackT> createProgressResponse(final ProgressEvent<
373373
if (request != null) {
374374
response.setClientRequestToken(request.getClientRequestToken());
375375
}
376+
response.setAnnotations(progressEvent.getAnnotations());
376377

377378
return response;
378379
}

src/main/java/software/amazon/cloudformation/proxy/ProgressEvent.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import lombok.Builder;
2222
import lombok.Data;
2323
import lombok.NoArgsConstructor;
24+
import software.amazon.cloudformation.proxy.hook.HookAnnotation;
2425

2526
@Data
2627
@AllArgsConstructor
@@ -81,6 +82,15 @@ public class ProgressEvent<ResourceT, CallbackT> {
8182
*/
8283
private String nextToken;
8384

85+
/**
86+
* The optional list of HookAnnotation objects that, if used by a CloudFormation
87+
* Hook, contain additional, user-defined metadata and information on the
88+
* results of a hook's evaluation.
89+
*
90+
* Note: this field is ignored for resource handlers.
91+
*/
92+
private List<HookAnnotation> annotations;
93+
8494
/**
8595
* Convenience method for constructing a FAILED response
8696
*
@@ -158,7 +168,8 @@ public static <ResourceT, CallbackT> ProgressEvent<ResourceT, CallbackT> success
158168

159169
public static <ResourceT,
160170
CallbackT> ProgressEvent<ResourceT, CallbackT> success(ResourceT model, CallbackT cxt, String message) {
161-
return success(model, cxt, message, null);
171+
return ProgressEvent.<ResourceT, CallbackT>builder().resourceModel(model).callbackContext(cxt).message(message)
172+
.status(OperationStatus.SUCCESS).build();
162173
}
163174

164175
public static <ResourceT,
@@ -167,6 +178,20 @@ CallbackT> ProgressEvent<ResourceT, CallbackT> success(ResourceT model, Callback
167178
.result(result).status(OperationStatus.SUCCESS).build();
168179
}
169180

181+
public static <ResourceT, CallbackT>
182+
ProgressEvent<ResourceT, CallbackT>
183+
success(ResourceT model, CallbackT cxt, String message, List<HookAnnotation> annotations) {
184+
return ProgressEvent.<ResourceT, CallbackT>builder().resourceModel(model).callbackContext(cxt).message(message)
185+
.annotations(annotations).status(OperationStatus.SUCCESS).build();
186+
}
187+
188+
public static <ResourceT, CallbackT>
189+
ProgressEvent<ResourceT, CallbackT>
190+
success(ResourceT model, CallbackT cxt, String message, String result, List<HookAnnotation> annotations) {
191+
return ProgressEvent.<ResourceT, CallbackT>builder().resourceModel(model).callbackContext(cxt).message(message)
192+
.result(result).annotations(annotations).status(OperationStatus.SUCCESS).build();
193+
}
194+
170195
public ProgressEvent<ResourceT, CallbackT>
171196
onSuccess(Function<ProgressEvent<ResourceT, CallbackT>, ProgressEvent<ResourceT, CallbackT>> func) {
172197
return (status != null && status == OperationStatus.SUCCESS) ? func.apply(this) : this;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package software.amazon.cloudformation.proxy.hook;
16+
17+
import lombok.AllArgsConstructor;
18+
import lombok.Builder;
19+
import lombok.Data;
20+
import lombok.NoArgsConstructor;
21+
22+
@Data
23+
@AllArgsConstructor
24+
@NoArgsConstructor
25+
@Builder
26+
public class HookAnnotation {
27+
/**
28+
* The name of the annotation; this is mandatory.
29+
*/
30+
private String annotationName;
31+
32+
/**
33+
* The status for the hook annotation: this is mandatory.
34+
*/
35+
private HookAnnotationStatus status;
36+
37+
/**
38+
* The optional status message for the annotation.
39+
*/
40+
private String statusMessage;
41+
42+
/**
43+
* The optional remediation message for the annotation.
44+
*/
45+
private String remediationMessage;
46+
47+
/**
48+
* The optional remediation link for the annotation.
49+
*/
50+
private String remediationLink;
51+
52+
/**
53+
* The optional severity level for the annotation.
54+
*/
55+
private HookAnnotationSeverityLevel severityLevel;
56+
57+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package software.amazon.cloudformation.proxy.hook;
16+
17+
public enum HookAnnotationSeverityLevel {
18+
INFORMATIONAL,
19+
LOW,
20+
MEDIUM,
21+
HIGH,
22+
CRITICAL,
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package software.amazon.cloudformation.proxy.hook;
16+
17+
public enum HookAnnotationStatus {
18+
PASSED,
19+
FAILED,
20+
SKIPPED,
21+
}

src/main/java/software/amazon/cloudformation/proxy/hook/HookProgressEvent.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package software.amazon.cloudformation.proxy.hook;
1616

1717
import com.fasterxml.jackson.annotation.JsonIgnore;
18+
import java.util.List;
1819
import java.util.function.Function;
1920
import lombok.AllArgsConstructor;
2021
import lombok.Builder;
@@ -71,6 +72,13 @@ public class HookProgressEvent<CallbackT> {
7172
*/
7273
private String result;
7374

75+
/**
76+
* The optional list of HookAnnotation objects that, if used by a CloudFormation
77+
* Hook, contain additional, user-defined metadata and information on the
78+
* results of a hook's evaluation.
79+
*/
80+
private List<HookAnnotation> annotations;
81+
7482
/**
7583
* Convenience method for constructing a FAILED response
7684
*

0 commit comments

Comments
 (0)