Skip to content

Commit

Permalink
feat(type-safe-api): add method prop
Browse files Browse the repository at this point in the history
  • Loading branch information
valebedu committed Nov 4, 2023
1 parent 3466b43 commit 7cea2c9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/type-safe-api/src/construct/integrations/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
IntegrationRenderProps,
} from "./integration";
import { generateCorsResponseParameters } from "../prepare-spec-event-handler/prepare-spec";
import { Method } from "../spec";
import { bucketInvocationUri } from "../spec/utils";

export interface S3IntegrationProps {
Expand All @@ -22,6 +23,12 @@ export interface S3IntegrationProps {
*/
readonly role?: IRole;

/**
* The HTTP method to use when invoking the S3 bucket
* @default - integration method is used
*/
readonly method?: Method;

/**
* The path override to use when invoking the S3 bucket
* @default - integration path is used
Expand All @@ -36,6 +43,7 @@ export interface S3IntegrationProps {
export class S3Integration extends Integration {
private readonly bucket: IBucket;
private readonly role: IRole;
private readonly method?: Method;
private readonly path?: string;

constructor(props: S3IntegrationProps) {
Expand All @@ -52,6 +60,7 @@ export class S3Integration extends Integration {
}

this.bucket.grantReadWrite(this.role, this.path ?? "*");
this.method = props.method;
this.path = props.path;
}

Expand All @@ -61,7 +70,7 @@ export class S3Integration extends Integration {
public render(props: IntegrationRenderProps): ApiGatewayIntegration {
return {
type: "AWS",
httpMethod: props.method.toUpperCase(),
httpMethod: (this.method ?? props.method).toUpperCase(),
uri: bucketInvocationUri(this.bucket, this.path ?? props.path),
credentials: this.role.roleArn,
responses: {
Expand Down

0 comments on commit 7cea2c9

Please sign in to comment.