@aws-cdk/toolkit-lib 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ ## Toolkit Code Registry
2
+
3
+ | Code | Description | Level | Data Interface |
4
+ |------|-------------|-------|----------------|
5
+ | CDK_TOOLKIT_I1000 | Provides synthesis times. | info | n/a |
6
+ | CDK_TOOLKIT_I1901 | Provides stack data | result | [StackData](docs/interfaces/StackData.html) |
7
+ | CDK_TOOLKIT_I1902 | Successfully deployed stacks | result | [AssemblyData](docs/interfaces/AssemblyData.html) |
8
+ | CDK_TOOLKIT_I2901 | Provides details on the selected stacks and their dependencies | result | n/a |
9
+ | CDK_TOOLKIT_E3900 | Resource import failed | error | n/a |
10
+ | CDK_TOOLKIT_I5000 | Provides deployment times | info | n/a |
11
+ | CDK_TOOLKIT_I5001 | Provides total time in deploy action, including synth and rollback | info | [Duration](docs/interfaces/Duration.html) |
12
+ | CDK_TOOLKIT_I5002 | Provides time for resource migration | info | n/a |
13
+ | CDK_TOOLKIT_I5031 | Informs about any log groups that are traced as part of the deployment | info | n/a |
14
+ | CDK_TOOLKIT_I5050 | Confirm rollback during deployment | info | n/a |
15
+ | CDK_TOOLKIT_I5060 | Confirm deploy security sensitive changes | info | n/a |
16
+ | CDK_TOOLKIT_I5900 | Deployment results on success | result | [SuccessfulDeployStackResult](docs/interfaces/SuccessfulDeployStackResult.html) |
17
+ | CDK_TOOLKIT_E5001 | No stacks found | error | n/a |
18
+ | CDK_TOOLKIT_I6000 | Provides rollback times | info | n/a |
19
+ | CDK_TOOLKIT_E6001 | No stacks found | error | n/a |
20
+ | CDK_TOOLKIT_E6900 | Rollback failed | error | n/a |
21
+ | CDK_TOOLKIT_I7000 | Provides destroy times | info | n/a |
22
+ | CDK_TOOLKIT_I7010 | Confirm destroy stacks | info | n/a |
23
+ | CDK_TOOLKIT_E7010 | Action was aborted due to negative confirmation of request | error | n/a |
24
+ | CDK_TOOLKIT_E7900 | Stack deletion failed | error | n/a |
25
+ | CDK_ASSEMBLY_I0042 | Writing updated context | debug | n/a |
26
+ | CDK_ASSEMBLY_I0241 | Fetching missing context | debug | n/a |
27
+ | CDK_ASSEMBLY_I1000 | Cloud assembly output starts | debug | n/a |
28
+ | CDK_ASSEMBLY_I1001 | Output lines emitted by the cloud assembly to stdout | info | n/a |
29
+ | CDK_ASSEMBLY_E1002 | Output lines emitted by the cloud assembly to stderr | error | n/a |
30
+ | CDK_ASSEMBLY_I1003 | Cloud assembly output finished | info | n/a |
31
+ | CDK_ASSEMBLY_E1111 | Incompatible CDK CLI version. Upgrade needed. | error | n/a |
package/README.md CHANGED
@@ -62,12 +62,12 @@ import * as core from 'aws-cdk-lib/core';
62
62
  declare const cdk: Toolkit;
63
63
 
64
64
  const cx = cdk.fromAssemblyBuilder(async () => {
65
- const app = new core.App();
65
+ const app = new core.App();
66
66
 
67
- // Define your stacks here
68
- new MyStack(app, 'MyStack');
67
+ // Define your stacks here
68
+ new MyStack(app, 'MyStack');
69
69
 
70
- return app.synth();
70
+ return app.synth();
71
71
  });
72
72
  ```
73
73
 
@@ -82,11 +82,11 @@ The following is a basic example that creates a deployment of the `MyStack` stac
82
82
  declare const cdk: Toolkit;
83
83
  declare const cx: ICloudAssemblySource;
84
84
 
85
- await toolkit.deploy(cloudAssembly, {
86
- stacks: {
87
- strategy: StackSelectionStrategy.PATTERN_MUST_MATCH,
88
- patterns: ["MyStack"],
89
- },
85
+ await cdk.deploy(cx, {
86
+ stacks: {
87
+ strategy: StackSelectionStrategy.PATTERN_MUST_MATCH,
88
+ patterns: ["MyStack"],
89
+ },
90
90
  });
91
91
  ```
92
92
 
@@ -231,9 +231,9 @@ The following is an example implementation that simply logs all message objects
231
231
 
232
232
  ```ts
233
233
  const toolkit = new toolkitLib.Toolkit({
234
- ioHost: {
234
+ ioHost: {
235
235
  notify: async function (msg) {
236
- console.log(msg);
236
+ console.log(msg);
237
237
  },
238
238
  requestResponse: async function (msg) {
239
239
  console.log(msg);
@@ -322,12 +322,12 @@ Alternatively a inline `AssemblyBuilder` function can be used to build a CDK app
322
322
  declare const cdk: Toolkit;
323
323
 
324
324
  const cx = cdk.fromAssemblyBuilder(async () => {
325
- const app = new core.App();
325
+ const app = new core.App();
326
326
 
327
- // Define your stacks here
328
- new MyStack(app, 'MyStack');
327
+ // Define your stacks here
328
+ new MyStack(app, 'MyStack');
329
329
 
330
- return app.synth();
330
+ return app.synth();
331
331
  });
332
332
  ```
333
333
 
@@ -403,7 +403,7 @@ declare const cx: ICloudAssemblySource;
403
403
  try {
404
404
  // Attempt a CDK Toolkit operation
405
405
  const deployment = await cdk.deploy(cloudAssembly, {
406
- stacks: ['MyStack']
406
+ stacks: ['MyStack']
407
407
  });
408
408
 
409
409
  } catch (error) {
@@ -425,8 +425,8 @@ try {
425
425
  console.error('Generic Toolkit error:', error.message);
426
426
 
427
427
  } else {
428
- // Handle unexpected errors
429
- console.error('Unexpected error:', error);
428
+ // Handle unexpected errors
429
+ console.error('Unexpected error:', error);
430
430
  }
431
431
  }
432
432
  ```
package/build-info.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "comment": "Generated at 2025-02-25T00:50:08Z by generate.sh",
3
- "commit": "321a46a"
2
+ "comment": "Generated at 2025-02-26T16:38:53Z by generate.sh",
3
+ "commit": "130445d"
4
4
  }
@@ -79,6 +79,7 @@ module.exports = __toCommonJS(aws_cdk_exports);
79
79
 
80
80
  // ../../aws-cdk/lib/api/aws-auth/sdk.ts
81
81
  var import_client_appsync = require("@aws-sdk/client-appsync");
82
+ var import_client_cloudcontrol = require("@aws-sdk/client-cloudcontrol");
82
83
  var import_client_cloudformation = require("@aws-sdk/client-cloudformation");
83
84
  var import_client_cloudwatch_logs = require("@aws-sdk/client-cloudwatch-logs");
84
85
  var import_client_codebuild = require("@aws-sdk/client-codebuild");
@@ -690,6 +691,13 @@ var SDK = class {
690
691
  }
691
692
  };
692
693
  }
694
+ cloudControl() {
695
+ const client = new import_client_cloudcontrol.CloudControlClient(this.config);
696
+ return {
697
+ listResources: (input) => client.send(new import_client_cloudcontrol.ListResourcesCommand(input)),
698
+ getResource: (input) => client.send(new import_client_cloudcontrol.GetResourceCommand(input))
699
+ };
700
+ }
693
701
  cloudFormation() {
694
702
  const client = new import_client_cloudformation.CloudFormationClient({
695
703
  ...this.config,
@@ -5821,7 +5829,7 @@ var fs9 = __toESM(require("fs-extra"));
5821
5829
  function some(node, predicate) {
5822
5830
  return node != null && (predicate(node) || findInChildren());
5823
5831
  function findInChildren() {
5824
- return Object.values(node.children ?? {}).some((child) => some(child, predicate));
5832
+ return Object.values(node?.children ?? {}).some((child) => some(child, predicate));
5825
5833
  }
5826
5834
  }
5827
5835
  function loadTree(assembly) {
@@ -5831,7 +5839,7 @@ function loadTree(assembly) {
5831
5839
  return fileName ? fs9.readJSONSync(path8.join(outdir, fileName)).tree : {};
5832
5840
  } catch (e) {
5833
5841
  trace(`Failed to get tree.json file: ${e}. Proceeding with empty tree.`);
5834
- return {};
5842
+ return void 0;
5835
5843
  }
5836
5844
  }
5837
5845
  function loadTreeFromDir(outdir) {
@@ -5839,91 +5847,137 @@ function loadTreeFromDir(outdir) {
5839
5847
  return fs9.readJSONSync(path8.join(outdir, "tree.json")).tree;
5840
5848
  } catch (e) {
5841
5849
  trace(`Failed to get tree.json file: ${e}. Proceeding with empty tree.`);
5842
- return {};
5850
+ return void 0;
5843
5851
  }
5844
5852
  }
5845
5853
 
5846
5854
  // ../../aws-cdk/lib/notices.ts
5847
5855
  var CACHE_FILE_PATH = path9.join(cdkCacheDir(), "notices.json");
5848
- var NoticesFilter = class {
5856
+ var NoticesFilter = class _NoticesFilter {
5849
5857
  static filter(options) {
5850
- return [
5851
- ...this.findForCliVersion(options.data, options.cliVersion),
5852
- ...this.findForFrameworkVersion(options.data, options.outDir),
5853
- ...this.findForBootstrapVersion(options.data, options.bootstrappedEnvironments)
5858
+ const components = [
5859
+ ..._NoticesFilter.constructTreeComponents(options.outDir),
5860
+ ..._NoticesFilter.otherComponents(options)
5854
5861
  ];
5862
+ return _NoticesFilter.findForNamedComponents(options.data, components);
5855
5863
  }
5856
- static findForCliVersion(data, cliVersion) {
5857
- return flatMap(data, (notice) => {
5858
- const affectedComponent = notice.components.find((component) => component.name === "cli");
5859
- const affectedRange = affectedComponent?.version;
5860
- if (affectedRange == null) {
5861
- return [];
5862
- }
5863
- if (!semver4.satisfies(cliVersion, affectedRange)) {
5864
- return [];
5865
- }
5866
- return [new FilteredNotice(notice)];
5867
- });
5864
+ /**
5865
+ * From a set of input options, return the notices components we are searching for
5866
+ */
5867
+ static otherComponents(options) {
5868
+ return [
5869
+ // CLI
5870
+ {
5871
+ name: "cli",
5872
+ version: options.cliVersion
5873
+ },
5874
+ // Node version
5875
+ {
5876
+ name: "node",
5877
+ version: process.version.replace(/^v/, ""),
5878
+ // remove the 'v' prefix.
5879
+ dynamicName: "node"
5880
+ },
5881
+ // Bootstrap environments
5882
+ ...options.bootstrappedEnvironments.flatMap((env) => {
5883
+ const semverBootstrapVersion = semver4.coerce(env.bootstrapStackVersion);
5884
+ if (!semverBootstrapVersion) {
5885
+ warning(`While filtering notices, could not coerce bootstrap version '${env.bootstrapStackVersion}' into semver`);
5886
+ return [];
5887
+ }
5888
+ return [{
5889
+ name: "bootstrap",
5890
+ version: `${semverBootstrapVersion}`,
5891
+ dynamicName: "ENVIRONMENTS",
5892
+ dynamicValue: env.environment.name
5893
+ }];
5894
+ })
5895
+ ];
5868
5896
  }
5869
- static findForFrameworkVersion(data, outDir) {
5870
- const tree = loadTreeFromDir(outDir);
5871
- return flatMap(data, (notice) => {
5872
- const matched = some(tree, (node) => {
5873
- return this.resolveAliases(notice.components).some((component) => compareNames(component.name, node.constructInfo?.fqn) && compareVersions(component.version, node.constructInfo?.version));
5874
- });
5875
- if (!matched) {
5876
- return [];
5877
- }
5878
- return [new FilteredNotice(notice)];
5879
- function compareNames(pattern, target) {
5880
- if (target == null) {
5881
- return false;
5897
+ /**
5898
+ * Based on a set of component names, find all notices that match one of the given components
5899
+ */
5900
+ static findForNamedComponents(data, actualComponents) {
5901
+ return data.flatMap((notice) => {
5902
+ const ors = this.resolveAliases(normalizeComponents(notice.components));
5903
+ for (const ands of ors) {
5904
+ const matched = ands.map((affected) => actualComponents.filter((actual) => _NoticesFilter.componentNameMatches(affected, actual) && semver4.satisfies(actual.version, affected.version)));
5905
+ if (matched.every((xs) => xs.length > 0)) {
5906
+ const ret = new FilteredNotice(notice);
5907
+ _NoticesFilter.addDynamicValues(matched.flatMap((x) => x), ret);
5908
+ return [ret];
5882
5909
  }
5883
- return pattern.endsWith(".") ? target.startsWith(pattern) : pattern === target;
5884
- }
5885
- function compareVersions(pattern, target) {
5886
- return semver4.satisfies(target ?? "", pattern);
5887
5910
  }
5911
+ return [];
5888
5912
  });
5889
5913
  }
5890
- static findForBootstrapVersion(data, bootstrappedEnvironments) {
5891
- return flatMap(data, (notice) => {
5892
- const affectedComponent = notice.components.find((component) => component.name === "bootstrap");
5893
- const affectedRange = affectedComponent?.version;
5894
- if (affectedRange == null) {
5895
- return [];
5896
- }
5897
- const affected = bootstrappedEnvironments.filter((i) => {
5898
- const semverBootstrapVersion = semver4.coerce(i.bootstrapStackVersion);
5899
- if (!semverBootstrapVersion) {
5900
- warning(`While filtering notices, could not coerce bootstrap version '${i.bootstrapStackVersion}' into semver`);
5901
- return false;
5902
- }
5903
- return semver4.satisfies(semverBootstrapVersion, affectedRange);
5904
- });
5905
- if (affected.length === 0) {
5906
- return [];
5914
+ /**
5915
+ * Whether the given "affected component" name applies to the given actual component name.
5916
+ *
5917
+ * The name matches if the name is exactly the same, or the name in the notice
5918
+ * is a prefix of the node name when the query ends in '.'.
5919
+ */
5920
+ static componentNameMatches(pattern, actual) {
5921
+ return pattern.name.endsWith(".") ? actual.name.startsWith(pattern.name) : pattern.name === actual.name;
5922
+ }
5923
+ /**
5924
+ * Adds dynamic values from the given ActualComponents
5925
+ *
5926
+ * If there are multiple components with the same dynamic name, they are joined
5927
+ * by a comma.
5928
+ */
5929
+ static addDynamicValues(comps, notice) {
5930
+ const dynamicValues = {};
5931
+ for (const comp of comps) {
5932
+ if (comp.dynamicName) {
5933
+ dynamicValues[comp.dynamicName] = dynamicValues[comp.dynamicName] ?? [];
5934
+ dynamicValues[comp.dynamicName].push(comp.dynamicValue ?? comp.version);
5907
5935
  }
5908
- const filtered = new FilteredNotice(notice);
5909
- filtered.addDynamicValue("ENVIRONMENTS", affected.map((s) => s.environment.name).join(","));
5910
- return [filtered];
5936
+ }
5937
+ for (const [key, values] of Object.entries(dynamicValues)) {
5938
+ notice.addDynamicValue(key, values.join(","));
5939
+ }
5940
+ }
5941
+ /**
5942
+ * Treat 'framework' as an alias for either `aws-cdk-lib.` or `@aws-cdk/core.`.
5943
+ *
5944
+ * Because it's EITHER `aws-cdk-lib` or `@aws-cdk/core`, we need to add multiple
5945
+ * arrays at the top level.
5946
+ */
5947
+ static resolveAliases(ors) {
5948
+ return ors.flatMap((ands) => {
5949
+ const hasFramework = ands.find((c) => c.name === "framework");
5950
+ if (!hasFramework) {
5951
+ return [ands];
5952
+ }
5953
+ return [
5954
+ ands.map((c) => c.name === "framework" ? { ...c, name: "@aws-cdk/core." } : c),
5955
+ ands.map((c) => c.name === "framework" ? { ...c, name: "aws-cdk-lib." } : c)
5956
+ ];
5911
5957
  });
5912
5958
  }
5913
- static resolveAliases(components) {
5914
- return flatMap(components, (component) => {
5915
- if (component.name === "framework") {
5916
- return [{
5917
- name: "@aws-cdk/core.",
5918
- version: component.version
5919
- }, {
5920
- name: "aws-cdk-lib.",
5921
- version: component.version
5922
- }];
5923
- } else {
5924
- return [component];
5959
+ /**
5960
+ * Load the construct tree from the given directory and return its components
5961
+ */
5962
+ static constructTreeComponents(manifestDir) {
5963
+ const tree = loadTreeFromDir(manifestDir);
5964
+ if (!tree) {
5965
+ return [];
5966
+ }
5967
+ const ret = [];
5968
+ recurse(tree);
5969
+ return ret;
5970
+ function recurse(x) {
5971
+ if (x.constructInfo?.fqn && x.constructInfo?.version) {
5972
+ ret.push({
5973
+ name: x.constructInfo?.fqn,
5974
+ version: x.constructInfo?.version
5975
+ });
5925
5976
  }
5926
- });
5977
+ for (const child of Object.values(x.children ?? {})) {
5978
+ recurse(child);
5979
+ }
5980
+ }
5927
5981
  }
5928
5982
  };
5929
5983
  var Notices = class _Notices {
@@ -6023,6 +6077,12 @@ var Notices = class _Notices {
6023
6077
  }
6024
6078
  }
6025
6079
  };
6080
+ function normalizeComponents(xs) {
6081
+ return xs.map((x) => Array.isArray(x) ? x : [x]);
6082
+ }
6083
+ function renderConjunction(xs) {
6084
+ return xs.map((c) => `${c.name}: ${c.version}`).join(" AND ");
6085
+ }
6026
6086
  var FilteredNotice = class {
6027
6087
  constructor(notice) {
6028
6088
  this.notice = notice;
@@ -6032,7 +6092,7 @@ var FilteredNotice = class {
6032
6092
  this.dynamicValues[`{resolve:${key}}`] = value;
6033
6093
  }
6034
6094
  format() {
6035
- const componentsValue = this.notice.components.map((c) => `${c.name}: ${c.version}`).join(", ");
6095
+ const componentsValue = normalizeComponents(this.notice.components).map(renderConjunction).join(", ");
6036
6096
  return this.resolveDynamicValues([
6037
6097
  `${this.notice.issueNumber} ${this.notice.title}`,
6038
6098
  this.formatOverview(),
@@ -6165,7 +6225,7 @@ var CachedDataSource = class {
6165
6225
  };
6166
6226
 
6167
6227
  // ../../aws-cdk/lib/api/toolkit-info.ts
6168
- var import_util12 = require("util");
6228
+ var import_util11 = require("util");
6169
6229
  var chalk10 = __toESM(require("chalk"));
6170
6230
 
6171
6231
  // ../../aws-cdk/lib/api/bootstrap/bootstrap-props.ts
@@ -6190,7 +6250,7 @@ var ToolkitInfo = class _ToolkitInfo {
6190
6250
  if (!stack) {
6191
6251
  await ioHost.notify(debug2(
6192
6252
  action,
6193
- (0, import_util12.format)(
6253
+ (0, import_util11.format)(
6194
6254
  "The environment %s doesn't have the CDK toolkit stack (%s) installed. Use %s to setup your environment for use with the toolkit.",
6195
6255
  environment.name,
6196
6256
  stackName,
@@ -6202,7 +6262,7 @@ var ToolkitInfo = class _ToolkitInfo {
6202
6262
  if (stack.stackStatus.isCreationFailure) {
6203
6263
  await ioHost.notify(debug2(
6204
6264
  action,
6205
- (0, import_util12.format)(
6265
+ (0, import_util11.format)(
6206
6266
  "The environment %s has a CDK toolkit stack (%s) that failed to create. Use %s to try provisioning it again.",
6207
6267
  environment.name,
6208
6268
  stackName,
@@ -6987,7 +7047,7 @@ function tagsForStack(stack) {
6987
7047
  }
6988
7048
 
6989
7049
  // ../../aws-cdk/lib/api/resource-import/importer.ts
6990
- var import_util13 = require("util");
7050
+ var import_util12 = require("util");
6991
7051
  var cfnDiff = __toESM(require("@aws-cdk/cloudformation-diff"));
6992
7052
  var chalk12 = __toESM(require("chalk"));
6993
7053
  var fs11 = __toESM(require("fs-extra"));
@@ -7025,12 +7085,12 @@ var ResourceImporter = class {
7025
7085
  const descr = this.describeResource(resource.logicalId);
7026
7086
  const idProps = contents[resource.logicalId];
7027
7087
  if (idProps) {
7028
- await this.ioHost.notify(info2(this.action, (0, import_util13.format)("%s: importing using %s", chalk12.blue(descr), chalk12.blue(fmtdict(idProps)))));
7088
+ await this.ioHost.notify(info2(this.action, (0, import_util12.format)("%s: importing using %s", chalk12.blue(descr), chalk12.blue(fmtdict(idProps)))));
7029
7089
  ret.importResources.push(resource);
7030
7090
  ret.resourceMap[resource.logicalId] = idProps;
7031
7091
  delete contents[resource.logicalId];
7032
7092
  } else {
7033
- await this.ioHost.notify(info2(this.action, (0, import_util13.format)("%s: skipping", chalk12.blue(descr))));
7093
+ await this.ioHost.notify(info2(this.action, (0, import_util12.format)("%s: skipping", chalk12.blue(descr))));
7034
7094
  }
7035
7095
  }
7036
7096
  const unknown = Object.keys(contents);
@@ -7074,9 +7134,9 @@ var ResourceImporter = class {
7074
7134
  });
7075
7135
  assertIsSuccessfulDeployStackResult(result);
7076
7136
  const message = result.noOp ? " \u2705 %s (no changes)" : " \u2705 %s";
7077
- await this.ioHost.notify(info2(this.action, "\n" + chalk12.green((0, import_util13.format)(message, this.stack.displayName))));
7137
+ await this.ioHost.notify(info2(this.action, "\n" + chalk12.green((0, import_util12.format)(message, this.stack.displayName))));
7078
7138
  } catch (e) {
7079
- await this.ioHost.notify(error2(this.action, (0, import_util13.format)("\n \u274C %s failed: %s", chalk12.bold(this.stack.displayName), e), "CDK_TOOLKIT_E3900"));
7139
+ await this.ioHost.notify(error2(this.action, (0, import_util12.format)("\n \u274C %s failed: %s", chalk12.bold(this.stack.displayName), e), "CDK_TOOLKIT_E3900"));
7080
7140
  throw e;
7081
7141
  }
7082
7142
  }
@@ -8103,6 +8163,128 @@ var AZContextProviderPlugin = class {
8103
8163
  }
8104
8164
  };
8105
8165
 
8166
+ // ../../aws-cdk/lib/util/json.ts
8167
+ function getResultObj(jsonObject, identifier, propertiesToReturn) {
8168
+ const propsObj = {};
8169
+ propertiesToReturn.forEach((propName) => {
8170
+ Object.assign(propsObj, { [propName]: findJsonValue(jsonObject, propName) });
8171
+ });
8172
+ Object.assign(propsObj, { ["Identifier"]: identifier });
8173
+ return propsObj;
8174
+ }
8175
+ function findJsonValue(jsonObject, path12) {
8176
+ const paths = path12.split(".");
8177
+ let obj = jsonObject;
8178
+ paths.forEach((p) => {
8179
+ obj = obj[p];
8180
+ if (obj === void 0) {
8181
+ throw new TypeError(`Cannot read field ${path12}. ${p} is not found.`);
8182
+ }
8183
+ });
8184
+ return obj;
8185
+ }
8186
+
8187
+ // ../../aws-cdk/lib/context-providers/cc-api-provider.ts
8188
+ var CcApiContextProviderPlugin = class {
8189
+ constructor(aws) {
8190
+ this.aws = aws;
8191
+ }
8192
+ /**
8193
+ * This returns a data object with the value from CloudControl API result.
8194
+ * args.typeName - see https://docs.aws.amazon.com/cloudcontrolapi/latest/userguide/supported-resources.html
8195
+ * args.exactIdentifier - use CC API getResource.
8196
+ * args.propertyMatch - use CCP API listResources to get resources and propertyMatch to search through the list.
8197
+ * args.propertiesToReturn - Properties from CC API to return.
8198
+ */
8199
+ async getValue(args) {
8200
+ const cloudControl = (await initContextProviderSdk(this.aws, args)).cloudControl();
8201
+ const result = await this.findResources(cloudControl, args);
8202
+ return result;
8203
+ }
8204
+ async findResources(cc, args) {
8205
+ if (args.exactIdentifier && args.propertyMatch) {
8206
+ throw new ContextProviderError(`Specify either exactIdentifier or propertyMatch, but not both. Failed to find resources using CC API for type ${args.typeName}.`);
8207
+ }
8208
+ if (!args.exactIdentifier && !args.propertyMatch) {
8209
+ throw new ContextProviderError(`Neither exactIdentifier nor propertyMatch is specified. Failed to find resources using CC API for type ${args.typeName}.`);
8210
+ }
8211
+ if (args.exactIdentifier) {
8212
+ return this.getResource(cc, args.typeName, args.exactIdentifier, args.propertiesToReturn);
8213
+ } else {
8214
+ return this.listResources(cc, args.typeName, args.propertyMatch, args.propertiesToReturn);
8215
+ }
8216
+ }
8217
+ /**
8218
+ * Calls getResource from CC API to get the resource.
8219
+ * See https://docs.aws.amazon.com/cli/latest/reference/cloudcontrol/get-resource.html
8220
+ *
8221
+ * If the exactIdentifier is not found, then an empty map is returned.
8222
+ * If the resource is found, then a map of the identifier to a map of property values is returned.
8223
+ */
8224
+ async getResource(cc, typeName, exactIdentifier, propertiesToReturn) {
8225
+ const resultObjs = [];
8226
+ try {
8227
+ const result = await cc.getResource({
8228
+ TypeName: typeName,
8229
+ Identifier: exactIdentifier
8230
+ });
8231
+ const id = result.ResourceDescription?.Identifier ?? "";
8232
+ if (id !== "") {
8233
+ const propsObject = JSON.parse(result.ResourceDescription?.Properties ?? "");
8234
+ const propsObj = getResultObj(propsObject, result.ResourceDescription?.Identifier, propertiesToReturn);
8235
+ resultObjs.push(propsObj);
8236
+ } else {
8237
+ throw new ContextProviderError(`Could not get resource ${exactIdentifier}.`);
8238
+ }
8239
+ } catch (err) {
8240
+ throw new ContextProviderError(`Encountered CC API error while getting resource ${exactIdentifier}. Error: ${err}`);
8241
+ }
8242
+ return resultObjs;
8243
+ }
8244
+ /**
8245
+ * Calls listResources from CC API to get the resources and apply args.propertyMatch to find the resources.
8246
+ * See https://docs.aws.amazon.com/cli/latest/reference/cloudcontrol/list-resources.html
8247
+ *
8248
+ * Since exactIdentifier is not specified, propertyMatch must be specified.
8249
+ * This returns an object where the ids are object keys and values are objects with keys of args.propertiesToReturn.
8250
+ */
8251
+ async listResources(cc, typeName, propertyMatch, propertiesToReturn) {
8252
+ const resultObjs = [];
8253
+ try {
8254
+ const result = await cc.listResources({
8255
+ TypeName: typeName
8256
+ });
8257
+ result.ResourceDescriptions?.forEach((resource) => {
8258
+ const id = resource.Identifier ?? "";
8259
+ if (id !== "") {
8260
+ const propsObject = JSON.parse(resource.Properties ?? "");
8261
+ const filters = Object.entries(propertyMatch);
8262
+ let match = false;
8263
+ if (filters) {
8264
+ let propertyMatchesFilter2 = function(actual, expected) {
8265
+ return expected === actual;
8266
+ };
8267
+ var propertyMatchesFilter = propertyMatchesFilter2;
8268
+ match = filters.every((record, _index, _arr) => {
8269
+ const key = record[0];
8270
+ const expected = record[1];
8271
+ const actual = findJsonValue(propsObject, key);
8272
+ return propertyMatchesFilter2(actual, expected);
8273
+ });
8274
+ }
8275
+ if (match) {
8276
+ const propsObj = getResultObj(propsObject, resource.Identifier, propertiesToReturn);
8277
+ resultObjs.push(propsObj);
8278
+ }
8279
+ }
8280
+ });
8281
+ } catch (err) {
8282
+ throw new ContextProviderError(`Could not get resources ${propertyMatch}. Error: ${err}`);
8283
+ }
8284
+ return resultObjs;
8285
+ }
8286
+ };
8287
+
8106
8288
  // ../../aws-cdk/lib/context-providers/endpoint-service-availability-zones.ts
8107
8289
  var EndpointServiceAZContextProviderPlugin = class {
8108
8290
  constructor(aws) {
@@ -8820,7 +9002,8 @@ var availableContextProviders = {
8820
9002
  [cxschema3.ContextProvider.SECURITY_GROUP_PROVIDER]: (s) => new SecurityGroupContextProviderPlugin(s),
8821
9003
  [cxschema3.ContextProvider.LOAD_BALANCER_PROVIDER]: (s) => new LoadBalancerContextProviderPlugin(s),
8822
9004
  [cxschema3.ContextProvider.LOAD_BALANCER_LISTENER_PROVIDER]: (s) => new LoadBalancerListenerContextProviderPlugin(s),
8823
- [cxschema3.ContextProvider.KEY_PROVIDER]: (s) => new KeyContextProviderPlugin(s)
9005
+ [cxschema3.ContextProvider.KEY_PROVIDER]: (s) => new KeyContextProviderPlugin(s),
9006
+ [cxschema3.ContextProvider.CC_API_PROVIDER]: (s) => new CcApiContextProviderPlugin(s)
8824
9007
  };
8825
9008
 
8826
9009
  // ../../aws-cdk/lib/api/util/rwlock.ts