serverless-kms-alias 2.0.3 → 2.1.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/.devcontainer/devcontainer.json +16 -0
- package/CHANGELOG.md +9 -0
- package/README.md +25 -2
- package/dist/index.js +16 -2
- package/dist/types/KmsAliasSettings.js +3 -0
- package/dist/types/ServerlessOptions.js +3 -0
- package/dist/types/index.js +3 -1
- package/package.json +18 -18
- package/src/index.ts +16 -2
- package/src/types/KmsAliasSettings.ts +3 -0
- package/src/types/ServerlessInstance.ts +13 -0
- package/src/types/ServerlessOptions.ts +3 -0
- package/src/types/index.ts +2 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "serverless-kms-alias",
|
|
3
|
+
"features": {
|
|
4
|
+
"ghcr.io/devcontainers/features/node:1": {
|
|
5
|
+
"version": "lts"
|
|
6
|
+
}
|
|
7
|
+
},
|
|
8
|
+
"customizations": {
|
|
9
|
+
"vscode": {
|
|
10
|
+
"extensions": [
|
|
11
|
+
"EditorConfig.EditorConfig"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"postCreateCommand": "npm install"
|
|
16
|
+
}
|
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ service: foo
|
|
|
18
18
|
provider:
|
|
19
19
|
name: aws
|
|
20
20
|
kmsKeyArn: '${kms:alias/aws/lambda}'
|
|
21
|
-
runtime:
|
|
21
|
+
runtime: nodejs16.x
|
|
22
22
|
|
|
23
23
|
plugins:
|
|
24
24
|
- serverless-kms-alias
|
|
@@ -34,7 +34,7 @@ functions:
|
|
|
34
34
|
service: foo
|
|
35
35
|
provider:
|
|
36
36
|
name: aws
|
|
37
|
-
runtime:
|
|
37
|
+
runtime: nodejs16.x
|
|
38
38
|
|
|
39
39
|
plugins:
|
|
40
40
|
- serverless-kms-alias
|
|
@@ -44,3 +44,26 @@ functions:
|
|
|
44
44
|
handler: foo.handler
|
|
45
45
|
kmsKeyArn: '${kms:arn:aws:kms:${aws:region}:${aws:accountId}:alias/aws/lambda}'
|
|
46
46
|
```
|
|
47
|
+
|
|
48
|
+
### Example - Enable for specific stages
|
|
49
|
+
|
|
50
|
+
```yaml
|
|
51
|
+
service: foo
|
|
52
|
+
provider:
|
|
53
|
+
name: aws
|
|
54
|
+
runtime: nodejs16.x
|
|
55
|
+
|
|
56
|
+
plugins:
|
|
57
|
+
- serverless-kms-alias
|
|
58
|
+
|
|
59
|
+
custom:
|
|
60
|
+
kmsAlias:
|
|
61
|
+
stages:
|
|
62
|
+
# list of stages for which the plugin should be enabled
|
|
63
|
+
- production
|
|
64
|
+
|
|
65
|
+
functions:
|
|
66
|
+
foo:
|
|
67
|
+
handler: foo.handler
|
|
68
|
+
kmsKeyArn: '${kms:arn:aws:kms:${aws:region}:${aws:accountId}:alias/aws/lambda}'
|
|
69
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const client_kms_1 = require("@aws-sdk/client-kms");
|
|
3
3
|
class KmsAliasPlugin {
|
|
4
|
-
constructor(serverless) {
|
|
4
|
+
constructor(serverless, options) {
|
|
5
5
|
this.configurationVariablesSources = {
|
|
6
6
|
kms: {
|
|
7
7
|
async resolve({ address }) {
|
|
8
8
|
if (!/^(alias\/[a-zA-Z]|arn:aws:kms:[\w-]*:[\d]*:alias)/i.test(address)) {
|
|
9
9
|
throw new Error(`Expected variable in the form of 'kms:alias/foo'`);
|
|
10
10
|
}
|
|
11
|
+
if (serverless.service?.custom?.kmsAlias?.stages?.length) {
|
|
12
|
+
const stage = options?.stage || serverless.config?.stage || serverless.service?.provider?.stage;
|
|
13
|
+
if (stage) {
|
|
14
|
+
if (!serverless.service.custom.kmsAlias.stages.includes(stage)) {
|
|
15
|
+
serverless.cli.log(`Info: KMS Alias plugin not enabled for stage`);
|
|
16
|
+
return {
|
|
17
|
+
value: address,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
serverless.cli.log(`Warn: Unable to determine stage for KMS alias`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
11
25
|
serverless.cli.log(`Info: Fetching KMS key for alias: ${address}`);
|
|
12
26
|
const client = new client_kms_1.KMSClient({
|
|
13
27
|
...serverless.providers.aws.getCredentials(),
|
|
@@ -34,4 +48,4 @@ class KmsAliasPlugin {
|
|
|
34
48
|
}
|
|
35
49
|
}
|
|
36
50
|
module.exports = KmsAliasPlugin;
|
|
37
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
51
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLG9EQUFvRTtBQWtCcEUsTUFBTSxjQUFjO0lBR2xCLFlBQW1CLFVBQThCLEVBQUUsT0FBMEI7UUFDM0UsSUFBSSxDQUFDLDZCQUE2QixHQUFHO1lBQ25DLEdBQUcsRUFBRTtnQkFDSCxLQUFLLENBQUMsT0FBTyxDQUFDLEVBQUUsT0FBTyxFQUFpQjtvQkFDdEMsSUFBSSxDQUFDLG9EQUFvRCxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsRUFBRTt3QkFDdkUsTUFBTSxJQUFJLEtBQUssQ0FBQyxrREFBa0QsQ0FBQyxDQUFDO3FCQUNyRTtvQkFFRCxJQUFJLFVBQVUsQ0FBQyxPQUFPLEVBQUUsTUFBTSxFQUFFLFFBQVEsRUFBRSxNQUFNLEVBQUUsTUFBTSxFQUFFO3dCQUN4RCxNQUFNLEtBQUssR0FBRyxPQUFPLEVBQUUsS0FBSyxJQUFJLFVBQVUsQ0FBQyxNQUFNLEVBQUUsS0FBSyxJQUFJLFVBQVUsQ0FBQy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0FBSyxDQUFDLDZDQUE2QyxPQUFPLEVBQUUsQ0FBQyxDQUFDO3FCQUN6RTtvQkFFRCxJQUFJLENBQUMsV0FBVyxDQUFDLEdBQUcsRUFBRTt3QkFDcEIsTUFBTSxJQUFJLEtBQUssQ0FBQywwQ0FBMEMsT0FBTyxFQUFFLENBQUMsQ0FBQztxQkFDdEU7b0JBRUQsVUFBVSxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsa0NBQWtDLE9BQU8sTUFBTSxXQUFXLENBQUMsR0FBRyxFQUFFLENBQUMsQ0FBQztvQkFFckYsT0FBTzt3QkFDTCxLQUFLLEVBQUUsV0FBVyxDQUFDLEdBQUc7cUJBQ3ZCLENBQUM7Z0JBQ0osQ0FBQzthQUNGO1NBQ0YsQ0FBQztJQUNKLENBQUM7Q0FDRjtBQUVELGlCQUFTLGNBQWMsQ0FBQyJ9
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiS21zQWxpYXNTZXR0aW5ncy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90eXBlcy9LbXNBbGlhc1NldHRpbmdzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ==
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2VydmVybGVzc09wdGlvbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdHlwZXMvU2VydmVybGVzc09wdGlvbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
package/dist/types/index.js
CHANGED
|
@@ -14,5 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./KmsAliasSettings"), exports);
|
|
17
18
|
__exportStar(require("./ServerlessInstance"), exports);
|
|
18
|
-
|
|
19
|
+
__exportStar(require("./ServerlessOptions"), exports);
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdHlwZXMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLHFEQUFtQztBQUNuQyx1REFBcUM7QUFDckMsc0RBQW9DIn0=
|
package/package.json
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "serverless-kms-alias",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">= 14"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@aws-sdk/client-kms": "^3.
|
|
8
|
+
"@aws-sdk/client-kms": "^3.266.1"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@types/lodash": "4.14.
|
|
12
|
-
"@types/serverless": "3.12.
|
|
13
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
14
|
-
"@typescript-eslint/parser": "5.
|
|
15
|
-
"eslint": "8.
|
|
11
|
+
"@types/lodash": "4.14.191",
|
|
12
|
+
"@types/serverless": "3.12.10",
|
|
13
|
+
"@typescript-eslint/eslint-plugin": "5.51.0",
|
|
14
|
+
"@typescript-eslint/parser": "5.51.0",
|
|
15
|
+
"eslint": "8.33.0",
|
|
16
16
|
"eslint-config-airbnb-base": "15.0.0",
|
|
17
17
|
"eslint-config-airbnb-typescript": "17.0.0",
|
|
18
|
-
"eslint-config-prettier": "8.
|
|
19
|
-
"eslint-plugin-import": "2.
|
|
20
|
-
"eslint-plugin-jsdoc": "39.
|
|
18
|
+
"eslint-config-prettier": "8.6.0",
|
|
19
|
+
"eslint-plugin-import": "2.27.5",
|
|
20
|
+
"eslint-plugin-jsdoc": "39.8.0",
|
|
21
21
|
"eslint-plugin-prettier": "4.2.1",
|
|
22
|
-
"eslint-plugin-promise": "6.
|
|
23
|
-
"eslint-plugin-security": "1.
|
|
24
|
-
"husky": "8.0.
|
|
25
|
-
"lint-staged": "13.
|
|
26
|
-
"markdownlint-cli": "0.
|
|
22
|
+
"eslint-plugin-promise": "6.1.1",
|
|
23
|
+
"eslint-plugin-security": "1.7.1",
|
|
24
|
+
"husky": "8.0.3",
|
|
25
|
+
"lint-staged": "13.1.1",
|
|
26
|
+
"markdownlint-cli": "0.33.0",
|
|
27
27
|
"npm-run-all": "4.1.5",
|
|
28
28
|
"pinst": "3.0.0",
|
|
29
|
-
"prettier": "2.
|
|
30
|
-
"prettier-plugin-packagejson": "2.
|
|
31
|
-
"typescript": "4.
|
|
29
|
+
"prettier": "2.8.4",
|
|
30
|
+
"prettier-plugin-packagejson": "2.4.2",
|
|
31
|
+
"typescript": "4.9.5"
|
|
32
32
|
},
|
|
33
33
|
"main": "dist/index.js",
|
|
34
34
|
"license": "MIT",
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DescribeKeyCommand, KMSClient } from '@aws-sdk/client-kms';
|
|
2
2
|
|
|
3
|
-
import type { ServerlessInstance } from './types';
|
|
3
|
+
import type { ServerlessInstance, ServerlessOptions } from './types';
|
|
4
4
|
|
|
5
5
|
interface ResolveParams {
|
|
6
6
|
address: string;
|
|
@@ -19,7 +19,7 @@ interface ServerlessVariableSource {
|
|
|
19
19
|
class KmsAliasPlugin {
|
|
20
20
|
public configurationVariablesSources: Record<string, ServerlessVariableSource>;
|
|
21
21
|
|
|
22
|
-
public constructor(serverless: ServerlessInstance) {
|
|
22
|
+
public constructor(serverless: ServerlessInstance, options: ServerlessOptions) {
|
|
23
23
|
this.configurationVariablesSources = {
|
|
24
24
|
kms: {
|
|
25
25
|
async resolve({ address }: ResolveParams): Promise<ResolveResult> {
|
|
@@ -27,6 +27,20 @@ class KmsAliasPlugin {
|
|
|
27
27
|
throw new Error(`Expected variable in the form of 'kms:alias/foo'`);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
if (serverless.service?.custom?.kmsAlias?.stages?.length) {
|
|
31
|
+
const stage = options?.stage || serverless.config?.stage || serverless.service?.provider?.stage;
|
|
32
|
+
if (stage) {
|
|
33
|
+
if (!serverless.service.custom.kmsAlias.stages.includes(stage)) {
|
|
34
|
+
serverless.cli.log(`Info: KMS Alias plugin not enabled for stage`);
|
|
35
|
+
return {
|
|
36
|
+
value: address,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
serverless.cli.log(`Warn: Unable to determine stage for KMS alias`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
30
44
|
serverless.cli.log(`Info: Fetching KMS key for alias: ${address}`);
|
|
31
45
|
|
|
32
46
|
const client = new KMSClient({
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import type { AwsAuthInputConfig } from '@aws-sdk/middleware-signing/dist-types/configurations';
|
|
2
2
|
|
|
3
|
+
import type { KmsAliasSettings } from './KmsAliasSettings';
|
|
4
|
+
|
|
3
5
|
export interface ServerlessInstance {
|
|
6
|
+
config?: {
|
|
7
|
+
stage?: string;
|
|
8
|
+
};
|
|
4
9
|
providers: {
|
|
5
10
|
aws: {
|
|
6
11
|
getCredentials(): AwsAuthInputConfig['credentials'];
|
|
7
12
|
getRegion(): string;
|
|
8
13
|
};
|
|
9
14
|
};
|
|
15
|
+
service: {
|
|
16
|
+
provider: {
|
|
17
|
+
stage?: string;
|
|
18
|
+
};
|
|
19
|
+
custom: {
|
|
20
|
+
kmsAlias?: KmsAliasSettings;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
10
23
|
cli: {
|
|
11
24
|
log(str: string, entity?: string): void;
|
|
12
25
|
};
|
package/src/types/index.ts
CHANGED