@composurecdk/logs 0.9.3 → 0.9.5

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/README.md CHANGED
@@ -50,3 +50,15 @@ CloudWatch Logs encrypts all log data at rest using AWS-managed keys. For additi
50
50
  ```ts
51
51
  const logGroup = createLogGroupBuilder().encryptionKey(myKmsKey).build(stack, "EncryptedLogs");
52
52
  ```
53
+
54
+ `.encryptionKey(...)` accepts a concrete key or a `Resolvable`, so a key built by [`@composurecdk/kms`](../kms/README.md) can be a component of the same system:
55
+
56
+ ```ts
57
+ compose(
58
+ {
59
+ logKey: createKeyBuilder().description("Encrypts the audit log group."),
60
+ audit: createLogGroupBuilder().encryptionKey(ref<KeyBuilderResult>("logKey").get("key")),
61
+ },
62
+ { logKey: [], audit: ["logKey"] },
63
+ );
64
+ ```
@@ -1,8 +1,34 @@
1
1
  import { LogGroup, type LogGroupProps } from "aws-cdk-lib/aws-logs";
2
2
  import { type IConstruct } from "constructs";
3
- import { type Lifecycle } from "@composurecdk/core";
3
+ import { type Lifecycle, type Resolvable } from "@composurecdk/core";
4
4
  import { type ITaggedBuilder } from "@composurecdk/cloudformation";
5
- export type LogGroupBuilderProps = LogGroupProps;
5
+ /**
6
+ * Configuration properties for the CloudWatch log group builder.
7
+ *
8
+ * The CDK {@link LogGroupProps} surface, with `encryptionKey` widened so the
9
+ * key can come from a composed component.
10
+ */
11
+ export interface LogGroupBuilderProps extends Omit<LogGroupProps, "encryptionKey"> {
12
+ /**
13
+ * The customer-managed KMS key used to encrypt the log group.
14
+ *
15
+ * Accepts a concrete key or a {@link Resolvable} — typically a {@link Ref}
16
+ * to a composed `@composurecdk/kms` key builder, so the key is a component
17
+ * of the system rather than a construct built outside it.
18
+ *
19
+ * CloudWatch Logs encrypts every log group with a service-managed key by
20
+ * default, so this prop opts into a customer-managed one. The key policy
21
+ * must allow the `logs.<region>.amazonaws.com` service principal — CDK adds
22
+ * that statement for a key it can see.
23
+ *
24
+ * The inner type is read from CDK's own prop rather than named as `IKey`, so
25
+ * it tracks the `kms.IKey` → `kms.IKeyRef` migration in either direction —
26
+ * see the table in `@composurecdk/kms`'s README.
27
+ *
28
+ * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/encrypt-log-data-kms.html
29
+ */
30
+ encryptionKey?: Resolvable<NonNullable<LogGroupProps["encryptionKey"]>>;
31
+ }
6
32
  /**
7
33
  * The build output of a {@link ILogGroupBuilder}. Contains the CDK constructs
8
34
  * created during {@link Lifecycle.build}, keyed by role.
@@ -32,7 +58,7 @@ export interface LogGroupBuilderResult {
32
58
  export type ILogGroupBuilder = ITaggedBuilder<LogGroupBuilderProps, LogGroupBuilder>;
33
59
  declare class LogGroupBuilder implements Lifecycle<LogGroupBuilderResult> {
34
60
  props: Partial<LogGroupBuilderProps>;
35
- build(scope: IConstruct, id: string): LogGroupBuilderResult;
61
+ build(scope: IConstruct, id: string, context?: Record<string, object>): LogGroupBuilderResult;
36
62
  }
37
63
  /**
38
64
  * Creates a new {@link ILogGroupBuilder} for configuring a CloudWatch log group.
@@ -1 +1 @@
1
- {"version":3,"file":"log-group-builder.d.ts","sourceRoot":"","sources":["../../src/log-group-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,8BAA8B,CAAC;AAGlF,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAEjD;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,iEAAiE;IACjE,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAAC,oBAAoB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,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,qBAAqB;CAa9F;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,qBAAqB,IAAI,gBAAgB,CAExD"}
@@ -2,14 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLogGroupBuilder = createLogGroupBuilder;
4
4
  const aws_logs_1 = require("aws-cdk-lib/aws-logs");
5
+ const core_1 = require("@composurecdk/core");
5
6
  const cloudformation_1 = require("@composurecdk/cloudformation");
6
7
  const defaults_js_1 = require("./defaults.js");
7
8
  class LogGroupBuilder {
8
9
  props = {};
9
- build(scope, id) {
10
+ build(scope, id, context) {
11
+ const { encryptionKey, ...logGroupProps } = this.props;
10
12
  const mergedProps = {
11
13
  ...defaults_js_1.LOG_GROUP_DEFAULTS,
12
- ...this.props,
14
+ ...logGroupProps,
15
+ ...(encryptionKey !== undefined ? { encryptionKey: (0, core_1.resolve)(encryptionKey, context) } : {}),
13
16
  };
14
17
  return {
15
18
  logGroup: new aws_logs_1.LogGroup(scope, id, mergedProps),
@@ -1 +1 @@
1
- {"version":3,"file":"log-group-builder.js","sourceRoot":"","sources":["../../src/log-group-builder.ts"],"names":[],"mappings":";;AA2EA,sDAEC;AA7ED,mDAAoE;AAGpE,iEAAkF;AAClF,+CAAmD;AAiCnD,MAAM,eAAe;IACnB,KAAK,GAAkC,EAAE,CAAC;IAE1C,KAAK,CAAC,KAAiB,EAAE,EAAU;QACjC,MAAM,WAAW,GAAG;YAClB,GAAG,gCAAkB;YACrB,GAAG,IAAI,CAAC,KAAK;SACd,CAAC;QACF,OAAO;YACL,QAAQ,EAAE,IAAI,mBAAQ,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,CAAC;SAC/C,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,qBAAqB;IACnC,OAAO,IAAA,8BAAa,EAAwC,eAAe,CAAC,CAAC;AAC/E,CAAC"}
1
+ {"version":3,"file":"log-group-builder.js","sourceRoot":"","sources":["../../src/log-group-builder.ts"],"names":[],"mappings":";;AAyGA,sDAEC;AA3GD,mDAAoE;AAEpE,6CAA8E;AAC9E,iEAAkF;AAClF,+CAAmD;AA2DnD,MAAM,eAAe;IACnB,KAAK,GAAkC,EAAE,CAAC;IAE1C,KAAK,CAAC,KAAiB,EAAE,EAAU,EAAE,OAAgC;QACnE,MAAM,EAAE,aAAa,EAAE,GAAG,aAAa,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAEvD,MAAM,WAAW,GAAG;YAClB,GAAG,gCAAkB;YACrB,GAAG,aAAa;YAChB,GAAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,IAAA,cAAO,EAAC,aAAa,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC3F,CAAC;QAEF,OAAO;YACL,QAAQ,EAAE,IAAI,mBAAQ,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,CAAC;SAC/C,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,qBAAqB;IACnC,OAAO,IAAA,8BAAa,EAAwC,eAAe,CAAC,CAAC;AAC/E,CAAC"}
@@ -1,8 +1,34 @@
1
1
  import { LogGroup, type LogGroupProps } from "aws-cdk-lib/aws-logs";
2
2
  import { type IConstruct } from "constructs";
3
- import { type Lifecycle } from "@composurecdk/core";
3
+ import { type Lifecycle, type Resolvable } from "@composurecdk/core";
4
4
  import { type ITaggedBuilder } from "@composurecdk/cloudformation";
5
- export type LogGroupBuilderProps = LogGroupProps;
5
+ /**
6
+ * Configuration properties for the CloudWatch log group builder.
7
+ *
8
+ * The CDK {@link LogGroupProps} surface, with `encryptionKey` widened so the
9
+ * key can come from a composed component.
10
+ */
11
+ export interface LogGroupBuilderProps extends Omit<LogGroupProps, "encryptionKey"> {
12
+ /**
13
+ * The customer-managed KMS key used to encrypt the log group.
14
+ *
15
+ * Accepts a concrete key or a {@link Resolvable} — typically a {@link Ref}
16
+ * to a composed `@composurecdk/kms` key builder, so the key is a component
17
+ * of the system rather than a construct built outside it.
18
+ *
19
+ * CloudWatch Logs encrypts every log group with a service-managed key by
20
+ * default, so this prop opts into a customer-managed one. The key policy
21
+ * must allow the `logs.<region>.amazonaws.com` service principal — CDK adds
22
+ * that statement for a key it can see.
23
+ *
24
+ * The inner type is read from CDK's own prop rather than named as `IKey`, so
25
+ * it tracks the `kms.IKey` → `kms.IKeyRef` migration in either direction —
26
+ * see the table in `@composurecdk/kms`'s README.
27
+ *
28
+ * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/encrypt-log-data-kms.html
29
+ */
30
+ encryptionKey?: Resolvable<NonNullable<LogGroupProps["encryptionKey"]>>;
31
+ }
6
32
  /**
7
33
  * The build output of a {@link ILogGroupBuilder}. Contains the CDK constructs
8
34
  * created during {@link Lifecycle.build}, keyed by role.
@@ -32,7 +58,7 @@ export interface LogGroupBuilderResult {
32
58
  export type ILogGroupBuilder = ITaggedBuilder<LogGroupBuilderProps, LogGroupBuilder>;
33
59
  declare class LogGroupBuilder implements Lifecycle<LogGroupBuilderResult> {
34
60
  props: Partial<LogGroupBuilderProps>;
35
- build(scope: IConstruct, id: string): LogGroupBuilderResult;
61
+ build(scope: IConstruct, id: string, context?: Record<string, object>): LogGroupBuilderResult;
36
62
  }
37
63
  /**
38
64
  * Creates a new {@link ILogGroupBuilder} for configuring a CloudWatch log group.
@@ -1 +1 @@
1
- {"version":3,"file":"log-group-builder.d.ts","sourceRoot":"","sources":["../../src/log-group-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;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;;;;;;;GAiBG;AACH,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC;AAErF,cAAM,eAAgB,YAAW,SAAS,CAAC,qBAAqB,CAAC;IAC/D,KAAK,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAM;IAE1C,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,qBAAqB;CAa9F;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,qBAAqB,IAAI,gBAAgB,CAExD"}
@@ -1,12 +1,15 @@
1
1
  import { LogGroup } from "aws-cdk-lib/aws-logs";
2
+ import { resolve } from "@composurecdk/core";
2
3
  import { taggedBuilder } from "@composurecdk/cloudformation";
3
4
  import { LOG_GROUP_DEFAULTS } from "./defaults.js";
4
5
  class LogGroupBuilder {
5
6
  props = {};
6
- build(scope, id) {
7
+ build(scope, id, context) {
8
+ const { encryptionKey, ...logGroupProps } = this.props;
7
9
  const mergedProps = {
8
10
  ...LOG_GROUP_DEFAULTS,
9
- ...this.props,
11
+ ...logGroupProps,
12
+ ...(encryptionKey !== undefined ? { encryptionKey: resolve(encryptionKey, context) } : {}),
10
13
  };
11
14
  return {
12
15
  logGroup: new LogGroup(scope, id, mergedProps),
@@ -1 +1 @@
1
- {"version":3,"file":"log-group-builder.js","sourceRoot":"","sources":["../../src/log-group-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,sBAAsB,CAAC;AAGpE,OAAO,EAAuB,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAiCnD,MAAM,eAAe;IACnB,KAAK,GAAkC,EAAE,CAAC;IAE1C,KAAK,CAAC,KAAiB,EAAE,EAAU;QACjC,MAAM,WAAW,GAAG;YAClB,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@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@composurecdk/logs",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "description": "Composable CloudWatch log group builder with secure defaults",
5
5
  "repository": {
6
6
  "type": "git",
@@ -56,7 +56,7 @@
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/node": "^25.9.3",
59
- "aws-cdk-lib": "^2.263.0",
59
+ "aws-cdk-lib": "^2.264.0",
60
60
  "constructs": "^10.6.0",
61
61
  "typescript": "^6.0.3",
62
62
  "vitest": "^4.1.8"