Skip to content

Commit 69442a8

Browse files
authored
feat(mixins-preview): vended log deliveries (#36138)
### Reason for this change Utility classes that will be needed for the VendedLogs Mixin. ### Description of changes Implements 4 classes, one for each destination resource Vended Logs can delivery data to. These classes are instantiated with the resource they are affiliated with and all have a bind method that takes care of setting up each deliveryDestination and the delivery connection between the source of the logs and the destination where logs are consumed. We are using a bind method to set up the delivery and the deliveryDestination instead of having these be set up in the constructor because of complications surrounding the lack of a resource in XRays. ### Describe any new or updated permissions being added **S3:** Adds the permissions defined here to an existing bucket policy or creates a bucket policy on the current bucket with these permissions: https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AWS-logs-infrastructure-S3.html Adds different permissions based on whether the service sending logs uses V1 or V2 permissions. **Firehose:** No new permissions. Adds tag to each Kinesis Firehose DeliveryStream that enables `LogDelivery`. **Cloudwatch:** Adds these permissions to existing Cloudwatch Logs policy or creates a new one with these permissions: https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AWS-logs-infrastructure-CWL.html Each Log Group that is involved with Vended Logs will need these permissions. **XRays:** Adds permissions specified here to existing XRay policy or creates a new one if one doesn't exist: https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AWS-logs-infrastructure-V2-XRayTraces.html ### Description of how you validated changes Extensive unit tests. Integ tests to follow. ### 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 3ef337d commit 69442a8

File tree

277 files changed

+1659
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

277 files changed

+1659
-8
lines changed

packages/@aws-cdk/mixins-preview/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ junit.xml
2222
!**/*.snapshot/**/asset.*/**
2323

2424
# we ignore generated files that cannot contain hand-written info
25-
lib/services/*/index.ts
2625
lib/services/**/*.jsiirc.json

packages/@aws-cdk/mixins-preview/lib/core/selectors.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ export abstract class ConstructSelector {
1919
return new CfnResourceSelector();
2020
}
2121

22+
/**
23+
* Selects only the provided construct.
24+
*/
25+
static onlyItself(): ConstructSelector {
26+
return new OnlyItselfSelector();
27+
}
28+
2229
/**
2330
* Selects constructs of a specific type.
2431
*/
@@ -107,3 +114,9 @@ class IdPatternSelector extends ConstructSelector {
107114
return result;
108115
}
109116
}
117+
118+
class OnlyItselfSelector extends ConstructSelector {
119+
select(scope: IConstruct): IConstruct[] {
120+
return [scope];
121+
}
122+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { IConstruct } from 'constructs/lib/construct';
2+
import { Mixin } from '../../core';
3+
import type { PolicyStatement } from 'aws-cdk-lib/aws-iam';
4+
import { PolicyDocument } from 'aws-cdk-lib/aws-iam';
5+
import type { CfnBucketPolicy } from 'aws-cdk-lib/aws-s3';
6+
import { makeIsCfnResource } from './utils';
7+
8+
/**
9+
* Adds statements to a bucket policy
10+
* @mixin true
11+
*/
12+
export class BucketPolicyStatementsMixins extends Mixin {
13+
private readonly statements: PolicyStatement[];
14+
15+
public constructor(statements: PolicyStatement[]) {
16+
super();
17+
this.statements = statements;
18+
}
19+
20+
public supports(construct: IConstruct): construct is CfnBucketPolicy {
21+
return makeIsCfnResource('AWS::S3::BucketPolicy')(construct);
22+
}
23+
24+
public applyTo(policy: IConstruct): IConstruct {
25+
if (!this.supports(policy)) {
26+
return policy;
27+
}
28+
29+
const policyDocument = this.getPolicyDocument(policy);
30+
policyDocument.addStatements(...this.statements);
31+
32+
policy.policyDocument = policyDocument;
33+
34+
return policy;
35+
}
36+
37+
/**
38+
* CfnBucketPolicy.policyDocument sometimes is a PolicyDocument object
39+
* and sometimes is a plain object. We need to handle both cases.
40+
*/
41+
private getPolicyDocument(policy: CfnBucketPolicy): PolicyDocument {
42+
if (policy.policyDocument instanceof PolicyDocument) {
43+
return policy.policyDocument;
44+
}
45+
return PolicyDocument.fromJson(policy.policyDocument);
46+
}
47+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { CfnResource } from 'aws-cdk-lib/core';
2+
import type { IConstruct } from 'constructs';
3+
4+
export function makeIsCfnResource(cfnResourceType: string): (construct: IConstruct) => boolean {
5+
return (construct: IConstruct) => CfnResource.isCfnResource(construct) && construct.cfnResourceType === cfnResourceType;
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as mixins from './mixins';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as mixins from './mixins';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as mixins from './mixins';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as mixins from './mixins';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as mixins from './mixins';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as mixins from './mixins';

0 commit comments

Comments
 (0)