You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(cli): CcApi context provider can be configured to fail if listing does not find a specific count of resources (#251)
Fixes#257
As described in the issue, `CcApiContextProviderPlugin` should have the
way to ensure the result has exact one resource.
This PR adds the `expectedMatchCount` option to restrict the length of
results in `listResources()`.
Unit tests are added and modified ensure the changes.
---
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license
---------
Co-authored-by: Rico Huijbers <[email protected]>
Copy file name to clipboardExpand all lines: packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.schema.json
+15-5
Original file line number
Diff line number
Diff line change
@@ -1024,19 +1024,19 @@
1024
1024
]
1025
1025
},
1026
1026
"CcApiContextQuery": {
1027
-
"description": "Query input for lookup up Cloudformation resources using CC API",
1027
+
"description": "Query input for lookup up CloudFormation resources using CC API",
1028
1028
"type": "object",
1029
1029
"properties": {
1030
1030
"typeName": {
1031
-
"description": "The Cloudformation resource type.\nSee https://docs.aws.amazon.com/cloudcontrolapi/latest/userguide/supported-resources.html",
1031
+
"description": "The CloudFormation resource type.\nSee https://docs.aws.amazon.com/cloudcontrolapi/latest/userguide/supported-resources.html",
1032
1032
"type": "string"
1033
1033
},
1034
1034
"exactIdentifier": {
1035
-
"description": "Identifier of the resource to look up using `GetResource`.\n\nSpecifying exactIdentifier will return exactly one result, or throw an error. (Default - Either exactIdentifier or propertyMatch should be specified.)",
1035
+
"description": "Identifier of the resource to look up using `GetResource`.\n\nSpecifying exactIdentifier will return exactly one result, or throw an error\nunless `ignoreErrorOnMissingContext` is set. (Default - Either exactIdentifier or propertyMatch should be specified.)",
1036
1036
"type": "string"
1037
1037
},
1038
1038
"propertyMatch": {
1039
-
"description": "Returns any resources matching these properties, using `ListResources`.\n\nSpecifying propertyMatch will return 0 or moreresults.\n\n## Notes on property completeness\n\nCloudControl API's `ListResources` may return fewer properties than\n`GetResource` would, depending on the resource implementation.\n\nThe resources that `propertyMatch` matches against will *only ever* be the\nproperties returned by the `ListResources` call. (Default - Either exactIdentifier or propertyMatch should be specified.)",
1039
+
"description": "Returns any resources matching these properties, using `ListResources`.\n\nBy default, specifying propertyMatch will successfully return 0 or more\nresults. To throw an error if the number of results is unexpected (and\nprevent the query results from being committed to context), specify\n`expectedMatchCount`.\n\n## Notes on property completeness\n\nCloudControl API's `ListResources` may return fewer properties than\n`GetResource` would, depending on the resource implementation.\n\nThe resources that `propertyMatch` matches against will *only ever* be the\nproperties returned by the `ListResources` call. (Default - Either exactIdentifier or propertyMatch should be specified.)",
1040
1040
"$ref": "#/definitions/Record<string,unknown>"
1041
1041
},
1042
1042
"propertiesToReturn": {
@@ -1046,11 +1046,21 @@
1046
1046
"type": "string"
1047
1047
}
1048
1048
},
1049
+
"expectedMatchCount": {
1050
+
"description": "Expected count of results if `propertyMatch` is specified.\n\nIf the expected result count does not match the actual count,\nby default an error is produced and the result is not committed to cached\ncontext, and the user can correct the situation and try again without\nhaving to manually clear out the context key using `cdk context --remove`\n\nIf the value of * `ignoreErrorOnMissingContext` is `true`, the value of\n`expectedMatchCount` is `at-least-one | exactly-one` and the number\nof found resources is 0, `dummyValue` is returned and committed to context\ninstead. (Default 'any')",
1051
+
"enum": [
1052
+
"any",
1053
+
"at-least-one",
1054
+
"at-most-one",
1055
+
"exactly-one"
1056
+
],
1057
+
"type": "string"
1058
+
},
1049
1059
"dummyValue": {
1050
1060
"description": "The value to return if the resource was not found and `ignoreErrorOnMissingContext` is true.\n\nIf supplied, `dummyValue` should be an array of objects.\n\n`dummyValue` does not have to have elements, and it may have objects with\ndifferent properties than the properties in `propertiesToReturn`, but it\nwill be easiest for downstream code if the `dummyValue` conforms to\nthe expected response shape. (Default - No dummy value available)"
1051
1061
},
1052
1062
"ignoreErrorOnMissingContext": {
1053
-
"description": "Ignore an error and return the `dummyValue` instead if the resource was not found.\n\n- In case of an `exactIdentifier` lookup, return the `dummyValue` if the resource with\n that identifier was not found.\n- In case of a `propertyMatch` lookup, this setting currently does not have any effect,\nas `propertyMatch` queries can legally return 0 resources.\n\nif `ignoreErrorOnMissingContext` is set, `dummyValue` should be set and be an array.",
1063
+
"description": "Ignore an error and return the `dummyValue` instead if the resource was not found.\n\n- In case of an `exactIdentifier` lookup, return the `dummyValue` if the resource with\n that identifier was not found.\n- In case of a `propertyMatch` lookup, return the `dummyValue` if `expectedMatchCount`\nis `at-least-one | exactly-one` and the number of resources found was 0.\n\nif `ignoreErrorOnMissingContext` is set, `dummyValue` should be set and be an array.",
).rejects.toThrow('dummyValue must be an array of objects');
427
516
});
517
+
518
+
test.each(['at-least-one','exactly-one']asconst)('dummyValue is returned when list operation returns 0 values for expectedMatchCount %p',async(expectedMatchCount)=>{
0 commit comments