in packages/@aws-cdk/toolkit-lib/lib/context-providers/cc-api-provider.ts [20:55]
public async getValue(args: CcApiContextQuery) {
// Validate input
if (args.exactIdentifier && args.propertyMatch) {
throw new ContextProviderError(`Provider protocol error: specify either exactIdentifier or propertyMatch, but not both (got ${JSON.stringify(args)})`);
}
if (args.ignoreErrorOnMissingContext && args.dummyValue === undefined) {
throw new ContextProviderError(`Provider protocol error: if ignoreErrorOnMissingContext is set, a dummyValue must be supplied (got ${JSON.stringify(args)})`);
}
if (args.dummyValue !== undefined && (!Array.isArray(args.dummyValue) || !args.dummyValue.every(isObject))) {
throw new ContextProviderError(`Provider protocol error: dummyValue must be an array of objects (got ${JSON.stringify(args.dummyValue)})`);
}
// Do the lookup
const cloudControl = (await initContextProviderSdk(this.aws, args)).cloudControl();
try {
let resources: FoundResource[];
if (args.exactIdentifier) {
// use getResource to get the exact indentifier
resources = await this.getResource(cloudControl, args.typeName, args.exactIdentifier);
} else if (args.propertyMatch) {
// use listResource
resources = await this.listResources(cloudControl, args.typeName, args.propertyMatch, args.expectedMatchCount);
} else {
throw new ContextProviderError(`Provider protocol error: neither exactIdentifier nor propertyMatch is specified in ${JSON.stringify(args)}.`);
}
return resources.map((r) => getResultObj(r.properties, r.identifier, args.propertiesToReturn));
} catch (err) {
if (err instanceof ZeroResourcesFoundError && args.ignoreErrorOnMissingContext) {
// We've already type-checked dummyValue.
return args.dummyValue;
}
throw err;
}
}