@aws-blocks/bb-app-setting 0.2.0 → 0.2.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/index.cdk.d.ts.map +1 -1
- package/dist/index.cdk.js +9 -2
- package/dist/index.cdk.test.js +13 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/src/index.cdk.test.ts +14 -3
- package/src/index.cdk.ts +9 -2
- package/src/version.ts +1 -1
package/dist/index.cdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cdk.d.ts","sourceRoot":"","sources":["../src/index.cdk.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cdk.d.ts","sourceRoot":"","sources":["../src/index.cdk.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,EAAwC,MAAM,sBAAsB,CAAC;AACnF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,iBAAiB,EAA6B,MAAM,YAAY,CAAC;AAE/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;;;;;;;GAUG;AACH,qBAAa,UAAU,CAAC,CAAC,GAAG,MAAM,CAAE,SAAQ,KAAK;IAChD;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,MAAM,EAC7B,KAAK,EAAE,WAAW,EAClB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAC7D,UAAU,CAAC,CAAC,CAAC;gBAKJ,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC;CAyJzE"}
|
package/dist/index.cdk.js
CHANGED
|
@@ -4,6 +4,7 @@ import * as cdk from 'aws-cdk-lib';
|
|
|
4
4
|
import * as ssm from 'aws-cdk-lib/aws-ssm';
|
|
5
5
|
import * as iam from 'aws-cdk-lib/aws-iam';
|
|
6
6
|
import * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
7
|
+
import { LogGroup } from 'aws-cdk-lib/aws-logs';
|
|
7
8
|
import * as cr from 'aws-cdk-lib/custom-resources';
|
|
8
9
|
import { Scope, registerConfig, DEFAULT_NODE_RUNTIME } from '@aws-blocks/core/cdk';
|
|
9
10
|
import { AppSettingErrors } from './errors.js';
|
|
@@ -112,7 +113,7 @@ export class AppSetting extends Scope {
|
|
|
112
113
|
// then fail tagging it (AddTagsToResource needs ssm:GetParameters).
|
|
113
114
|
// We only need runtime read access, granted below.
|
|
114
115
|
if (!external) {
|
|
115
|
-
registerSecret(cdk.Stack.of(this), parameterName, options.kmsKeyArn);
|
|
116
|
+
registerSecret(cdk.Stack.of(this), parameterName, this.defaults.logRetention, options.kmsKeyArn);
|
|
116
117
|
}
|
|
117
118
|
// Grant the handler KMS access. External secrets are read-only (Decrypt
|
|
118
119
|
// only); stack-managed secrets also need Encrypt so the app can write the
|
|
@@ -171,7 +172,7 @@ const SECRET_BULK_KEY = Symbol.for('BLOCKS_SECRET_BULK_INIT');
|
|
|
171
172
|
* All subsequent calls just append to the parameter list (resolved lazily at
|
|
172
173
|
* synth time).
|
|
173
174
|
*/
|
|
174
|
-
function registerSecret(stack, parameterName, keyId) {
|
|
175
|
+
function registerSecret(stack, parameterName, logRetention, keyId) {
|
|
175
176
|
let state = stack[SECRET_BULK_KEY];
|
|
176
177
|
if (state) {
|
|
177
178
|
state.params.push({ name: parameterName, keyId });
|
|
@@ -183,6 +184,12 @@ function registerSecret(stack, parameterName, keyId) {
|
|
|
183
184
|
const secretInitFn = new lambda.Function(stack, 'BlocksSecretInitFn', {
|
|
184
185
|
runtime: DEFAULT_NODE_RUNTIME,
|
|
185
186
|
handler: 'index.handler',
|
|
187
|
+
// Own the log group so its retention follows the stack-wide default
|
|
188
|
+
// instead of AWS's infinite retention.
|
|
189
|
+
logGroup: new LogGroup(stack, 'BlocksSecretInitLogs', {
|
|
190
|
+
retention: logRetention,
|
|
191
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
192
|
+
}),
|
|
186
193
|
code: lambda.Code.fromInline(`
|
|
187
194
|
const { SSMClient, GetParameterCommand, PutParameterCommand, DeleteParameterCommand, AddTagsToResourceCommand } = require('@aws-sdk/client-ssm');
|
|
188
195
|
const crypto = require('crypto');
|
package/dist/index.cdk.test.js
CHANGED
|
@@ -10,12 +10,13 @@ import { test } from 'node:test';
|
|
|
10
10
|
import assert from 'node:assert';
|
|
11
11
|
import * as cdk from 'aws-cdk-lib';
|
|
12
12
|
import { Template, Match } from 'aws-cdk-lib/assertions';
|
|
13
|
-
import { Scope, DEFAULT_NODE_RUNTIME } from '@aws-blocks/core/cdk';
|
|
13
|
+
import { Scope, DEFAULT_NODE_RUNTIME, BlocksPresets } from '@aws-blocks/core/cdk';
|
|
14
14
|
import { AppSetting } from './index.cdk.js';
|
|
15
15
|
class StubBlocksStack extends cdk.Stack {
|
|
16
16
|
handler;
|
|
17
17
|
executionRole;
|
|
18
18
|
id;
|
|
19
|
+
defaults = BlocksPresets.production;
|
|
19
20
|
constructor(scope, id) {
|
|
20
21
|
super(scope, id);
|
|
21
22
|
this.id = id;
|
|
@@ -31,12 +32,21 @@ class StubBlocksStack extends cdk.Stack {
|
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
|
-
function setup() {
|
|
35
|
+
function setup(defaults = BlocksPresets.production, stackId = 'TestStack') {
|
|
35
36
|
const app = new cdk.App();
|
|
36
|
-
const stack = new StubBlocksStack(app,
|
|
37
|
+
const stack = new StubBlocksStack(app, stackId);
|
|
38
|
+
stack.defaults = defaults;
|
|
37
39
|
const parent = new Scope('app');
|
|
38
40
|
return { stack, parent };
|
|
39
41
|
}
|
|
42
|
+
test('CDK: the secret-init Lambda log group adopts defaults.logRetention', () => {
|
|
43
|
+
const { stack, parent } = setup(BlocksPresets.sandbox, 'SecretRetentionStack');
|
|
44
|
+
new AppSetting(parent, 'my-secret', { secret: true, name: '/myapp/secret-key' });
|
|
45
|
+
const template = Template.fromStack(stack);
|
|
46
|
+
// The secret-init Lambda now owns an explicit log group whose retention
|
|
47
|
+
// follows the stack-wide default (sandbox → one week) instead of infinite.
|
|
48
|
+
template.hasResourceProperties('AWS::Logs::LogGroup', { RetentionInDays: 7 });
|
|
49
|
+
});
|
|
40
50
|
test('CDK: secret AppSetting SSM policy is scoped to specific parameter ARN (not wildcard)', () => {
|
|
41
51
|
const { stack, parent } = setup();
|
|
42
52
|
new AppSetting(parent, 'my-secret', { secret: true, name: '/myapp/secret-key' });
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-blocks/bb-app-setting",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/aws-devtools-labs/aws-blocks.git",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"test": "node --test --test-concurrency=1 dist/**/*.test.js"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@aws-blocks/core": "^0.
|
|
43
|
-
"@aws-blocks/bb-logger": "^0.1.
|
|
42
|
+
"@aws-blocks/core": "^0.4.0",
|
|
43
|
+
"@aws-blocks/bb-logger": "^0.1.6",
|
|
44
44
|
"@aws-sdk/client-ssm": "^3.0.0",
|
|
45
45
|
"@standard-schema/spec": "^1.1.0"
|
|
46
46
|
},
|
package/src/index.cdk.test.ts
CHANGED
|
@@ -12,13 +12,14 @@ import assert from 'node:assert';
|
|
|
12
12
|
import * as cdk from 'aws-cdk-lib';
|
|
13
13
|
import type { Construct } from 'constructs';
|
|
14
14
|
import { Template, Match } from 'aws-cdk-lib/assertions';
|
|
15
|
-
import { Scope, DEFAULT_NODE_RUNTIME } from '@aws-blocks/core/cdk';
|
|
15
|
+
import { Scope, DEFAULT_NODE_RUNTIME, BlocksPresets, type BlocksDefaults } from '@aws-blocks/core/cdk';
|
|
16
16
|
import { AppSetting } from './index.cdk.js';
|
|
17
17
|
|
|
18
18
|
class StubBlocksStack extends cdk.Stack {
|
|
19
19
|
public readonly handler: cdk.aws_lambda.Function;
|
|
20
20
|
public readonly executionRole: cdk.aws_iam.IRole;
|
|
21
21
|
public readonly id: string;
|
|
22
|
+
public defaults: BlocksDefaults = BlocksPresets.production;
|
|
22
23
|
constructor(scope: Construct, id: string) {
|
|
23
24
|
super(scope, id);
|
|
24
25
|
this.id = id;
|
|
@@ -35,13 +36,23 @@ class StubBlocksStack extends cdk.Stack {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
function setup(): { stack: StubBlocksStack; parent: Scope } {
|
|
39
|
+
function setup(defaults: BlocksDefaults = BlocksPresets.production, stackId = 'TestStack'): { stack: StubBlocksStack; parent: Scope } {
|
|
39
40
|
const app = new cdk.App();
|
|
40
|
-
const stack = new StubBlocksStack(app,
|
|
41
|
+
const stack = new StubBlocksStack(app, stackId);
|
|
42
|
+
stack.defaults = defaults;
|
|
41
43
|
const parent = new Scope('app');
|
|
42
44
|
return { stack, parent };
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
test('CDK: the secret-init Lambda log group adopts defaults.logRetention', () => {
|
|
48
|
+
const { stack, parent } = setup(BlocksPresets.sandbox, 'SecretRetentionStack');
|
|
49
|
+
new AppSetting(parent, 'my-secret', { secret: true, name: '/myapp/secret-key' });
|
|
50
|
+
const template = Template.fromStack(stack);
|
|
51
|
+
// The secret-init Lambda now owns an explicit log group whose retention
|
|
52
|
+
// follows the stack-wide default (sandbox → one week) instead of infinite.
|
|
53
|
+
template.hasResourceProperties('AWS::Logs::LogGroup', { RetentionInDays: 7 });
|
|
54
|
+
});
|
|
55
|
+
|
|
45
56
|
test('CDK: secret AppSetting SSM policy is scoped to specific parameter ARN (not wildcard)', () => {
|
|
46
57
|
const { stack, parent } = setup();
|
|
47
58
|
new AppSetting(parent, 'my-secret', { secret: true, name: '/myapp/secret-key' });
|
package/src/index.cdk.ts
CHANGED
|
@@ -5,6 +5,7 @@ import * as cdk from 'aws-cdk-lib';
|
|
|
5
5
|
import * as ssm from 'aws-cdk-lib/aws-ssm';
|
|
6
6
|
import * as iam from 'aws-cdk-lib/aws-iam';
|
|
7
7
|
import * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
8
|
+
import { LogGroup, type RetentionDays } from 'aws-cdk-lib/aws-logs';
|
|
8
9
|
import * as cr from 'aws-cdk-lib/custom-resources';
|
|
9
10
|
import { Scope, registerConfig, DEFAULT_NODE_RUNTIME } from '@aws-blocks/core/cdk';
|
|
10
11
|
import type { ScopeParent } from '@aws-blocks/core';
|
|
@@ -151,7 +152,7 @@ export class AppSetting<T = string> extends Scope {
|
|
|
151
152
|
// then fail tagging it (AddTagsToResource needs ssm:GetParameters).
|
|
152
153
|
// We only need runtime read access, granted below.
|
|
153
154
|
if (!external) {
|
|
154
|
-
registerSecret(cdk.Stack.of(this), parameterName, options.kmsKeyArn);
|
|
155
|
+
registerSecret(cdk.Stack.of(this), parameterName, this.defaults.logRetention, options.kmsKeyArn);
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
// Grant the handler KMS access. External secrets are read-only (Decrypt
|
|
@@ -223,7 +224,7 @@ interface SecretBulkState {
|
|
|
223
224
|
* All subsequent calls just append to the parameter list (resolved lazily at
|
|
224
225
|
* synth time).
|
|
225
226
|
*/
|
|
226
|
-
function registerSecret(stack: cdk.Stack, parameterName: string, keyId?: string): void {
|
|
227
|
+
function registerSecret(stack: cdk.Stack, parameterName: string, logRetention: RetentionDays, keyId?: string): void {
|
|
227
228
|
let state = (stack as any)[SECRET_BULK_KEY] as SecretBulkState | undefined;
|
|
228
229
|
if (state) {
|
|
229
230
|
state.params.push({ name: parameterName, keyId });
|
|
@@ -237,6 +238,12 @@ function registerSecret(stack: cdk.Stack, parameterName: string, keyId?: string)
|
|
|
237
238
|
const secretInitFn = new lambda.Function(stack, 'BlocksSecretInitFn', {
|
|
238
239
|
runtime: DEFAULT_NODE_RUNTIME,
|
|
239
240
|
handler: 'index.handler',
|
|
241
|
+
// Own the log group so its retention follows the stack-wide default
|
|
242
|
+
// instead of AWS's infinite retention.
|
|
243
|
+
logGroup: new LogGroup(stack, 'BlocksSecretInitLogs', {
|
|
244
|
+
retention: logRetention,
|
|
245
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
246
|
+
}),
|
|
240
247
|
code: lambda.Code.fromInline(`
|
|
241
248
|
const { SSMClient, GetParameterCommand, PutParameterCommand, DeleteParameterCommand, AddTagsToResourceCommand } = require('@aws-sdk/client-ssm');
|
|
242
249
|
const crypto = require('crypto');
|
package/src/version.ts
CHANGED