@gradientedge/cdk-utils 8.98.0 → 8.99.1
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.
- package/dist/src/lib/services/aws/secrets-manager/main.d.ts +9 -14
- package/dist/src/lib/services/aws/secrets-manager/main.js +27 -24
- package/dist/src/lib/utils/aws/index.d.ts +2 -0
- package/dist/src/lib/utils/aws/index.js +8 -1
- package/package.json +12 -10
- package/src/lib/services/aws/secrets-manager/main.ts +28 -26
- package/src/lib/utils/aws/index.ts +7 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { SecretsManager as SM } from '@aws-sdk/client-secrets-manager';
|
|
2
1
|
import * as cdk from 'aws-cdk-lib';
|
|
3
2
|
import * as secretsManager from 'aws-cdk-lib/aws-secretsmanager';
|
|
4
3
|
import { CommonConstruct } from '../../../common';
|
|
@@ -20,16 +19,12 @@ import { CommonConstruct } from '../../../common';
|
|
|
20
19
|
*/
|
|
21
20
|
export declare class SecretsManager {
|
|
22
21
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @param
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @summary Method to load a secret from secrets manager
|
|
29
|
-
* @param secretName
|
|
30
|
-
* @param region
|
|
22
|
+
* @summary Method to create a secret
|
|
23
|
+
* @param id scoped id of the resource
|
|
24
|
+
* @param scope scope in which this resource is defined
|
|
25
|
+
* @param props the secret properties
|
|
31
26
|
*/
|
|
32
|
-
|
|
27
|
+
createSecret(id: string, scope: CommonConstruct, props: secretsManager.SecretProps): cdk.aws_secretsmanager.Secret;
|
|
33
28
|
/**
|
|
34
29
|
* @summary Method to retrieve a secret from secrets manager with a cloudformation export
|
|
35
30
|
* @param id
|
|
@@ -39,10 +34,10 @@ export declare class SecretsManager {
|
|
|
39
34
|
*/
|
|
40
35
|
retrieveSecretFromSecretsManager(id: string, scope: CommonConstruct, stackName: string, exportName: string): cdk.aws_secretsmanager.ISecret;
|
|
41
36
|
/**
|
|
42
|
-
* @summary Method to
|
|
43
|
-
* @param id scoped id of the resource
|
|
37
|
+
* @summary Method to resolve secret value from a secret using AWS SDK
|
|
44
38
|
* @param scope scope in which this resource is defined
|
|
45
|
-
* @param
|
|
39
|
+
* @param secretId the secret name/ARN
|
|
40
|
+
* @param secretKey the secret key to resolve the value for
|
|
46
41
|
*/
|
|
47
|
-
|
|
42
|
+
resolveSecretValue(scope: CommonConstruct, secretId: string, secretKey: string): Promise<any>;
|
|
48
43
|
}
|
|
@@ -46,21 +46,19 @@ const utils = __importStar(require("../../../utils"));
|
|
|
46
46
|
*/
|
|
47
47
|
class SecretsManager {
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @param
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return new client_secrets_manager_1.SecretsManager({ region: region });
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* @summary Method to load a secret from secrets manager
|
|
57
|
-
* @param secretName
|
|
58
|
-
* @param region
|
|
49
|
+
* @summary Method to create a secret
|
|
50
|
+
* @param id scoped id of the resource
|
|
51
|
+
* @param scope scope in which this resource is defined
|
|
52
|
+
* @param props the secret properties
|
|
59
53
|
*/
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
createSecret(id, scope, props) {
|
|
55
|
+
const secret = new secretsManager.Secret(scope, `${id}`, {
|
|
56
|
+
...props,
|
|
57
|
+
secretName: `${props.secretName}-${scope.props.stage}`,
|
|
58
|
+
});
|
|
59
|
+
utils.createCfnOutput(`${id}-secretName`, scope, secret.secretName);
|
|
60
|
+
utils.createCfnOutput(`${id}-secretArn`, scope, secret.secretArn);
|
|
61
|
+
return secret;
|
|
64
62
|
}
|
|
65
63
|
/**
|
|
66
64
|
* @summary Method to retrieve a secret from secrets manager with a cloudformation export
|
|
@@ -73,19 +71,24 @@ class SecretsManager {
|
|
|
73
71
|
return secretsManager.Secret.fromSecretNameV2(scope, `${id}`, cdk.Fn.importValue(`${stackName}-${scope.props.stage}-${exportName}`));
|
|
74
72
|
}
|
|
75
73
|
/**
|
|
76
|
-
* @summary Method to
|
|
77
|
-
* @param id scoped id of the resource
|
|
74
|
+
* @summary Method to resolve secret value from a secret using AWS SDK
|
|
78
75
|
* @param scope scope in which this resource is defined
|
|
79
|
-
* @param
|
|
76
|
+
* @param secretId the secret name/ARN
|
|
77
|
+
* @param secretKey the secret key to resolve the value for
|
|
80
78
|
*/
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
async resolveSecretValue(scope, secretId, secretKey) {
|
|
80
|
+
const client = new client_secrets_manager_1.SecretsManagerClient({
|
|
81
|
+
credentials: utils.determineCredentials(),
|
|
82
|
+
region: scope.props.region,
|
|
85
83
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
const command = new client_secrets_manager_1.GetSecretValueCommand({
|
|
85
|
+
SecretId: secretId,
|
|
86
|
+
});
|
|
87
|
+
const response = await client.send(command);
|
|
88
|
+
if (!response.SecretString)
|
|
89
|
+
throw `Unable to resolve secret for ${secretId}`;
|
|
90
|
+
const secretString = JSON.parse(response.SecretString);
|
|
91
|
+
return secretString[secretKey];
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
exports.SecretsManager = SecretsManager;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as cdk from 'aws-cdk-lib';
|
|
2
2
|
import { CommonConstruct } from '../../common';
|
|
3
|
+
import { AwsCredentialIdentityProvider } from '@aws-sdk/types';
|
|
3
4
|
/**
|
|
4
5
|
* @summary Helper method to add CloudFormation outputs from the construct
|
|
5
6
|
* @param id scoped id of the resource
|
|
@@ -10,3 +11,4 @@ import { CommonConstruct } from '../../common';
|
|
|
10
11
|
* @returns The CloudFormation output
|
|
11
12
|
*/
|
|
12
13
|
export declare function createCfnOutput(id: string, scope: CommonConstruct, value?: string, description?: string, overrideId?: boolean): cdk.CfnOutput;
|
|
14
|
+
export declare function determineCredentials(): AwsCredentialIdentityProvider;
|
|
@@ -23,9 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.createCfnOutput = void 0;
|
|
26
|
+
exports.determineCredentials = exports.createCfnOutput = void 0;
|
|
27
27
|
const cdk = __importStar(require("aws-cdk-lib"));
|
|
28
28
|
const _ = __importStar(require("lodash"));
|
|
29
|
+
const credential_providers_1 = require("@aws-sdk/credential-providers");
|
|
29
30
|
/**
|
|
30
31
|
* @summary Helper method to add CloudFormation outputs from the construct
|
|
31
32
|
* @param id scoped id of the resource
|
|
@@ -48,3 +49,9 @@ function createCfnOutput(id, scope, value, description, overrideId = true) {
|
|
|
48
49
|
return output;
|
|
49
50
|
}
|
|
50
51
|
exports.createCfnOutput = createCfnOutput;
|
|
52
|
+
function determineCredentials() {
|
|
53
|
+
if (process.env.AWS_PROFILE)
|
|
54
|
+
return (0, credential_providers_1.fromIni)();
|
|
55
|
+
return (0, credential_providers_1.fromEnv)();
|
|
56
|
+
}
|
|
57
|
+
exports.determineCredentials = determineCredentials;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradientedge/cdk-utils",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.99.1",
|
|
4
4
|
"description": "Utilities for AWS CDK provisioning",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"build:production": "rimraf dist/ && npx tsc -p tsconfig.prd.json && pnpm -r build",
|
|
31
31
|
"ci": "pnpm install --frozen-lockfile && pnpm build && pnpm validate && pnpm run docs",
|
|
32
32
|
"cz": "npx cz",
|
|
33
|
-
"override:plugin:docs": "cp theme/type-converter.js node_modules/better-docs/typescript",
|
|
34
33
|
"docs": "npx rimraf api-docs && pnpm override:plugin:docs && npx jsdoc --pedantic -c jsdoc.json .",
|
|
35
|
-
"lint": "pnpm prettify && eslint **/*.ts --cache --max-warnings=0",
|
|
36
34
|
"fix": "pnpm prettify && eslint --fix **/*.ts",
|
|
35
|
+
"lint": "pnpm prettify && eslint **/*.ts --cache --max-warnings=0",
|
|
36
|
+
"override:plugin:docs": "cp theme/type-converter.js node_modules/better-docs/typescript",
|
|
37
37
|
"prettier": "npx prettier --cache --check \"**/*.{ts,json,md}\"",
|
|
38
38
|
"prettify": "npx prettier --cache --write \"**/*.{ts,json,md}\"",
|
|
39
39
|
"test": "npx rimraf coverage && npx jest --ci --maxWorkers=100%",
|
|
@@ -46,13 +46,15 @@
|
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@aws-sdk/client-secrets-manager": "^3.
|
|
49
|
+
"@aws-sdk/client-secrets-manager": "^3.357.0",
|
|
50
|
+
"@aws-sdk/credential-providers": "^3.357.0",
|
|
51
|
+
"@aws-sdk/types": "^3.357.0",
|
|
50
52
|
"@types/lodash": "^4.14.195",
|
|
51
53
|
"@types/node": "^20.3.1",
|
|
52
54
|
"@types/uuid": "^9.0.2",
|
|
53
55
|
"app-root-path": "^3.1.0",
|
|
54
|
-
"aws-cdk-lib": "^2.
|
|
55
|
-
"constructs": "^10.2.
|
|
56
|
+
"aws-cdk-lib": "^2.85.0",
|
|
57
|
+
"constructs": "^10.2.56",
|
|
56
58
|
"lodash": "^4.17.21",
|
|
57
59
|
"moment": "^2.29.4",
|
|
58
60
|
"nconf": "^0.12.0",
|
|
@@ -65,9 +67,9 @@
|
|
|
65
67
|
"@babel/eslint-parser": "^7.22.5",
|
|
66
68
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
67
69
|
"@types/jest": "^29.5.2",
|
|
68
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
69
|
-
"@typescript-eslint/parser": "^5.
|
|
70
|
-
"aws-cdk": "^2.
|
|
70
|
+
"@typescript-eslint/eslint-plugin": "^5.60.0",
|
|
71
|
+
"@typescript-eslint/parser": "^5.60.0",
|
|
72
|
+
"aws-cdk": "^2.85.0",
|
|
71
73
|
"better-docs": "^2.7.2",
|
|
72
74
|
"codecov": "^3.8.3",
|
|
73
75
|
"commitizen": "^4.3.0",
|
|
@@ -84,8 +86,8 @@
|
|
|
84
86
|
"jsdoc": "^4.0.2",
|
|
85
87
|
"jsdoc-babel": "^0.5.0",
|
|
86
88
|
"jsdoc-mermaid": "^1.0.0",
|
|
87
|
-
"jsdoc-to-markdown": "^8.0.0",
|
|
88
89
|
"jsdoc-plugin-typescript": "^2.2.1",
|
|
90
|
+
"jsdoc-to-markdown": "^8.0.0",
|
|
89
91
|
"prettier": "^2.8.8",
|
|
90
92
|
"prettier-plugin-organize-imports": "^3.2.2",
|
|
91
93
|
"rimraf": "^5.0.1",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-secrets-manager'
|
|
2
2
|
import * as cdk from 'aws-cdk-lib'
|
|
3
3
|
import * as secretsManager from 'aws-cdk-lib/aws-secretsmanager'
|
|
4
4
|
import * as utils from '../../../utils'
|
|
@@ -22,22 +22,21 @@ import { CommonConstruct } from '../../../common'
|
|
|
22
22
|
*/
|
|
23
23
|
export class SecretsManager {
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
* @param
|
|
25
|
+
* @summary Method to create a secret
|
|
26
|
+
* @param id scoped id of the resource
|
|
27
|
+
* @param scope scope in which this resource is defined
|
|
28
|
+
* @param props the secret properties
|
|
27
29
|
*/
|
|
28
|
-
public
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
public createSecret(id: string, scope: CommonConstruct, props: secretsManager.SecretProps) {
|
|
31
|
+
const secret = new secretsManager.Secret(scope, `${id}`, {
|
|
32
|
+
...props,
|
|
33
|
+
secretName: `${props.secretName}-${scope.props.stage}`,
|
|
34
|
+
})
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*/
|
|
37
|
-
public async loadSecret(secretName: string, region: string) {
|
|
38
|
-
const secretsManager = this.getAwsSecretsManager(region)
|
|
39
|
-
const secret: any = await Promise.all([secretsManager.getSecretValue({ SecretId: secretName })])
|
|
40
|
-
return secret ? JSON.parse(secret[0].SecretString) : {}
|
|
36
|
+
utils.createCfnOutput(`${id}-secretName`, scope, secret.secretName)
|
|
37
|
+
utils.createCfnOutput(`${id}-secretArn`, scope, secret.secretArn)
|
|
38
|
+
|
|
39
|
+
return secret
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
/**
|
|
@@ -56,20 +55,23 @@ export class SecretsManager {
|
|
|
56
55
|
}
|
|
57
56
|
|
|
58
57
|
/**
|
|
59
|
-
* @summary Method to
|
|
60
|
-
* @param id scoped id of the resource
|
|
58
|
+
* @summary Method to resolve secret value from a secret using AWS SDK
|
|
61
59
|
* @param scope scope in which this resource is defined
|
|
62
|
-
* @param
|
|
60
|
+
* @param secretId the secret name/ARN
|
|
61
|
+
* @param secretKey the secret key to resolve the value for
|
|
63
62
|
*/
|
|
64
|
-
public
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
public async resolveSecretValue(scope: CommonConstruct, secretId: string, secretKey: string) {
|
|
64
|
+
const client = new SecretsManagerClient({
|
|
65
|
+
credentials: utils.determineCredentials(),
|
|
66
|
+
region: scope.props.region,
|
|
68
67
|
})
|
|
68
|
+
const command = new GetSecretValueCommand({
|
|
69
|
+
SecretId: secretId,
|
|
70
|
+
})
|
|
71
|
+
const response = await client.send(command)
|
|
72
|
+
if (!response.SecretString) throw `Unable to resolve secret for ${secretId}`
|
|
73
|
+
const secretString = JSON.parse(response.SecretString)
|
|
69
74
|
|
|
70
|
-
|
|
71
|
-
utils.createCfnOutput(`${id}-secretArn`, scope, secret.secretArn)
|
|
72
|
-
|
|
73
|
-
return secret
|
|
75
|
+
return secretString[secretKey]
|
|
74
76
|
}
|
|
75
77
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as cdk from 'aws-cdk-lib'
|
|
2
2
|
import * as _ from 'lodash'
|
|
3
3
|
import { CommonConstruct } from '../../common'
|
|
4
|
+
import { fromEnv, fromIni } from '@aws-sdk/credential-providers'
|
|
5
|
+
import { AwsCredentialIdentityProvider } from '@aws-sdk/types'
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* @summary Helper method to add CloudFormation outputs from the construct
|
|
@@ -29,3 +31,8 @@ export function createCfnOutput(
|
|
|
29
31
|
}
|
|
30
32
|
return output
|
|
31
33
|
}
|
|
34
|
+
|
|
35
|
+
export function determineCredentials(): AwsCredentialIdentityProvider {
|
|
36
|
+
if (process.env.AWS_PROFILE) return fromIni()
|
|
37
|
+
return fromEnv()
|
|
38
|
+
}
|