Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
feat: ✨ move config to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
ecxyzzy committed Sep 12, 2023
1 parent f0a1b13 commit 1041fce
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 107 deletions.
35 changes: 35 additions & 0 deletions apps/api/src/routes/v1/rest/websoc/+config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ApiPropsOverride } from "@bronya.js/api-construct";
import {
Effect,
ManagedPolicy,
PolicyDocument,
PolicyStatement,
Role,
ServicePrincipal,
} from "aws-cdk-lib/aws-iam";

export const overrides: ApiPropsOverride = {
constructs: {
functionProps: (scope, id) => ({
role: new Role(scope, `${id}-v1-rest-websoc-role`, {
assumedBy: new ServicePrincipal("lambda.amazonaws.com"),
managedPolicies: [
ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSLambdaBasicExecutionRole"),
],
inlinePolicies: {
lambdaInvokePolicy: new PolicyDocument({
statements: [
new PolicyStatement({
effect: Effect.ALLOW,
resources: [
`arn:aws:lambda:${process.env["AWS_REGION"]}:${process.env["ACCOUNT_ID"]}:function:peterportal-api-next-services-prod-websoc-proxy-function`,
],
actions: ["lambda:InvokeFunction"],
}),
],
}),
},
}),
}),
},
};
36 changes: 0 additions & 36 deletions apps/api/src/routes/v1/rest/websoc/+endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import { ApiPropsOverride } from "@bronya.js/api-construct";
import { PrismaClient } from "@libs/db";
import { createErrorResult, createOKResult } from "@libs/lambda";
import type { WebsocAPIResponse } from "@libs/uc-irvine-api/websoc";
import { combineAndNormalizeResponses, notNull, sortResponse } from "@libs/websoc-utils";
import {
Effect,
ManagedPolicy,
PolicyDocument,
PolicyStatement,
Role,
ServicePrincipal,
} from "aws-cdk-lib/aws-iam";
import type { APIGatewayProxyHandler } from "aws-lambda";
import { ZodError } from "zod";

Expand Down Expand Up @@ -143,30 +134,3 @@ export const GET: APIGatewayProxyHandler = async (event, context) => {
return createErrorResult(400, error, requestId);
}
};

// TODO: move this into a separate file.
export const overrides: ApiPropsOverride = {
constructs: {
functionProps: (scope, id) => ({
role: new Role(scope, `${id}-v1-rest-websoc-role`, {
assumedBy: new ServicePrincipal("lambda.amazonaws.com"),
managedPolicies: [
ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSLambdaBasicExecutionRole"),
],
inlinePolicies: {
lambdaInvokePolicy: new PolicyDocument({
statements: [
new PolicyStatement({
effect: Effect.ALLOW,
resources: [
`arn:aws:lambda:${process.env["AWS_REGION"]}:${process.env["ACCOUNT_ID"]}:function:peterportal-api-next-services-prod-websoc-proxy-function`,
],
actions: ["lambda:InvokeFunction"],
}),
],
}),
},
}),
}),
},
};
35 changes: 35 additions & 0 deletions apps/api/src/routes/v1/rest/websoc/{id}/+config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ApiPropsOverride } from "@bronya.js/api-construct";
import {
Effect,
ManagedPolicy,
PolicyDocument,
PolicyStatement,
Role,
ServicePrincipal,
} from "aws-cdk-lib/aws-iam";

export const overrides: ApiPropsOverride = {
constructs: {
functionProps: (scope, id) => ({
role: new Role(scope, `${id}-v1-rest-websoc-id-role`, {
assumedBy: new ServicePrincipal("lambda.amazonaws.com"),
managedPolicies: [
ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSLambdaBasicExecutionRole"),
],
inlinePolicies: {
lambdaInvokePolicy: new PolicyDocument({
statements: [
new PolicyStatement({
effect: Effect.ALLOW,
resources: [
`arn:aws:lambda:${process.env["AWS_REGION"]}:${process.env["ACCOUNT_ID"]}:function:peterportal-api-next-services-prod-websoc-proxy-function`,
],
actions: ["lambda:InvokeFunction"],
}),
],
}),
},
}),
}),
},
};
37 changes: 0 additions & 37 deletions apps/api/src/routes/v1/rest/websoc/{id}/+endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import { ApiPropsOverride } from "@bronya.js/api-construct";
import { PrismaClient } from "@libs/db";
import { createErrorResult, createOKResult } from "@libs/lambda";
import {
Effect,
ManagedPolicy,
PolicyDocument,
PolicyStatement,
Role,
ServicePrincipal,
} from "aws-cdk-lib/aws-iam";
import type { APIGatewayProxyHandler } from "aws-lambda";
import { ZodError } from "zod";

Expand Down Expand Up @@ -141,31 +132,3 @@ export const GET: APIGatewayProxyHandler = async (event, context) => {

return createErrorResult(400, "Invalid endpoint", requestId);
};

export const overrides: ApiPropsOverride = {
constructs: {
functionProps(scope, id) {
return {
role: new Role(scope, `${id}-v1-rest-websoc-id-role`, {
assumedBy: new ServicePrincipal("lambda.amazonaws.com"),
managedPolicies: [
ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSLambdaBasicExecutionRole"),
],
inlinePolicies: {
lambdaInvokePolicy: new PolicyDocument({
statements: [
new PolicyStatement({
effect: Effect.ALLOW,
resources: [
`arn:aws:lambda:${process.env["AWS_REGION"]}:${process.env["ACCOUNT_ID"]}:function:peterportal-api-next-services-prod-websoc-proxy-function`,
],
actions: ["lambda:InvokeFunction"],
}),
],
}),
},
}),
};
},
},
};
36 changes: 2 additions & 34 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1041fce

Please sign in to comment.