@gradientedge/cdk-utils 8.99.0 → 8.100.0

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.
@@ -1,3 +1,4 @@
1
+ import * as cdk from 'aws-cdk-lib';
1
2
  import * as secretsManager from 'aws-cdk-lib/aws-secretsmanager';
2
3
  import { CommonConstruct } from '../../../common';
3
4
  /**
@@ -23,12 +24,20 @@ export declare class SecretsManager {
23
24
  * @param scope scope in which this resource is defined
24
25
  * @param props the secret properties
25
26
  */
26
- createSecret(id: string, scope: CommonConstruct, props: secretsManager.SecretProps): secretsManager.Secret;
27
+ createSecret(id: string, scope: CommonConstruct, props: secretsManager.SecretProps): cdk.aws_secretsmanager.Secret;
28
+ /**
29
+ * @summary Method to retrieve a secret from secrets manager with a cloudformation export
30
+ * @param id
31
+ * @param scope
32
+ * @param stackName
33
+ * @param exportName
34
+ */
35
+ retrieveSecretFromSecretsManager(id: string, scope: CommonConstruct, stackName: string, exportName: string): cdk.aws_secretsmanager.ISecret;
27
36
  /**
28
37
  * @summary Method to resolve secret value from a secret using AWS SDK
29
- * @param scope scope in which this resource is defined
38
+ * @param region the region in which the secret is defined
30
39
  * @param secretId the secret name/ARN
31
40
  * @param secretKey the secret key to resolve the value for
32
41
  */
33
- resolveSecretValue(scope: CommonConstruct, secretId: string, secretKey: string): Promise<any>;
42
+ resolveSecretValue(region: string, secretId: string, secretKey: string): Promise<any>;
34
43
  }
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.SecretsManager = void 0;
27
27
  const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
28
+ const cdk = __importStar(require("aws-cdk-lib"));
28
29
  const secretsManager = __importStar(require("aws-cdk-lib/aws-secretsmanager"));
29
30
  const utils = __importStar(require("../../../utils"));
30
31
  /**
@@ -59,16 +60,26 @@ class SecretsManager {
59
60
  utils.createCfnOutput(`${id}-secretArn`, scope, secret.secretArn);
60
61
  return secret;
61
62
  }
63
+ /**
64
+ * @summary Method to retrieve a secret from secrets manager with a cloudformation export
65
+ * @param id
66
+ * @param scope
67
+ * @param stackName
68
+ * @param exportName
69
+ */
70
+ retrieveSecretFromSecretsManager(id, scope, stackName, exportName) {
71
+ return secretsManager.Secret.fromSecretNameV2(scope, `${id}`, cdk.Fn.importValue(`${stackName}-${scope.props.stage}-${exportName}`));
72
+ }
62
73
  /**
63
74
  * @summary Method to resolve secret value from a secret using AWS SDK
64
- * @param scope scope in which this resource is defined
75
+ * @param region the region in which the secret is defined
65
76
  * @param secretId the secret name/ARN
66
77
  * @param secretKey the secret key to resolve the value for
67
78
  */
68
- async resolveSecretValue(scope, secretId, secretKey) {
79
+ async resolveSecretValue(region, secretId, secretKey) {
69
80
  const client = new client_secrets_manager_1.SecretsManagerClient({
70
81
  credentials: utils.determineCredentials(),
71
- region: scope.props.region,
82
+ region: region,
72
83
  });
73
84
  const command = new client_secrets_manager_1.GetSecretValueCommand({
74
85
  SecretId: secretId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "8.99.0",
3
+ "version": "8.100.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -1,4 +1,5 @@
1
1
  import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-secrets-manager'
2
+ import * as cdk from 'aws-cdk-lib'
2
3
  import * as secretsManager from 'aws-cdk-lib/aws-secretsmanager'
3
4
  import * as utils from '../../../utils'
4
5
  import { CommonConstruct } from '../../../common'
@@ -38,16 +39,31 @@ export class SecretsManager {
38
39
  return secret
39
40
  }
40
41
 
42
+ /**
43
+ * @summary Method to retrieve a secret from secrets manager with a cloudformation export
44
+ * @param id
45
+ * @param scope
46
+ * @param stackName
47
+ * @param exportName
48
+ */
49
+ public retrieveSecretFromSecretsManager(id: string, scope: CommonConstruct, stackName: string, exportName: string) {
50
+ return secretsManager.Secret.fromSecretNameV2(
51
+ scope,
52
+ `${id}`,
53
+ cdk.Fn.importValue(`${stackName}-${scope.props.stage}-${exportName}`)
54
+ )
55
+ }
56
+
41
57
  /**
42
58
  * @summary Method to resolve secret value from a secret using AWS SDK
43
- * @param scope scope in which this resource is defined
59
+ * @param region the region in which the secret is defined
44
60
  * @param secretId the secret name/ARN
45
61
  * @param secretKey the secret key to resolve the value for
46
62
  */
47
- public async resolveSecretValue(scope: CommonConstruct, secretId: string, secretKey: string) {
63
+ public async resolveSecretValue(region: string, secretId: string, secretKey: string) {
48
64
  const client = new SecretsManagerClient({
49
65
  credentials: utils.determineCredentials(),
50
- region: scope.props.region,
66
+ region: region,
51
67
  })
52
68
  const command = new GetSecretValueCommand({
53
69
  SecretId: secretId,