Skip to content

Commit 80979fd

Browse files
committed
feat: Add in support for resourceModel to the CC API Context Provider
1 parent 29249ac commit 80979fd

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

packages/@aws-cdk/cloud-assembly-schema/lib/cloud-assembly/context-queries.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ export interface KeyContextQuery extends ContextLookupRoleOptions {
368368
* const x: CcApiContextQuery = {
369369
* typeName: 'AWS::Some::Type',
370370
* expectedMatchCount: 'exactly-one',
371+
* resourceModel: {SomeArn: 'arn:aws:....'},
371372
* propertiesToReturn: ['SomeProp'],
372373
* account: '11111111111',
373374
* region: 'us-east-1',
@@ -390,6 +391,17 @@ export interface CcApiContextQuery extends ContextLookupRoleOptions {
390391
*/
391392
readonly exactIdentifier?: string;
392393

394+
/**
395+
* The resource model to use to select the resources, using `ListResources`..
396+
*
397+
* This is needed for sub-resources where the parent Arn is required.
398+
*
399+
* See https://docs.aws.amazon.com/cloudcontrolapi/latest/userguide/resource-operations-list.html#resource-operations-list-containers
400+
*
401+
* @default - no resource Model is provided
402+
*/
403+
readonly resourceModel?: Record<string, unknown>;
404+
393405
/**
394406
* Returns any resources matching these properties, using `ListResources`.
395407
*

packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,10 @@
10931093
"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.)",
10941094
"type": "string"
10951095
},
1096+
"resourceModel": {
1097+
"description": "The resource model to use to select the resources, using `ListResources`..\n\nThis is needed for sub-resources where the parent Arn is required.\n\nSee https://docs.aws.amazon.com/cloudcontrolapi/latest/userguide/resource-operations-list.html#resource-operations-list-containers (Default - no resource Model is provided)",
1098+
"$ref": "#/definitions/Record%3Cstring%2Cunknown%3E"
1099+
},
10961100
"propertyMatch": {
10971101
"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.)",
10981102
"$ref": "#/definitions/Record%3Cstring%2Cunknown%3E"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"schemaHash": "e20bc1d07ab1a891372f40a6d2d8a8eb8e12f828b2b5b90d86b270dcb881ad74",
2+
"schemaHash": "c0092c55280aa03c568e1d591f2034783597e942a400d1d58d7f05a8215f51f4",
33
"$comment": "Do not hold back the version on additions: jsonschema validation of the manifest by the consumer will trigger errors on unexpected fields.",
4-
"revision": 49
4+
"revision": 50
55
}

packages/@aws-cdk/toolkit-lib/lib/context-providers/cc-api-provider.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class CcApiContextProviderPlugin implements ContextProviderPlugin {
3939
resources = await this.getResource(cloudControl, args.typeName, args.exactIdentifier);
4040
} else if (args.propertyMatch) {
4141
// use listResource
42-
resources = await this.listResources(cloudControl, args.typeName, args.propertyMatch, args.expectedMatchCount);
42+
resources = await this.listResources(cloudControl, args.typeName, args.propertyMatch, args.expectedMatchCount, args.resourceModel);
4343
} else {
4444
throw new ContextProviderError(`Provider protocol error: neither exactIdentifier nor propertyMatch is specified in ${JSON.stringify(args)}.`);
4545
}
@@ -99,14 +99,17 @@ export class CcApiContextProviderPlugin implements ContextProviderPlugin {
9999
typeName: string,
100100
propertyMatch: Record<string, unknown>,
101101
expectedMatchCount?: CcApiContextQuery['expectedMatchCount'],
102+
resourceModel?: Record<string, unknown>,
102103
): Promise<FoundResource[]> {
103104
try {
104105
const found: FoundResource[] = [];
105106
let nextToken: string | undefined = undefined;
107+
const resourceModelJSON: string | undefined = resourceModel ? JSON.stringify(resourceModel) : undefined;
106108

107109
do {
108110
const result = await cc.listResources({
109111
TypeName: typeName,
112+
ResourceModel: resourceModelJSON,
110113
MaxResults: 100,
111114
...nextToken ? { NextToken: nextToken } : {},
112115
});

0 commit comments

Comments
 (0)