Skip to content

Commit cc491df

Browse files
authored
fix(mixins-preview): cannot use string literal types for S3LogsDeliveryProps.permissionsVersion (#36197)
### Issue # (if applicable) ``` @aws-cdk.mixins-preview.aws_logs.S3LogsDelivery-example.ts:19:3 - error TS2322: Type '"permissionsVersion"' is not assignable to type '"V1" | "V2" | undefined'. 19 permissionsVersion: 'permissionsVersion', ~~~~~~~~~~~~~~~~~~ @aws-cdk.mixins-preview.aws_logs.S3LogsDeliveryProps-example.ts:16:3 - error TS2322: Type '"permissionsVersion"' is not assignable to type '"V1" | "V2" | undefined'. 16 permissionsVersion: 'permissionsVersion', ~~~~~~~~~~~~~~~~~~ /codebuild/output/src37859859/src/packages/@aws-cdk/mixins-preview/lib/services/aws-logs/logs-delivery.ts:54:12 54 readonly permissionsVersion?: 'V1' | 'V2'; ~~~~~~~~~~~~~~~~~~ The expected type comes from property 'permissionsVersion' which is declared here on type 'S3LogsDeliveryProps' [jsii-rosetta] [WARN] 2 diagnostics from assemblies with 'strict' mode on (and 368 more non-strict diagnostics) ``` ### Reason for this change String literal types are not allowed in our pipeline. ### Description of changes Replaced the string literal type with an enum. ### Describe any new or updated permissions being added n/a ### Description of how you validated changes Existing tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent f431021 commit cc491df

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

packages/@aws-cdk/mixins-preview/lib/services/aws-logs/logs-delivery.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ export interface ILogsDelivery {
4141
bind(scope: IConstruct, deliverySource: logs.IDeliverySourceRef, sourceResourceArn: string): ILogsDeliveryConfig;
4242
}
4343

44+
/**
45+
* S3 Vended Logs Permissions version.
46+
*/
47+
export enum S3LogsDeliveryPermissionsVersion {
48+
/**
49+
* V1
50+
*/
51+
V1 = 'V1',
52+
/**
53+
* V2
54+
*/
55+
V2 = 'V2',
56+
}
57+
4458
/**
4559
* Props for S3LogsDelivery
4660
*/
@@ -51,7 +65,7 @@ export interface S3LogsDeliveryProps {
5165
*
5266
* @default "V2
5367
*/
54-
readonly permissionsVersion?: 'V1' | 'V2';
68+
readonly permissionsVersion?: S3LogsDeliveryPermissionsVersion;
5569
}
5670

5771
/**

packages/@aws-cdk/mixins-preview/test/services/aws-logs/logs-delivery.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AccountRootPrincipal, Effect, PolicyDocument, PolicyStatement, Role, Se
55
import { DeliveryStream, S3Bucket } from 'aws-cdk-lib/aws-kinesisfirehose';
66
import { CfnDeliverySource, LogGroup, ResourcePolicy, RetentionDays } from 'aws-cdk-lib/aws-logs';
77
import { Secret } from 'aws-cdk-lib/aws-secretsmanager';
8-
import { FirehoseLogsDelivery, LogGroupLogsDelivery, S3LogsDelivery, XRayLogsDelivery } from '../../../lib/services/aws-logs';
8+
import { FirehoseLogsDelivery, LogGroupLogsDelivery, S3LogsDelivery, S3LogsDeliveryPermissionsVersion, XRayLogsDelivery } from '../../../lib/services/aws-logs';
99

1010
// at the time of creating this test file S3 does not support Vended Logs on Buckets but this test pretends they do to make writing tests easier
1111
describe('S3 Delivery', () => {
@@ -77,7 +77,7 @@ describe('S3 Delivery', () => {
7777
});
7878

7979
const s3Logs1 = new S3LogsDelivery(bucket, {
80-
permissionsVersion: 'V2',
80+
permissionsVersion: S3LogsDeliveryPermissionsVersion.V2,
8181
});
8282
s3Logs1.bind(source1, deliverySource1, source1.bucketArn);
8383

@@ -89,7 +89,7 @@ describe('S3 Delivery', () => {
8989
test('creates policy with V1 permissions if specified', () => {
9090
const bucket = new Bucket(stack, 'Destination');
9191
const s3Logs = new S3LogsDelivery(bucket, {
92-
permissionsVersion: 'V1',
92+
permissionsVersion: S3LogsDeliveryPermissionsVersion.V1,
9393
});
9494
s3Logs.bind(source, deliverySource, source.bucketArn);
9595

@@ -207,7 +207,7 @@ describe('S3 Delivery', () => {
207207
test('creates policy with V2 permissions if specified', () => {
208208
const bucket = new Bucket(stack, 'Destination');
209209
const s3Logs = new S3LogsDelivery(bucket, {
210-
permissionsVersion: 'V2',
210+
permissionsVersion: S3LogsDeliveryPermissionsVersion.V2,
211211
});
212212
s3Logs.bind(source, deliverySource, source.bucketArn);
213213

0 commit comments

Comments
 (0)