@gradientedge/cdk-utils 8.27.0 → 8.29.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.
- package/dist/src/lib/manager/aws/api-manager.js +1 -1
- package/dist/src/lib/manager/aws/secrets-manager.d.ts +2 -6
- package/dist/src/lib/manager/aws/secrets-manager.js +3 -29
- package/package.json +10 -10
- package/src/lib/manager/aws/api-manager.ts +1 -1
- package/src/lib/manager/aws/secrets-manager.ts +3 -36
|
@@ -60,7 +60,7 @@ class ApiManager {
|
|
|
60
60
|
throw `Api props undefined for ${id}`;
|
|
61
61
|
const api = new apig.LambdaRestApi(scope, `${id}`, {
|
|
62
62
|
binaryMediaTypes: props.binaryMediaTypes,
|
|
63
|
-
|
|
63
|
+
minCompressionSize: props.minCompressionSize,
|
|
64
64
|
defaultMethodOptions: props.defaultMethodOptions,
|
|
65
65
|
deploy: props.deploy || true,
|
|
66
66
|
deployOptions: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SecretsManager as SM } from '@aws-sdk/client-secrets-manager';
|
|
1
2
|
import * as cdk from 'aws-cdk-lib';
|
|
2
3
|
import * as common from '../../common';
|
|
3
4
|
/**
|
|
@@ -25,7 +26,7 @@ export declare class SecretsManager {
|
|
|
25
26
|
*
|
|
26
27
|
* @param {string} region
|
|
27
28
|
*/
|
|
28
|
-
getAwsSecretsManager(region: string):
|
|
29
|
+
getAwsSecretsManager(region: string): SM;
|
|
29
30
|
/**
|
|
30
31
|
* @stability experimental
|
|
31
32
|
* @summary Method to load a secret from secrets manager
|
|
@@ -40,11 +41,6 @@ export declare class SecretsManager {
|
|
|
40
41
|
* @param {string} region
|
|
41
42
|
*/
|
|
42
43
|
loadSecrets(secretNames: string, region: string): Promise<{}>;
|
|
43
|
-
/**
|
|
44
|
-
* @stability experimental
|
|
45
|
-
* @summary Method to export secrets from secrets manager to a dot env format
|
|
46
|
-
*/
|
|
47
|
-
exportToDotEnv(): void;
|
|
48
44
|
/**
|
|
49
45
|
* @stability stable
|
|
50
46
|
* @summary Method to retrieve a secret from secrets manager with a cloudformation export
|
|
@@ -24,10 +24,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.SecretsManager = void 0;
|
|
27
|
+
const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
|
|
27
28
|
const cdk = __importStar(require("aws-cdk-lib"));
|
|
28
29
|
const secretsManager = __importStar(require("aws-cdk-lib/aws-secretsmanager"));
|
|
29
|
-
const AWS = require('aws-sdk');
|
|
30
|
-
const fs = require('fs');
|
|
31
30
|
/**
|
|
32
31
|
* @stability experimental
|
|
33
32
|
* @category cdk-utils.secrets-manager
|
|
@@ -54,7 +53,7 @@ class SecretsManager {
|
|
|
54
53
|
* @param {string} region
|
|
55
54
|
*/
|
|
56
55
|
getAwsSecretsManager(region) {
|
|
57
|
-
return new
|
|
56
|
+
return new client_secrets_manager_1.SecretsManager({ region: region });
|
|
58
57
|
}
|
|
59
58
|
/**
|
|
60
59
|
* @stability experimental
|
|
@@ -64,7 +63,7 @@ class SecretsManager {
|
|
|
64
63
|
*/
|
|
65
64
|
async loadSecret(secretName, region) {
|
|
66
65
|
const secretsManager = this.getAwsSecretsManager(region);
|
|
67
|
-
const secret = await Promise.all([secretsManager.getSecretValue({ SecretId: secretName })
|
|
66
|
+
const secret = await Promise.all([secretsManager.getSecretValue({ SecretId: secretName })]);
|
|
68
67
|
return secret ? JSON.parse(secret[0].SecretString) : {};
|
|
69
68
|
}
|
|
70
69
|
/**
|
|
@@ -80,31 +79,6 @@ class SecretsManager {
|
|
|
80
79
|
}
|
|
81
80
|
return secrets;
|
|
82
81
|
}
|
|
83
|
-
/**
|
|
84
|
-
* @stability experimental
|
|
85
|
-
* @summary Method to export secrets from secrets manager to a dot env format
|
|
86
|
-
*/
|
|
87
|
-
exportToDotEnv() {
|
|
88
|
-
let nconf = require('nconf');
|
|
89
|
-
nconf.argv().env();
|
|
90
|
-
const appRoot = require('app-root-path');
|
|
91
|
-
if (nconf.get('profile')) {
|
|
92
|
-
console.log(`Using named aws profile ${nconf.get('profile')}`);
|
|
93
|
-
AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile: nconf.get('profile') });
|
|
94
|
-
}
|
|
95
|
-
const region = nconf.get('region');
|
|
96
|
-
AWS.config.update({ region: nconf.get('region') });
|
|
97
|
-
const outFileName = nconf.get('out') ? nconf.get('out') : '.env';
|
|
98
|
-
this.loadSecret(nconf.get('name'), region).then((secretString) => {
|
|
99
|
-
if (nconf.get('overwrite')) {
|
|
100
|
-
fs.writeFileSync(`${appRoot.path}/.env`, '');
|
|
101
|
-
}
|
|
102
|
-
Object.keys(secretString).forEach(function (key) {
|
|
103
|
-
console.log(`Adding environment variable for key: ${key}`);
|
|
104
|
-
fs.appendFileSync(`${appRoot.path}/${outFileName}`, `${key}=${secretString[key]}\r\n`);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
82
|
/**
|
|
109
83
|
* @stability stable
|
|
110
84
|
* @summary Method to retrieve a secret from secrets manager with a cloudformation export
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradientedge/cdk-utils",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.29.0",
|
|
4
4
|
"description": "Utilities for AWS CDK provisioning",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@types/lodash": "^4.14.191",
|
|
51
|
-
"@types/node": "^18.15.
|
|
51
|
+
"@types/node": "^18.15.3",
|
|
52
52
|
"app-root-path": "^3.1.0",
|
|
53
|
-
"aws-cdk-lib": "^2.
|
|
54
|
-
"aws-sdk": "^
|
|
55
|
-
"constructs": "^10.1.
|
|
53
|
+
"aws-cdk-lib": "^2.69.0",
|
|
54
|
+
"@aws-sdk/client-secrets-manager": "^3.293.0",
|
|
55
|
+
"constructs": "^10.1.280",
|
|
56
56
|
"lodash": "^4.17.21",
|
|
57
57
|
"moment": "^2.29.4",
|
|
58
58
|
"nconf": "^0.12.0",
|
|
@@ -61,16 +61,16 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
64
|
-
"@types/jest": "^29.
|
|
65
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
66
|
-
"@typescript-eslint/parser": "^5.
|
|
64
|
+
"@types/jest": "^29.5.0",
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
66
|
+
"@typescript-eslint/parser": "^5.55.0",
|
|
67
67
|
"aws-cdk": "*",
|
|
68
68
|
"babel-eslint": "^10.1.0",
|
|
69
69
|
"better-docs": "^2.7.2",
|
|
70
70
|
"codecov": "^3.8.3",
|
|
71
71
|
"commitizen": "^4.3.0",
|
|
72
72
|
"dotenv": "^16.0.3",
|
|
73
|
-
"eslint": "^8.
|
|
73
|
+
"eslint": "^8.36.0",
|
|
74
74
|
"eslint-config-prettier": "^8.7.0",
|
|
75
75
|
"eslint-plugin-import": "^2.27.5",
|
|
76
76
|
"husky": "^8.0.3",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"taffydb": "^2.7.3",
|
|
89
89
|
"ts-jest": "^29.0.5",
|
|
90
90
|
"ts-node": "^10.9.1",
|
|
91
|
-
"typescript": "
|
|
91
|
+
"typescript": "5.0.2"
|
|
92
92
|
},
|
|
93
93
|
"optionalDependencies": {
|
|
94
94
|
"@babel/core": "^7.21.00",
|
|
@@ -42,7 +42,7 @@ export class ApiManager {
|
|
|
42
42
|
if (!props) throw `Api props undefined for ${id}`
|
|
43
43
|
const api = new apig.LambdaRestApi(scope, `${id}`, {
|
|
44
44
|
binaryMediaTypes: props.binaryMediaTypes,
|
|
45
|
-
|
|
45
|
+
minCompressionSize: props.minCompressionSize,
|
|
46
46
|
defaultMethodOptions: props.defaultMethodOptions,
|
|
47
47
|
deploy: props.deploy || true,
|
|
48
48
|
deployOptions: {
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
+
import { SecretsManager as SM } from '@aws-sdk/client-secrets-manager'
|
|
1
2
|
import * as cdk from 'aws-cdk-lib'
|
|
2
3
|
import * as secretsManager from 'aws-cdk-lib/aws-secretsmanager'
|
|
3
4
|
import * as common from '../../common'
|
|
4
5
|
|
|
5
|
-
const AWS = require('aws-sdk')
|
|
6
|
-
const fs = require('fs')
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* @stability experimental
|
|
10
8
|
* @category cdk-utils.secrets-manager
|
|
@@ -31,7 +29,7 @@ export class SecretsManager {
|
|
|
31
29
|
* @param {string} region
|
|
32
30
|
*/
|
|
33
31
|
public getAwsSecretsManager(region: string) {
|
|
34
|
-
return new
|
|
32
|
+
return new SM({ region: region })
|
|
35
33
|
}
|
|
36
34
|
|
|
37
35
|
/**
|
|
@@ -42,7 +40,7 @@ export class SecretsManager {
|
|
|
42
40
|
*/
|
|
43
41
|
public async loadSecret(secretName: string, region: string) {
|
|
44
42
|
const secretsManager = this.getAwsSecretsManager(region)
|
|
45
|
-
const secret: any = await Promise.all([secretsManager.getSecretValue({ SecretId: secretName })
|
|
43
|
+
const secret: any = await Promise.all([secretsManager.getSecretValue({ SecretId: secretName })])
|
|
46
44
|
|
|
47
45
|
return secret ? JSON.parse(secret[0].SecretString) : {}
|
|
48
46
|
}
|
|
@@ -62,37 +60,6 @@ export class SecretsManager {
|
|
|
62
60
|
return secrets
|
|
63
61
|
}
|
|
64
62
|
|
|
65
|
-
/**
|
|
66
|
-
* @stability experimental
|
|
67
|
-
* @summary Method to export secrets from secrets manager to a dot env format
|
|
68
|
-
*/
|
|
69
|
-
public exportToDotEnv() {
|
|
70
|
-
let nconf = require('nconf')
|
|
71
|
-
nconf.argv().env()
|
|
72
|
-
const appRoot = require('app-root-path')
|
|
73
|
-
|
|
74
|
-
if (nconf.get('profile')) {
|
|
75
|
-
console.log(`Using named aws profile ${nconf.get('profile')}`)
|
|
76
|
-
AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile: nconf.get('profile') })
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const region = nconf.get('region')
|
|
80
|
-
AWS.config.update({ region: nconf.get('region') })
|
|
81
|
-
|
|
82
|
-
const outFileName = nconf.get('out') ? nconf.get('out') : '.env'
|
|
83
|
-
|
|
84
|
-
this.loadSecret(nconf.get('name'), region).then((secretString: any) => {
|
|
85
|
-
if (nconf.get('overwrite')) {
|
|
86
|
-
fs.writeFileSync(`${appRoot.path}/.env`, '')
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
Object.keys(secretString).forEach(function (key) {
|
|
90
|
-
console.log(`Adding environment variable for key: ${key}`)
|
|
91
|
-
fs.appendFileSync(`${appRoot.path}/${outFileName}`, `${key}=${secretString[key]}\r\n`)
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
|
|
96
63
|
/**
|
|
97
64
|
* @stability stable
|
|
98
65
|
* @summary Method to retrieve a secret from secrets manager with a cloudformation export
|