Skip to content

Commit

Permalink
fix(cdk): allow buckets to enable ACLs
Browse files Browse the repository at this point in the history
  • Loading branch information
shellscape committed Jan 8, 2025
1 parent 832fb45 commit 00f8d1a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
33 changes: 19 additions & 14 deletions packages/cdk/src/methods/kinesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ interface AddStreamResult {
}

interface AddFirehoseOptions {
destination?: IDestination;
destinationBucket?: Bucket | Omit<AddBucketOptions, 'name' | 'scope'>;
// conversion?: DataFormatConversion;
destinations?: IDestination[];
name: string;
scope: DotStack;
source: Stream | Omit<AddStreamOptions, 'name' | 'scope'>;
Expand All @@ -52,21 +51,20 @@ interface GrantRemoteStreamOptions {
}

export const addFirehose = (options: AddFirehoseOptions): AddFirehoseResult => {
const { /* conversion,*/ destinations, destinationBucket, name, scope, source } = options;
const { /* conversion,*/ destination, destinationBucket, name, scope, source } = options;

if (!destination && !destinationBucket)
throw new RangeError('Must provide either desitination or destinationBucket');

const baseName = DotStack.baseName(name, 'firehose');
const firehoseName = scope.resourceName(baseName);
const sourceStream =
source instanceof Stream
? source
: addStream({ name: `${name}-stream`, scope, ...source }).stream;
const deliveryProps: DeliveryStreamProps = {
deliveryStreamName: firehoseName,
destinations: [],
sourceStream
};
let bucket: Bucket | undefined;
let deliveryProps: DeliveryStreamProps;

if (destinations) deliveryProps.destinations.push(...destinations);
if (destinationBucket) {
bucket =
destinationBucket instanceof Bucket
Expand Down Expand Up @@ -113,11 +111,18 @@ export const addFirehose = (options: AddFirehoseOptions): AddFirehoseResult => {
})
);

const s3Destintation = new S3Bucket(bucket, { /* conversion,*/ role });
// (s3Destintation as any).errorOutputPrefix = errorOutputPrefix;
// (s3Destintation as any).prefix = prefix;
deliveryProps.destinations.push(s3Destintation);
(deliveryProps as any).role = role;
deliveryProps = {
deliveryStreamName: firehoseName,
destination: new S3Bucket(bucket, { /* conversion,*/ role }),
role,
source: sourceStream as any
};
} else {
deliveryProps = {
deliveryStreamName: firehoseName,
destination: destination!,
source: sourceStream as any
};
}

const deliveryStream = new DeliveryStream(scope, firehoseName, deliveryProps);
Expand Down
6 changes: 5 additions & 1 deletion packages/cdk/src/methods/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
EventType,
HttpMethods,
LifecycleRule,
NotificationKeyFilter
NotificationKeyFilter,
ObjectOwnership
} from 'aws-cdk-lib/aws-s3';
import { BucketDeployment, Source } from 'aws-cdk-lib/aws-s3-deployment';
import { IGrantable } from 'aws-cdk-lib/aws-iam';
Expand Down Expand Up @@ -52,6 +53,7 @@ export interface AddBucketDeploymentResult {
export interface AddBucketOptions {
autoDeleteObjects?: boolean;
cors?: boolean;
enableACLs?: boolean;
expireAfterDays?: number;
handlers?: BucketEventHandlerOptions[];
name: string;
Expand Down Expand Up @@ -93,6 +95,7 @@ export const addBucket = (options: AddBucketOptions): AddBucketResult => {
*/
autoDeleteObjects = true,
cors = false,
enableACLs = false,
expireAfterDays,
handlers,
name,
Expand Down Expand Up @@ -154,6 +157,7 @@ export const addBucket = (options: AddBucketOptions): AddBucketResult => {
bucketName,
cors: corsProps,
lifecycleRules,
objectOwnership: enableACLs ? ObjectOwnership.BUCKET_OWNER_PREFERRED : void 0,
publicReadAccess,
removalPolicy,
// Note: If this is ever used with a bucket that accepts overwriting existing objects,
Expand Down

0 comments on commit 00f8d1a

Please sign in to comment.