@webiny/project-aws 6.6.0-alpha.12 → 6.6.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_templates/appTemplates/api/graphql/package.json +2 -2
- package/_templates/appTemplates/api/graphql/src/index.ts +2 -2
- package/_templates/appTemplates/api/graphql/src/web.ts +1 -1
- package/_templates/extensions/OpenSearch/api/graphql/src/index.ts +2 -2
- package/_templates/extensions/OpenSearch/api/graphql/src/web.ts +1 -1
- package/_templates/extensions/Postgres/api/graphql/src/index.ts +3 -6
- package/_templates/extensions/Postgres/api/graphql/src/web.ts +1 -1
- package/api.d.ts +6 -6
- package/api.js +3 -2
- package/api.js.map +1 -1
- package/decorators/GetPulumiServiceWithDownloadInfo.d.ts +1 -3
- package/decorators/GetPulumiServiceWithDownloadInfo.js +15 -11
- package/decorators/GetPulumiServiceWithDownloadInfo.js.map +1 -1
- package/extensions/AuroraPostgresCluster.d.ts +12 -0
- package/extensions/{Postgres.js → AuroraPostgresCluster.js} +7 -7
- package/extensions/AuroraPostgresCluster.js.map +1 -0
- package/extensions/Postgres/AddCorePostgres.d.ts +1 -1
- package/extensions/Postgres/AddCorePostgres.js +0 -2
- package/extensions/Postgres/AddCorePostgres.js.map +1 -1
- package/extensions/Postgres/CopyPgModulesAfterApiBuild.d.ts +4 -3
- package/extensions/Postgres/CopyPgModulesAfterApiBuild.js.map +1 -1
- package/extensions/Postgres/ReplaceApiLambdaFnHandlers.d.ts +3 -3
- package/extensions/Postgres/ReplaceApiLambdaFnHandlers.js.map +1 -1
- package/extensions/Postgres/ValidatePostgresBeforeCoreDeploy.d.ts +1 -1
- package/extensions/Postgres/ValidatePostgresBeforeCoreDeploy.js +3 -3
- package/extensions/Postgres/ValidatePostgresBeforeCoreDeploy.js.map +1 -1
- package/extensions/Postgres/copyPgRuntimeModules.d.ts +1 -1
- package/extensions/Postgres/copyPgRuntimeModules.js +2 -2
- package/extensions/Postgres/copyPgRuntimeModules.js.map +1 -1
- package/extensions/ProjectAws/EnsurePostgresSetupUnchanged.d.ts +2 -2
- package/extensions/ProjectAws/EnsurePostgresSetupUnchanged.js +1 -1
- package/extensions/ProjectAws/EnsurePostgresSetupUnchanged.js.map +1 -1
- package/extensions/ProjectAws/RefuseApiWatchWithPostgres.d.ts +3 -3
- package/extensions/ProjectAws/RefuseApiWatchWithPostgres.js +1 -1
- package/extensions/ProjectAws/RefuseApiWatchWithPostgres.js.map +1 -1
- package/extensions/definitions.js +2 -4
- package/extensions/definitions.js.map +1 -1
- package/extensions/index.d.ts +3 -3
- package/extensions/index.js +3 -4
- package/extensions/registerExtensionImplementations.js +3 -5
- package/extensions/registerExtensionImplementations.js.map +1 -1
- package/infra.d.ts +2 -8
- package/infra.js +6 -10
- package/infra.js.map +1 -1
- package/package.json +19 -18
- package/project.d.ts +1 -0
- package/pulumi/apps/admin/createAdminPulumiApp.js.map +1 -1
- package/pulumi/apps/api/ApiGraphql.js.map +1 -1
- package/pulumi/apps/api/ApiGraphqlWeb.js.map +1 -1
- package/pulumi/apps/api/ApiOutput.js.map +1 -1
- package/pulumi/apps/api/ApiSchemaSetup.d.ts +2 -2
- package/pulumi/apps/api/ApiSchemaSetup.js +1 -1
- package/pulumi/apps/api/ApiSchemaSetup.js.map +1 -1
- package/pulumi/apps/api/apiDynamoDb.js.map +1 -1
- package/pulumi/apps/api/backgroundTask/types.js.map +1 -1
- package/pulumi/apps/api/createApiPulumiApp.js.map +1 -1
- package/pulumi/apps/common/CoreOutput.js.map +1 -1
- package/pulumi/apps/core/CoreCognito.d.ts +14 -0
- package/pulumi/apps/core/CoreCognito.js +34 -1
- package/pulumi/apps/core/CoreCognito.js.map +1 -1
- package/pulumi/apps/core/CorePostgres.d.ts +4 -4
- package/pulumi/apps/core/CorePostgres.js +2 -1
- package/pulumi/apps/core/CorePostgres.js.map +1 -1
- package/pulumi/apps/core/cognitoIdentityProviders/configure.js +11 -0
- package/pulumi/apps/core/cognitoIdentityProviders/configure.js.map +1 -1
- package/pulumi/apps/core/coreDynamoDb.d.ts +2 -2
- package/pulumi/apps/core/coreDynamoDb.js.map +1 -1
- package/pulumi/apps/core/coreServiceManifests.d.ts +6 -4
- package/pulumi/apps/core/coreServiceManifests.js.map +1 -1
- package/pulumi/apps/core/coreVpcEndpoints.d.ts +2 -2
- package/pulumi/apps/core/coreVpcEndpoints.js.map +1 -1
- package/pulumi/apps/core/createCorePulumiApp.js.map +1 -1
- package/pulumi/apps/extensions/getPostgresConfigFromExtension.d.ts +4 -2
- package/pulumi/apps/extensions/getPostgresConfigFromExtension.js +4 -3
- package/pulumi/apps/extensions/getPostgresConfigFromExtension.js.map +1 -1
- package/pulumi/apps/extensions/projectUsesPostgres.d.ts +1 -1
- package/pulumi/apps/extensions/projectUsesPostgres.js.map +1 -1
- package/pulumi/apps/react/adminSettingsItem.d.ts +1 -1
- package/pulumi/apps/react/adminSettingsItem.js.map +1 -1
- package/pulumi/apps/react/createReactPulumiApp.js.map +1 -1
- package/pulumi/types.d.ts +2 -2
- package/pulumi/utils/lambdaEnvVariables.js +2 -2
- package/pulumi/utils/lambdaEnvVariables.js.map +1 -1
- package/pulumi/utils/withServiceManifest.d.ts +2 -2
- package/pulumi/utils/withServiceManifest.js.map +1 -1
- package/services/PulumiGetStackOutputService/mapStackOutput.js +1 -1
- package/services/PulumiGetStackOutputService/mapStackOutput.js.map +1 -1
- package/extensions/Postgres.d.ts +0 -11
- package/extensions/Postgres.js.map +0 -1
- package/extensions/RdsProxy/EnsurePostgresWithRdsProxy.d.ts +0 -14
- package/extensions/RdsProxy/EnsurePostgresWithRdsProxy.js +0 -23
- package/extensions/RdsProxy/EnsurePostgresWithRdsProxy.js.map +0 -1
- package/extensions/RdsProxy.d.ts +0 -9
- package/extensions/RdsProxy.js +0 -31
- package/extensions/RdsProxy.js.map +0 -1
- package/pulumi/apps/extensions/getRdsProxyConfigFromExtension.d.ts +0 -5
- package/pulumi/apps/extensions/getRdsProxyConfigFromExtension.js +0 -8
- package/pulumi/apps/extensions/getRdsProxyConfigFromExtension.js.map +0 -1
|
@@ -23,7 +23,7 @@ export interface PostgresLambdaEnv {
|
|
|
23
23
|
* certificates of the Lambda runtime. No password: the functions read it from the secret.
|
|
24
24
|
*
|
|
25
25
|
* Throws when the core stack has no Postgres database, which is the case until `deploy core` runs
|
|
26
|
-
* with `<Infra.
|
|
26
|
+
* with `<Infra.AuroraPostgres />`.
|
|
27
27
|
*/
|
|
28
28
|
export declare const getPostgresLambdaEnv: (pg: PostgresOutputs) => PostgresLambdaEnv;
|
|
29
29
|
/**
|
|
@@ -33,7 +33,7 @@ export declare const getPostgresLambdaEnv: (pg: PostgresOutputs) => PostgresLamb
|
|
|
33
33
|
export declare const getPostgresLambdaEnvFromCore: (core: pulumi.Output<PostgresOutputs>) => Record<keyof PostgresLambdaEnv, pulumi.Output<string>>;
|
|
34
34
|
/**
|
|
35
35
|
* Env only the API's web function gets, on top of the `graphql` Lambda's (and over it), with
|
|
36
|
-
* `<Infra.
|
|
36
|
+
* `<Infra.AuroraPostgres />`. Nothing without Postgres.
|
|
37
37
|
*
|
|
38
38
|
* - `WEBINY_PG_POOL_MAX`: its pool size. One web function environment serves several requests at
|
|
39
39
|
* once, so it needs more than the 1 connection the plain Lambda functions keep.
|
|
@@ -24,7 +24,7 @@ const getPostgresLambdaEnv = (pg)=>{
|
|
|
24
24
|
"pgUser",
|
|
25
25
|
"pgSecretArn"
|
|
26
26
|
].filter((name)=>!pg[name]);
|
|
27
|
-
if (missing.length) throw new Error(`The core app has no Postgres database (missing outputs: ${missing.join(", ")}). Deploy the core app with \`<Infra.
|
|
27
|
+
if (missing.length) throw new Error(`The core app has no Postgres database (missing outputs: ${missing.join(", ")}). Deploy the core app with \`<Infra.AuroraPostgres />\` first: \`yarn webiny deploy core\`.`);
|
|
28
28
|
return {
|
|
29
29
|
WEBINY_PG_HOST: pg.pgProxyHost || pg.pgWriterHost,
|
|
30
30
|
WEBINY_PG_WRITER_HOST: pg.pgWriterHost,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulumi/apps/api/ApiSchemaSetup.js","sources":["../../../../src/pulumi/apps/api/ApiSchemaSetup.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\nimport * as aws from \"@pulumi/aws\";\nimport type { PulumiApp, PulumiAppModule } from \"@webiny/pulumi\";\nimport { createAppModule } from \"@webiny/pulumi\";\nimport type { PostgresOutputs } from \"~/pulumi/apps/common/CoreOutput.js\";\nimport type { PostgresExtensionConfig } from \"~/pulumi/apps/extensions/getPostgresConfigFromExtension.js\";\nimport type { ServiceManifest } from \"~/pulumi/utils/addServiceManifestTableItem.js\";\nimport { WEB_FUNCTION_RDS_CA_CERTS } from \"~/extensions/Postgres/rdsCaBundle.js\";\nimport { ApiGraphql } from \"./ApiGraphql.js\";\n\n/* The event `@webiny/api-event-handler-aws-pg` answers with the schema setup. */\nexport const SQL_SCHEMA_SETUP_EVENT = \"WebinySqlSchemaSetup\";\n\nexport const ApiSchemaSetupLambdaName = \"schema-setup\";\n\n/* The CA bundle of the Lambda Node.js runtime, which has the Amazon RDS certificates. */\nconst LAMBDA_RDS_CA_CERTS = \"/var/runtime/ca-cert.pem\";\n\nconst POSTGRES_DEFAULT_PORT = 5432;\n\nexport interface PostgresLambdaEnv {\n WEBINY_PG_HOST: string;\n WEBINY_PG_WRITER_HOST: string;\n WEBINY_PG_PORT: string;\n WEBINY_PG_DATABASE: string;\n WEBINY_PG_USER: string;\n WEBINY_PG_SECRET_ARN: string;\n WEBINY_PG_SSL: string;\n NODE_EXTRA_CA_CERTS: string;\n}\n\nconst POSTGRES_LAMBDA_ENV_NAMES: Array<keyof PostgresLambdaEnv> = [\n \"WEBINY_PG_HOST\",\n \"WEBINY_PG_WRITER_HOST\",\n \"WEBINY_PG_PORT\",\n \"WEBINY_PG_DATABASE\",\n \"WEBINY_PG_USER\",\n \"WEBINY_PG_SECRET_ARN\",\n \"WEBINY_PG_SSL\",\n \"NODE_EXTRA_CA_CERTS\"\n];\n\n/**\n * The env vars an API function connects to Postgres with, from the core stack's Postgres outputs.\n * The API goes through the RDS Proxy when the core has one, else to the cluster's writer; the schema\n * setup always goes to the writer (`WEBINY_PG_WRITER_HOST`). Over TLS, verified against the RDS\n * certificates of the Lambda runtime. No password: the functions read it from the secret.\n *\n * Throws when the core stack has no Postgres database, which is the case until `deploy core` runs\n * with `<Infra.Postgres />`.\n */\nexport const getPostgresLambdaEnv = (pg: PostgresOutputs): PostgresLambdaEnv => {\n const missing = ([\"pgWriterHost\", \"pgDatabase\", \"pgUser\", \"pgSecretArn\"] as const).filter(\n name => !pg[name]\n );\n if (missing.length) {\n throw new Error(\n `The core app has no Postgres database (missing outputs: ${missing.join(\", \")}). ` +\n \"Deploy the core app with `<Infra.Postgres />` first: `yarn webiny deploy core`.\"\n );\n }\n\n return {\n WEBINY_PG_HOST: (pg.pgProxyHost || pg.pgWriterHost) as string,\n WEBINY_PG_WRITER_HOST: pg.pgWriterHost as string,\n WEBINY_PG_PORT: String(pg.pgPort || POSTGRES_DEFAULT_PORT),\n WEBINY_PG_DATABASE: pg.pgDatabase as string,\n WEBINY_PG_USER: pg.pgUser as string,\n WEBINY_PG_SECRET_ARN: pg.pgSecretArn as string,\n WEBINY_PG_SSL: \"true\",\n NODE_EXTRA_CA_CERTS: LAMBDA_RDS_CA_CERTS\n };\n};\n\n/**\n * {@link getPostgresLambdaEnv} for the core stack's output, one Pulumi output per env var, so it can\n * be spread into a function's env next to the other variables.\n */\nexport const getPostgresLambdaEnvFromCore = (\n core: pulumi.Output<PostgresOutputs>\n): Record<keyof PostgresLambdaEnv, pulumi.Output<string>> => {\n const env = core.apply(getPostgresLambdaEnv);\n return Object.fromEntries(\n POSTGRES_LAMBDA_ENV_NAMES.map(name => [name, env.apply(values => values[name])])\n ) as Record<keyof PostgresLambdaEnv, pulumi.Output<string>>;\n};\n\n/**\n * Env only the API's web function gets, on top of the `graphql` Lambda's (and over it), with\n * `<Infra.Postgres />`. Nothing without Postgres.\n *\n * - `WEBINY_PG_POOL_MAX`: its pool size. One web function environment serves several requests at\n * once, so it needs more than the 1 connection the plain Lambda functions keep.\n * - `NODE_EXTRA_CA_CERTS`: the RDS CA bundle shipped in its code. Its runtime has no\n * `/var/runtime/ca-cert.pem`, the bundle the plain Lambda functions verify the database with.\n */\nexport const getPostgresWebFunctionEnv = (\n postgres: Pick<PostgresExtensionConfig, \"poolSize\"> | undefined\n): Record<string, string> => {\n if (!postgres) {\n return {};\n }\n return {\n WEBINY_PG_POOL_MAX: String(postgres.poolSize),\n NODE_EXTRA_CA_CERTS: WEB_FUNCTION_RDS_CA_CERTS\n };\n};\n\n/* Lets the API functions read the database password, and nothing else, from the core's secret. */\nexport const createPostgresSecretPolicy = (secretArn: string): aws.iam.PolicyDocument => {\n return {\n Version: \"2012-10-17\",\n Statement: [\n {\n Sid: \"PermissionForPostgresSecret\",\n Effect: \"Allow\",\n Action: [\"secretsmanager:GetSecretValue\"],\n Resource: [secretArn]\n }\n ]\n };\n};\n\n/* The event the deploy invokes the schema-setup function with. */\nexport const createSchemaSetupEvent = (serviceManifests: ServiceManifest[]) => {\n return {\n [SQL_SCHEMA_SETUP_EVENT]: {\n serviceManifests: serviceManifests.map(({ name, manifest }) => ({ name, manifest }))\n }\n };\n};\n\n/**\n * The manifests the api deploy stores: the core's (from the core stack output; the core deploys\n * before this function exists), then the api app's own. On a repeated name the api's own wins.\n *\n * Throws when the core stack has no service manifests: a core deployed before the core put them\n * in its output. Its `core` manifest would never reach the database.\n */\nexport const getSchemaSetupServiceManifests = (\n coreManifests: ServiceManifest[] | undefined,\n apiManifests: ServiceManifest[]\n): ServiceManifest[] => {\n if (!coreManifests) {\n throw new Error(\n \"The core app's stack output has no service manifests, which the api deploy stores \" +\n \"in the database. Deploy the core app again: `yarn webiny deploy core`.\"\n );\n }\n\n const byName = new Map<string, ServiceManifest>();\n for (const manifest of [...coreManifests, ...apiManifests]) {\n byName.set(manifest.name, manifest);\n }\n return [...byName.values()];\n};\n\nexport interface ApiSchemaSetupParams {\n /* The core stack's Postgres outputs. */\n postgres: pulumi.Output<PostgresOutputs>;\n /* Stored in the database by the setup, for service discovery. */\n serviceManifests: pulumi.Input<ServiceManifest[]>;\n /* Changes on every deploy, so every deploy runs the setup. Replaced in tests. */\n trigger?: string;\n}\n\nexport type ApiSchemaSetup = PulumiAppModule<typeof ApiSchemaSetup>;\n\n/**\n * The API on Postgres, at deploy time:\n * - lets the API role read the database password from the core's secret;\n * - adds the `schema-setup` function: the GraphQL function's bundle, role, env and VPC, with time\n * for the setup and no route to it;\n * - invokes it on every deploy with the `WebinySqlSchemaSetup` event. A failed setup fails the\n * deploy, so the schema is in place before the after-deploy hooks (AutoInstall) run. With RDS\n * Proxy the setup also waits until the proxy accepts the API's connections, and fails the deploy\n * when it doesn't within 10 minutes.\n *\n * The GraphQL function gets the `WEBINY_PG_*` env from `createApiPulumiApp`, before this module\n * copies its config.\n */\nexport const ApiSchemaSetup = createAppModule({\n name: \"ApiSchemaSetup\",\n config(app: PulumiApp, params: ApiSchemaSetupParams) {\n const graphql = app.getModule(ApiGraphql);\n\n const secretPolicy = app.addResource(aws.iam.RolePolicy, {\n name: \"api-lambda-pg-secret\",\n config: {\n role: graphql.role.output.id,\n policy: params.postgres.apply(pg => {\n const { WEBINY_PG_SECRET_ARN } = getPostgresLambdaEnv(pg);\n return JSON.stringify(createPostgresSecretPolicy(WEBINY_PG_SECRET_ARN));\n })\n }\n });\n\n const baseConfig = graphql.functions.graphql.config.clone();\n\n const schemaSetup = app.addResource(aws.lambda.Function, {\n name: ApiSchemaSetupLambdaName,\n config: {\n ...baseConfig,\n description: \"Sets the Webiny API up on Postgres. Invoked by every deploy.\",\n // Lambda's maximum. Creating the tables of a new database takes longer than a request\n // may, and with RDS Proxy the setup then waits (up to 10 minutes) until the proxy\n // accepts the API's connections: a new proxy refuses them for a few minutes.\n timeout: 900,\n loggingConfig: {\n logFormat: \"JSON\"\n }\n }\n });\n\n const invocation = app.addResource(aws.lambda.Invocation, {\n name: ApiSchemaSetupLambdaName,\n config: {\n functionName: schemaSetup.output.name,\n input: pulumi\n .output(params.serviceManifests)\n .apply(manifests =>\n JSON.stringify(createSchemaSetupEvent(manifests as ServiceManifest[]))\n ),\n triggers: {\n deploy: params.trigger ?? new Date().toISOString()\n }\n },\n opts: {\n // The function reads the password from the secret as soon as it runs.\n dependsOn: [secretPolicy.output]\n }\n });\n\n return {\n secretPolicy,\n functions: {\n schemaSetup\n },\n invocation\n };\n }\n});\n"],"names":["SQL_SCHEMA_SETUP_EVENT","ApiSchemaSetupLambdaName","LAMBDA_RDS_CA_CERTS","POSTGRES_DEFAULT_PORT","POSTGRES_LAMBDA_ENV_NAMES","getPostgresLambdaEnv","pg","missing","name","Error","String","getPostgresLambdaEnvFromCore","core","env","Object","values","getPostgresWebFunctionEnv","postgres","WEB_FUNCTION_RDS_CA_CERTS","createPostgresSecretPolicy","secretArn","createSchemaSetupEvent","serviceManifests","manifest","getSchemaSetupServiceManifests","coreManifests","apiManifests","byName","Map","ApiSchemaSetup","createAppModule","app","params","graphql","ApiGraphql","secretPolicy","aws","WEBINY_PG_SECRET_ARN","JSON","baseConfig","schemaSetup","invocation","pulumi","manifests","Date"],"mappings":";;;;;AAWO,MAAMA,yBAAyB;AAE/B,MAAMC,2BAA2B;AAGxC,MAAMC,sBAAsB;AAE5B,MAAMC,wBAAwB;AAa9B,MAAMC,4BAA4D;IAC9D;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACH;AAWM,MAAMC,uBAAuB,CAACC;IACjC,MAAMC,UAAW;QAAC;QAAgB;QAAc;QAAU;KAAc,CAAW,MAAM,CACrFC,CAAAA,OAAQ,CAACF,EAAE,CAACE,KAAK;IAErB,IAAID,QAAQ,MAAM,EACd,MAAM,IAAIE,MACN,CAAC,wDAAwD,EAAEF,QAAQ,IAAI,CAAC,MAAM,sFAAG,CAAC;IAK1F,OAAO;QACH,gBAAiBD,GAAG,WAAW,IAAIA,GAAG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F,IAAI,SAAS,CAACG;QAE9B,MAAMC,eAAeJ,IAAI,WAAW,CAACK,uCAAAA,GAAAA,CAAAA,UAAkB,EAAE;YACrD,MAAM;YACN,QAAQ;gBACJ,MAAMH,QAAQ,IAAI,CAAC,MAAM,CAAC,EAAE;gBAC5B,QAAQD,OAAO,QAAQ,CAAC,KAAK,CAAC1B,CAAAA;oBAC1B,MAAM,EAAE+B,oBAAoB,EAAE,GAAGhC,qBAAqBC;oBACtD,OAAOgC,KAAK,SAAS,CAACnB,2BAA2BkB;gBACrD;YACJ;QACJ;QAEA,MAAME,aAAaN,QAAQ,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK;QAEzD,MAAMO,cAAcT,IAAI,WAAW,CAACK,uCAAAA,MAAAA,CAAAA,QAAmB,EAAE;YACrD,MAAMnC;YACN,QAAQ;gBACJ,GAAGsC,UAAU;gBACb,aAAa;gBAIb,SAAS;gBACT,eAAe;oBACX,WAAW;gBACf;YACJ;QACJ;QAEA,MAAME,aAAaV,IAAI,WAAW,CAACK,uCAAAA,MAAAA,CAAAA,UAAqB,EAAE;YACtD,MAAMnC;YACN,QAAQ;gBACJ,cAAcuC,YAAY,MAAM,CAAC,IAAI;gBACrC,OAAOE,0CAAAA,MACI,CAACV,OAAO,gBAAgB,EAC9B,KAAK,CAACW,CAAAA,YACHL,KAAK,SAAS,CAACjB,uBAAuBsB;gBAE9C,UAAU;oBACN,QAAQX,OAAO,OAAO,IAAI,IAAIY,OAAO,WAAW;gBACpD;YACJ;YACA,MAAM;gBAEF,WAAW;oBAACT,aAAa,MAAM;iBAAC;YACpC;QACJ;QAEA,OAAO;YACHA;YACA,WAAW;gBACPK;YACJ;YACAC;QACJ;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"pulumi/apps/api/ApiSchemaSetup.js","sources":["../../../../src/pulumi/apps/api/ApiSchemaSetup.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\nimport * as aws from \"@pulumi/aws\";\nimport type { PulumiApp, PulumiAppModule } from \"@webiny/pulumi\";\nimport { createAppModule } from \"@webiny/pulumi\";\nimport type { PostgresOutputs } from \"~/pulumi/apps/common/CoreOutput.js\";\nimport type { PostgresExtensionConfig } from \"~/pulumi/apps/extensions/getPostgresConfigFromExtension.js\";\nimport type { ServiceManifest } from \"~/pulumi/utils/addServiceManifestTableItem.js\";\nimport { WEB_FUNCTION_RDS_CA_CERTS } from \"~/extensions/Postgres/rdsCaBundle.js\";\nimport { ApiGraphql } from \"./ApiGraphql.js\";\n\n/* The event `@webiny/api-composition-aws-pg` answers with the schema setup. */\nexport const SQL_SCHEMA_SETUP_EVENT = \"WebinySqlSchemaSetup\";\n\nexport const ApiSchemaSetupLambdaName = \"schema-setup\";\n\n/* The CA bundle of the Lambda Node.js runtime, which has the Amazon RDS certificates. */\nconst LAMBDA_RDS_CA_CERTS = \"/var/runtime/ca-cert.pem\";\n\nconst POSTGRES_DEFAULT_PORT = 5432;\n\nexport interface PostgresLambdaEnv {\n WEBINY_PG_HOST: string;\n WEBINY_PG_WRITER_HOST: string;\n WEBINY_PG_PORT: string;\n WEBINY_PG_DATABASE: string;\n WEBINY_PG_USER: string;\n WEBINY_PG_SECRET_ARN: string;\n WEBINY_PG_SSL: string;\n NODE_EXTRA_CA_CERTS: string;\n}\n\nconst POSTGRES_LAMBDA_ENV_NAMES: Array<keyof PostgresLambdaEnv> = [\n \"WEBINY_PG_HOST\",\n \"WEBINY_PG_WRITER_HOST\",\n \"WEBINY_PG_PORT\",\n \"WEBINY_PG_DATABASE\",\n \"WEBINY_PG_USER\",\n \"WEBINY_PG_SECRET_ARN\",\n \"WEBINY_PG_SSL\",\n \"NODE_EXTRA_CA_CERTS\"\n];\n\n/**\n * The env vars an API function connects to Postgres with, from the core stack's Postgres outputs.\n * The API goes through the RDS Proxy when the core has one, else to the cluster's writer; the schema\n * setup always goes to the writer (`WEBINY_PG_WRITER_HOST`). Over TLS, verified against the RDS\n * certificates of the Lambda runtime. No password: the functions read it from the secret.\n *\n * Throws when the core stack has no Postgres database, which is the case until `deploy core` runs\n * with `<Infra.AuroraPostgres />`.\n */\nexport const getPostgresLambdaEnv = (pg: PostgresOutputs): PostgresLambdaEnv => {\n const missing = ([\"pgWriterHost\", \"pgDatabase\", \"pgUser\", \"pgSecretArn\"] as const).filter(\n name => !pg[name]\n );\n if (missing.length) {\n throw new Error(\n `The core app has no Postgres database (missing outputs: ${missing.join(\", \")}). ` +\n \"Deploy the core app with `<Infra.AuroraPostgres />` first: `yarn webiny deploy core`.\"\n );\n }\n\n return {\n WEBINY_PG_HOST: (pg.pgProxyHost || pg.pgWriterHost) as string,\n WEBINY_PG_WRITER_HOST: pg.pgWriterHost as string,\n WEBINY_PG_PORT: String(pg.pgPort || POSTGRES_DEFAULT_PORT),\n WEBINY_PG_DATABASE: pg.pgDatabase as string,\n WEBINY_PG_USER: pg.pgUser as string,\n WEBINY_PG_SECRET_ARN: pg.pgSecretArn as string,\n WEBINY_PG_SSL: \"true\",\n NODE_EXTRA_CA_CERTS: LAMBDA_RDS_CA_CERTS\n };\n};\n\n/**\n * {@link getPostgresLambdaEnv} for the core stack's output, one Pulumi output per env var, so it can\n * be spread into a function's env next to the other variables.\n */\nexport const getPostgresLambdaEnvFromCore = (\n core: pulumi.Output<PostgresOutputs>\n): Record<keyof PostgresLambdaEnv, pulumi.Output<string>> => {\n const env = core.apply(getPostgresLambdaEnv);\n return Object.fromEntries(\n POSTGRES_LAMBDA_ENV_NAMES.map(name => [name, env.apply(values => values[name])])\n ) as Record<keyof PostgresLambdaEnv, pulumi.Output<string>>;\n};\n\n/**\n * Env only the API's web function gets, on top of the `graphql` Lambda's (and over it), with\n * `<Infra.AuroraPostgres />`. Nothing without Postgres.\n *\n * - `WEBINY_PG_POOL_MAX`: its pool size. One web function environment serves several requests at\n * once, so it needs more than the 1 connection the plain Lambda functions keep.\n * - `NODE_EXTRA_CA_CERTS`: the RDS CA bundle shipped in its code. Its runtime has no\n * `/var/runtime/ca-cert.pem`, the bundle the plain Lambda functions verify the database with.\n */\nexport const getPostgresWebFunctionEnv = (\n postgres: Pick<PostgresExtensionConfig, \"poolSize\"> | undefined\n): Record<string, string> => {\n if (!postgres) {\n return {};\n }\n return {\n WEBINY_PG_POOL_MAX: String(postgres.poolSize),\n NODE_EXTRA_CA_CERTS: WEB_FUNCTION_RDS_CA_CERTS\n };\n};\n\n/* Lets the API functions read the database password, and nothing else, from the core's secret. */\nexport const createPostgresSecretPolicy = (secretArn: string): aws.iam.PolicyDocument => {\n return {\n Version: \"2012-10-17\",\n Statement: [\n {\n Sid: \"PermissionForPostgresSecret\",\n Effect: \"Allow\",\n Action: [\"secretsmanager:GetSecretValue\"],\n Resource: [secretArn]\n }\n ]\n };\n};\n\n/* The event the deploy invokes the schema-setup function with. */\nexport const createSchemaSetupEvent = (serviceManifests: ServiceManifest[]) => {\n return {\n [SQL_SCHEMA_SETUP_EVENT]: {\n serviceManifests: serviceManifests.map(({ name, manifest }) => ({ name, manifest }))\n }\n };\n};\n\n/**\n * The manifests the api deploy stores: the core's (from the core stack output; the core deploys\n * before this function exists), then the api app's own. On a repeated name the api's own wins.\n *\n * Throws when the core stack has no service manifests: a core deployed before the core put them\n * in its output. Its `core` manifest would never reach the database.\n */\nexport const getSchemaSetupServiceManifests = (\n coreManifests: ServiceManifest[] | undefined,\n apiManifests: ServiceManifest[]\n): ServiceManifest[] => {\n if (!coreManifests) {\n throw new Error(\n \"The core app's stack output has no service manifests, which the api deploy stores \" +\n \"in the database. Deploy the core app again: `yarn webiny deploy core`.\"\n );\n }\n\n const byName = new Map<string, ServiceManifest>();\n for (const manifest of [...coreManifests, ...apiManifests]) {\n byName.set(manifest.name, manifest);\n }\n return [...byName.values()];\n};\n\nexport interface ApiSchemaSetupParams {\n /* The core stack's Postgres outputs. */\n postgres: pulumi.Output<PostgresOutputs>;\n /* Stored in the database by the setup, for service discovery. */\n serviceManifests: pulumi.Input<ServiceManifest[]>;\n /* Changes on every deploy, so every deploy runs the setup. Replaced in tests. */\n trigger?: string;\n}\n\nexport type ApiSchemaSetup = PulumiAppModule<typeof ApiSchemaSetup>;\n\n/**\n * The API on Postgres, at deploy time:\n * - lets the API role read the database password from the core's secret;\n * - adds the `schema-setup` function: the GraphQL function's bundle, role, env and VPC, with time\n * for the setup and no route to it;\n * - invokes it on every deploy with the `WebinySqlSchemaSetup` event. A failed setup fails the\n * deploy, so the schema is in place before the after-deploy hooks (AutoInstall) run. With RDS\n * Proxy the setup also waits until the proxy accepts the API's connections, and fails the deploy\n * when it doesn't within 10 minutes.\n *\n * The GraphQL function gets the `WEBINY_PG_*` env from `createApiPulumiApp`, before this module\n * copies its config.\n */\nexport const ApiSchemaSetup = createAppModule({\n name: \"ApiSchemaSetup\",\n config(app: PulumiApp, params: ApiSchemaSetupParams) {\n const graphql = app.getModule(ApiGraphql);\n\n const secretPolicy = app.addResource(aws.iam.RolePolicy, {\n name: \"api-lambda-pg-secret\",\n config: {\n role: graphql.role.output.id,\n policy: params.postgres.apply(pg => {\n const { WEBINY_PG_SECRET_ARN } = getPostgresLambdaEnv(pg);\n return JSON.stringify(createPostgresSecretPolicy(WEBINY_PG_SECRET_ARN));\n })\n }\n });\n\n const baseConfig = graphql.functions.graphql.config.clone();\n\n const schemaSetup = app.addResource(aws.lambda.Function, {\n name: ApiSchemaSetupLambdaName,\n config: {\n ...baseConfig,\n description: \"Sets the Webiny API up on Postgres. Invoked by every deploy.\",\n // Lambda's maximum. Creating the tables of a new database takes longer than a request\n // may, and with RDS Proxy the setup then waits (up to 10 minutes) until the proxy\n // accepts the API's connections: a new proxy refuses them for a few minutes.\n timeout: 900,\n loggingConfig: {\n logFormat: \"JSON\"\n }\n }\n });\n\n const invocation = app.addResource(aws.lambda.Invocation, {\n name: ApiSchemaSetupLambdaName,\n config: {\n functionName: schemaSetup.output.name,\n input: pulumi\n .output(params.serviceManifests)\n .apply(manifests =>\n JSON.stringify(createSchemaSetupEvent(manifests as ServiceManifest[]))\n ),\n triggers: {\n deploy: params.trigger ?? new Date().toISOString()\n }\n },\n opts: {\n // The function reads the password from the secret as soon as it runs.\n dependsOn: [secretPolicy.output]\n }\n });\n\n return {\n secretPolicy,\n functions: {\n schemaSetup\n },\n invocation\n };\n }\n});\n"],"names":["SQL_SCHEMA_SETUP_EVENT","ApiSchemaSetupLambdaName","LAMBDA_RDS_CA_CERTS","POSTGRES_DEFAULT_PORT","POSTGRES_LAMBDA_ENV_NAMES","getPostgresLambdaEnv","pg","missing","name","Error","String","getPostgresLambdaEnvFromCore","core","env","Object","values","getPostgresWebFunctionEnv","postgres","WEB_FUNCTION_RDS_CA_CERTS","createPostgresSecretPolicy","secretArn","createSchemaSetupEvent","serviceManifests","manifest","getSchemaSetupServiceManifests","coreManifests","apiManifests","byName","Map","ApiSchemaSetup","createAppModule","app","params","graphql","ApiGraphql","secretPolicy","aws","WEBINY_PG_SECRET_ARN","JSON","baseConfig","schemaSetup","invocation","pulumi","manifests","Date"],"mappings":";;;;;AAWO,MAAMA,yBAAyB;AAE/B,MAAMC,2BAA2B;AAGxC,MAAMC,sBAAsB;AAE5B,MAAMC,wBAAwB;AAa9B,MAAMC,4BAA4D;IAC9D;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACH;AAWM,MAAMC,uBAAuB,CAACC;IACjC,MAAMC,UAAW;QAAC;QAAgB;QAAc;QAAU;KAAc,CAAW,MAAM,CACrFC,CAAAA,OAAQ,CAACF,EAAE,CAACE,KAAK;IAErB,IAAID,QAAQ,MAAM,EACd,MAAM,IAAIE,MACN,CAAC,wDAAwD,EAAEF,QAAQ,IAAI,CAAC,MAAM,4FAAG,CAAC;IAK1F,OAAO;QACH,gBAAiBD,GAAG,WAAW,IAAIA,GAAG,YAAY;QAClD,uBAAuBA,GAAG,YAAY;QACtC,gBAAgBI,OAAOJ,GAAG,MAAM,IAAIH;QACpC,oBAAoBG,GAAG,UAAU;QACjC,gBAAgBA,GAAG,MAAM;QACzB,sBAAsBA,GAAG,WAAW;QACpC,eAAe;QACf,q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B,QAAQD,OAAO,QAAQ,CAAC,KAAK,CAAC1B,CAAAA;oBAC1B,MAAM,EAAE+B,oBAAoB,EAAE,GAAGhC,qBAAqBC;oBACtD,OAAOgC,KAAK,SAAS,CAACnB,2BAA2BkB;gBACrD;YACJ;QACJ;QAEA,MAAME,aAAaN,QAAQ,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK;QAEzD,MAAMO,cAAcT,IAAI,WAAW,CAACK,uCAAAA,MAAAA,CAAAA,QAAmB,EAAE;YACrD,MAAMnC;YACN,QAAQ;gBACJ,GAAGsC,UAAU;gBACb,aAAa;gBAIb,SAAS;gBACT,eAAe;oBACX,WAAW;gBACf;YACJ;QACJ;QAEA,MAAME,aAAaV,IAAI,WAAW,CAACK,uCAAAA,MAAAA,CAAAA,UAAqB,EAAE;YACtD,MAAMnC;YACN,QAAQ;gBACJ,cAAcuC,YAAY,MAAM,CAAC,IAAI;gBACrC,OAAOE,0CAAAA,MACI,CAACV,OAAO,gBAAgB,EAC9B,KAAK,CAACW,CAAAA,YACHL,KAAK,SAAS,CAACjB,uBAAuBsB;gBAE9C,UAAU;oBACN,QAAQX,OAAO,OAAO,IAAI,IAAIY,OAAO,WAAW;gBACpD;YACJ;YACA,MAAM;gBAEF,WAAW;oBAACT,aAAa,MAAM;iBAAC;YACpC;QACJ;QAEA,OAAO;YACHA;YACA,WAAW;gBACPK;YACJ;YACAC;QACJ;IACJ;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulumi/apps/api/apiDynamoDb.js","sources":["../../../../src/pulumi/apps/api/apiDynamoDb.ts"],"sourcesContent":["import type * as pulumi from \"@pulumi/pulumi\";\nimport type { PulumiApp } from \"@webiny/pulumi\";\nimport type { CoreOutput } from \"~/pulumi/apps/common/CoreOutput.js\";\n\n/*\n * The api app's references to the core's DynamoDB tables. With `<Infra.
|
|
1
|
+
{"version":3,"file":"pulumi/apps/api/apiDynamoDb.js","sources":["../../../../src/pulumi/apps/api/apiDynamoDb.ts"],"sourcesContent":["import type * as pulumi from \"@pulumi/pulumi\";\nimport type { PulumiApp } from \"@webiny/pulumi\";\nimport type { CoreOutput } from \"~/pulumi/apps/common/CoreOutput.js\";\n\n/*\n * The api app's references to the core's DynamoDB tables. With `<Infra.AuroraPostgres />` the core\n * has neither the primary nor the audit logs table, so there is no env or output for them. The\n * OpenSearch table belongs to `CoreOpenSearch` and exists whenever OpenSearch is configured, with\n * or without Postgres, so its env stays. The GraphQL policy's DynamoDB statement follows the\n * core's output instead (see `ApiGraphql`).\n */\n\nexport type DynamoDbLambdaEnv = Partial<\n Record<\"DB_TABLE\" | \"DB_TABLE_AUDIT_LOGS\" | \"DB_TABLE_OPENSEARCH\", pulumi.Output<unknown>>\n>;\n\n/* The env that names the core's DynamoDB tables, for the GraphQL functions. */\nexport const getDynamoDbLambdaEnv = (\n core: CoreOutput,\n usesPostgres: boolean\n): DynamoDbLambdaEnv => {\n if (usesPostgres) {\n // Unset (undefined) without OpenSearch, as before.\n return { DB_TABLE_OPENSEARCH: core.opensearchDynamodbTableName };\n }\n return {\n DB_TABLE: core.primaryDynamodbTableName,\n DB_TABLE_AUDIT_LOGS: core.auditLogsDynamodbTableName,\n DB_TABLE_OPENSEARCH: core.opensearchDynamodbTableName\n };\n};\n\n/* The api stack outputs that name the core's DynamoDB tables. */\nexport const addDynamoDbOutputs = (app: PulumiApp, core: CoreOutput, usesPostgres: boolean) => {\n if (usesPostgres) {\n return;\n }\n app.addOutputs({\n dynamoDbTable: core.primaryDynamodbTableName,\n auditLogsDynamoDbTable: core.auditLogsDynamodbTableName\n });\n};\n"],"names":["getDynamoDbLambdaEnv","core","usesPostgres","addDynamoDbOutputs","app"],"mappings":"AAiBO,MAAMA,uBAAuB,CAChCC,MACAC;IAEA,IAAIA,cAEA,OAAO;QAAE,qBAAqBD,KAAK,2BAA2B;IAAC;IAEnE,OAAO;QACH,UAAUA,KAAK,wBAAwB;QACvC,qBAAqBA,KAAK,0BAA0B;QACpD,qBAAqBA,KAAK,2BAA2B;IACzD;AACJ;AAGO,MAAME,qBAAqB,CAACC,KAAgBH,MAAkBC;IACjE,IAAIA,cACA;IAEJE,IAAI,UAAU,CAAC;QACX,eAAeH,KAAK,wBAAwB;QAC5C,wBAAwBA,KAAK,0BAA0B;IAC3D;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulumi/apps/api/backgroundTask/types.js","sources":["../../../../../src/pulumi/apps/api/backgroundTask/types.ts"],"sourcesContent":["import type * as pulumi from \"@pulumi/pulumi\";\n\n/**\n * Update types if required. Try to avoid generic objects\n */\nexport enum StepFunctionDefinitionStatesType {\n Task = \"Task\",\n Pass = \"Pass\",\n Choice = \"Choice\",\n Wait = \"Wait\",\n Fail = \"Fail\",\n Succeed = \"Succeed\"\n}\n\nexport interface StepFunctionDefinitionStatesCatch {\n ErrorEquals: string[];\n Next: string;\n ResultPath?: string;\n}\n\nexport interface StepFunctionDefinitionStatesChoiceBase {\n Variable: string;\n Next: string;\n StringEquals?: string;\n StringMatches?: string;\n IsPresent?: boolean;\n IsNull?: boolean;\n}\n\nexport interface StepFunctionDefinitionStatesChoiceAndItem {\n Variable: string;\n StringEquals?: string;\n StringMatches?: string;\n IsPresent?: boolean;\n IsTimestamp?: boolean;\n IsNumeric?: boolean;\n NumericGreaterThan?: number;\n}\nexport interface StepFunctionDefinitionStatesChoiceAnd {\n And: StepFunctionDefinitionStatesChoiceAndItem[];\n Next: string;\n}\n\nexport type StepFunctionDefinitionStatesChoice =\n | StepFunctionDefinitionStatesChoiceBase\n | StepFunctionDefinitionStatesChoiceAnd;\n\nexport interface StepFunctionDefinitionStatesTypeBase {\n Type: StepFunctionDefinitionStatesType;\n Comment?: string;\n InputPath?: string;\n OutputPath?: string;\n}\n\nexport interface StepFunctionDefinitionStatesTypeTask extends StepFunctionDefinitionStatesTypeBase {\n Type: StepFunctionDefinitionStatesType.Task;\n Resource: pulumi.Input<string>;\n Next: string;\n ResultPath?: string;\n Parameters: Record<string, any>;\n Catch: StepFunctionDefinitionStatesCatch[];\n End?: boolean;\n}\n\nexport interface StepFunctionDefinitionStatesTypePass extends StepFunctionDefinitionStatesTypeBase {\n Type: StepFunctionDefinitionStatesType.Pass;\n Next: string;\n ResultPath?: string;\n Parameters: Record<string, any>;\n End?: boolean;\n}\n\nexport interface StepFunctionDefinitionStatesTypeChoice extends StepFunctionDefinitionStatesTypeBase {\n Type: StepFunctionDefinitionStatesType.Choice;\n Choices: StepFunctionDefinitionStatesChoice[];\n Default?: string;\n}\n\nexport interface StepFunctionDefinitionStatesTypeFail extends StepFunctionDefinitionStatesTypeBase {\n Type: StepFunctionDefinitionStatesType.Fail;\n Error?: string;\n Cause?: string;\n CausePath?: string;\n ErrorPath?: string;\n}\n\nexport interface StepFunctionDefinitionStatesTypeSucceed extends StepFunctionDefinitionStatesTypeBase {\n Type: StepFunctionDefinitionStatesType.Succeed;\n}\n\nexport interface StepFunctionDefinitionStatesTypeWait extends StepFunctionDefinitionStatesTypeBase {\n Next: string;\n Seconds?: number;\n Timestamp?: string;\n SecondsPath?: string;\n TimestampPath?: string;\n}\n\nexport type StepFunctionDefinitionStatesTypes =\n | StepFunctionDefinitionStatesTypeTask\n | StepFunctionDefinitionStatesTypePass\n | StepFunctionDefinitionStatesTypeChoice\n | StepFunctionDefinitionStatesTypeFail\n | StepFunctionDefinitionStatesTypeSucceed\n | StepFunctionDefinitionStatesTypeWait;\n\nexport interface StepFunctionDefinition {\n Comment: string;\n StartAt: string;\n States: {\n [key: string]: StepFunctionDefinitionStatesTypes;\n };\n}\n"],"names":["StepFunctionDefinitionStatesType"],"mappings":"AAKO,IAAKA,yCAAgCA,WAAAA,GAAAA,
|
|
1
|
+
{"version":3,"file":"pulumi/apps/api/backgroundTask/types.js","sources":["../../../../../src/pulumi/apps/api/backgroundTask/types.ts"],"sourcesContent":["import type * as pulumi from \"@pulumi/pulumi\";\n\n/**\n * Update types if required. Try to avoid generic objects\n */\nexport enum StepFunctionDefinitionStatesType {\n Task = \"Task\",\n Pass = \"Pass\",\n Choice = \"Choice\",\n Wait = \"Wait\",\n Fail = \"Fail\",\n Succeed = \"Succeed\"\n}\n\nexport interface StepFunctionDefinitionStatesCatch {\n ErrorEquals: string[];\n Next: string;\n ResultPath?: string;\n}\n\nexport interface StepFunctionDefinitionStatesChoiceBase {\n Variable: string;\n Next: string;\n StringEquals?: string;\n StringMatches?: string;\n IsPresent?: boolean;\n IsNull?: boolean;\n}\n\nexport interface StepFunctionDefinitionStatesChoiceAndItem {\n Variable: string;\n StringEquals?: string;\n StringMatches?: string;\n IsPresent?: boolean;\n IsTimestamp?: boolean;\n IsNumeric?: boolean;\n NumericGreaterThan?: number;\n}\nexport interface StepFunctionDefinitionStatesChoiceAnd {\n And: StepFunctionDefinitionStatesChoiceAndItem[];\n Next: string;\n}\n\nexport type StepFunctionDefinitionStatesChoice =\n | StepFunctionDefinitionStatesChoiceBase\n | StepFunctionDefinitionStatesChoiceAnd;\n\nexport interface StepFunctionDefinitionStatesTypeBase {\n Type: StepFunctionDefinitionStatesType;\n Comment?: string;\n InputPath?: string;\n OutputPath?: string;\n}\n\nexport interface StepFunctionDefinitionStatesTypeTask extends StepFunctionDefinitionStatesTypeBase {\n Type: StepFunctionDefinitionStatesType.Task;\n Resource: pulumi.Input<string>;\n Next: string;\n ResultPath?: string;\n Parameters: Record<string, any>;\n Catch: StepFunctionDefinitionStatesCatch[];\n End?: boolean;\n}\n\nexport interface StepFunctionDefinitionStatesTypePass extends StepFunctionDefinitionStatesTypeBase {\n Type: StepFunctionDefinitionStatesType.Pass;\n Next: string;\n ResultPath?: string;\n Parameters: Record<string, any>;\n End?: boolean;\n}\n\nexport interface StepFunctionDefinitionStatesTypeChoice extends StepFunctionDefinitionStatesTypeBase {\n Type: StepFunctionDefinitionStatesType.Choice;\n Choices: StepFunctionDefinitionStatesChoice[];\n Default?: string;\n}\n\nexport interface StepFunctionDefinitionStatesTypeFail extends StepFunctionDefinitionStatesTypeBase {\n Type: StepFunctionDefinitionStatesType.Fail;\n Error?: string;\n Cause?: string;\n CausePath?: string;\n ErrorPath?: string;\n}\n\nexport interface StepFunctionDefinitionStatesTypeSucceed extends StepFunctionDefinitionStatesTypeBase {\n Type: StepFunctionDefinitionStatesType.Succeed;\n}\n\nexport interface StepFunctionDefinitionStatesTypeWait extends StepFunctionDefinitionStatesTypeBase {\n Next: string;\n Seconds?: number;\n Timestamp?: string;\n SecondsPath?: string;\n TimestampPath?: string;\n}\n\nexport type StepFunctionDefinitionStatesTypes =\n | StepFunctionDefinitionStatesTypeTask\n | StepFunctionDefinitionStatesTypePass\n | StepFunctionDefinitionStatesTypeChoice\n | StepFunctionDefinitionStatesTypeFail\n | StepFunctionDefinitionStatesTypeSucceed\n | StepFunctionDefinitionStatesTypeWait;\n\nexport interface StepFunctionDefinition {\n Comment: string;\n StartAt: string;\n States: {\n [key: string]: StepFunctionDefinitionStatesTypes;\n };\n}\n"],"names":["StepFunctionDefinitionStatesType"],"mappings":"AAKO,IAAKA,yCAAgCA,WAAAA,GAAAA,SAAAA,gCAAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulumi/apps/api/createApiPulumiApp.js","sources":["../../../../src/pulumi/apps/api/createApiPulumiApp.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport pick from \"lodash/pick.js\";\nimport { createPulumiApp, isResourceOfType, type PulumiApp } from \"@webiny/pulumi\";\nimport {\n ApiBackgroundTask,\n ApiCloudfront,\n ApiFileManager,\n ApiGateway,\n ApiGraphql,\n ApiGraphqlStream,\n ApiWebsocket,\n CoreOutput,\n VpcConfig\n} from \"~/pulumi/apps/index.js\";\nimport { ApiGraphqlWeb } from \"~/pulumi/apps/index.js\";\nimport type { GraphqlWebVpc } from \"~/pulumi/apps/index.js\";\nimport {\n addDomainsUrlsOutputs,\n withCommonLambdaEnvVariables,\n withServiceManifest\n} from \"~/pulumi/utils/index.js\";\nimport { getEnvVariableAwsRegion } from \"~/pulumi/env/awsRegion.js\";\n// import { attachSyncSystem } from \"../syncSystem/api/index.js\";\nimport { applyAwsResourceTags, getAwsAccountId } from \"~/pulumi/apps/awsUtils.js\";\nimport {\n addServiceManifestTableItems,\n type WithServiceManifest\n} from \"~/pulumi/utils/withServiceManifest.js\";\nimport { ApiScheduler } from \"~/pulumi/apps/api/ApiScheduler.js\";\nimport { getAwsProjectSdk } from \"~/pulumi/getAwsProjectSdk.js\";\nimport { getVpcConfigFromExtension } from \"~/pulumi/apps/extensions/getVpcConfigFromExtension.js\";\nimport { isVpcEnabled } from \"~/pulumi/apps/extensions/isVpcEnabled.js\";\nimport { isWebFunctionEnabled } from \"~/pulumi/apps/extensions/isWebFunctionEnabled.js\";\nimport { getOsConfigFromExtension } from \"~/pulumi/apps/extensions/getOsConfigFromExtension.js\";\nimport { getPostgresConfigFromExtension } from \"~/pulumi/apps/extensions/getPostgresConfigFromExtension.js\";\nimport { projectUsesPostgres } from \"~/pulumi/apps/extensions/projectUsesPostgres.js\";\nimport {\n ApiSchemaSetup,\n getPostgresLambdaEnvFromCore,\n getPostgresWebFunctionEnv,\n getSchemaSetupServiceManifests\n} from \"./ApiSchemaSetup.js\";\nimport { createApiServiceManifests } from \"./apiServiceManifests.js\";\nimport { addDynamoDbOutputs, getDynamoDbLambdaEnv } from \"./apiDynamoDb.js\";\nimport { handleGuardDutyEvents } from \"./handleGuardDutyEvents.js\";\nimport {\n ApiPulumi,\n SetApiCustomDomains\n} from \"@webiny/project-extensions-aws/abstractions/features/pulumi/index.js\";\nimport { apiPulumi } from \"~/pulumi/features/ApiPulumi/index.js\";\nimport { DefaultSetApiCustomDomains } from \"~/pulumi/features/DefaultSetApiCustomDomains.js\";\nimport { ApiCustomDomains as apiCustomDomainsExt } from \"@webiny/project-extensions-aws/extensions/ApiCustomDomains.js\";\nimport { applyCustomDomain } from \"~/pulumi/apps/customDomain.js\";\n\nexport type ApiPulumiApp = ReturnType<typeof createApiPulumiApp>;\n\nexport const createApiPulumiApp = () => {\n const baseApp = createPulumiApp({\n name: \"api\",\n path: \"apps/api\",\n program: async (app: PulumiApp & WithServiceManifest) => {\n const sdk = await getAwsProjectSdk();\n const projectConfig = await sdk.getProjectConfig();\n\n const pulumiResourceNamePrefix = await sdk.getPulumiResourceNamePrefix();\n const vpcExtensionsConfig = getVpcConfigFromExtension(projectConfig);\n const openSearchExtensionConfig = getOsConfigFromExtension(projectConfig);\n const postgresConfig = getPostgresConfigFromExtension(projectConfig);\n const usesPostgres = Boolean(postgresConfig);\n\n let searchEngineParams: typeof openSearchExtensionConfig | null = null;\n\n if (openSearchExtensionConfig) {\n searchEngineParams = openSearchExtensionConfig;\n }\n\n if (searchEngineParams) {\n const params = searchEngineParams;\n if (typeof params === \"object\") {\n if (params.endpoint) {\n process.env.OPENSEARCH_ENDPOINT = params.endpoint;\n }\n\n if (params.domainName) {\n process.env.AWS_OS_DOMAIN_NAME = params.domainName;\n }\n\n if (params.indexPrefix) {\n process.env.OPENSEARCH_INDEX_PREFIX = params.indexPrefix;\n }\n\n if (params.sharedIndexes) {\n process.env.OPENSEARCH_SHARED_INDEXES = \"true\";\n }\n\n if (params.username) {\n process.env.OPENSEARCH_USERNAME = params.username;\n }\n\n if (params.password) {\n process.env.OPENSEARCH_PASSWORD = params.password;\n }\n }\n }\n\n if (pulumiResourceNamePrefix) {\n app.onResource(resource => {\n if (!resource.name.startsWith(pulumiResourceNamePrefix)) {\n resource.name = `${pulumiResourceNamePrefix}${resource.name}`;\n }\n });\n }\n\n // <-------------------- Enterprise start -------------------->\n app.addHandler(async () => {\n const featureFlags = await sdk.getFeatureFlags();\n\n const usingAdvancedVpcParams =\n vpcExtensionsConfig && typeof vpcExtensionsConfig !== \"boolean\";\n\n if (featureFlags.isEnabled(\"fileManager.threatDetection\")) {\n handleGuardDutyEvents(app as ApiPulumiApp);\n }\n\n // Not using advanced VPC params? Then immediately exit.\n if (usingAdvancedVpcParams) {\n const { onResource, addResource } = app;\n const { useExistingVpc } = vpcExtensionsConfig;\n\n // 1. We first deal with \"existing VPC\" setup.\n if (useExistingVpc) {\n if (!useExistingVpc.lambdaFunctionsVpcConfig) {\n throw new Error(\n \"Cannot specify `useExistingVpc` parameter because the `lambdaFunctionsVpcConfig` parameter wasn't provided.\"\n );\n }\n\n onResource(resource => {\n if (isResourceOfType(resource, aws.lambda.Function)) {\n const canUseVpc = resource.meta.canUseVpc !== false;\n if (canUseVpc) {\n resource.config.vpcConfig(\n useExistingVpc!.lambdaFunctionsVpcConfig\n );\n }\n }\n\n if (isResourceOfType(resource, aws.iam.Role)) {\n if (resource.meta.isLambdaFunctionRole) {\n addResource(aws.iam.RolePolicyAttachment, {\n name: `${resource.name}-vpc-access-execution-role`,\n config: {\n role: resource.output.name,\n policyArn:\n aws.iam.ManagedPolicy\n .AWSLambdaVPCAccessExecutionRole\n }\n });\n }\n }\n });\n }\n }\n });\n // <-------------------- Enterprise end -------------------->\n\n // Overrides must be applied via a handler, registered at the very start of the program.\n // By doing this, we're ensuring user's adjustments are not applied to late.\n sdk.getContainer().registerComposite(apiPulumi);\n\n // Make the `SetApiCustomDomains` service injectable into user-defined `ApiPulumi`\n // implementations. This allows applying custom domains using dynamically created\n // Pulumi resources (e.g. ACM certificates), from within a single implementation file.\n // We register an instance (bound to the current `app`) so that user implementations\n // only need to pass the custom domain params - not the `app` itself.\n sdk.getContainer().registerInstance(\n SetApiCustomDomains,\n new DefaultSetApiCustomDomains(app as ApiPulumiApp)\n );\n\n const pulumiHandlers = sdk.getContainer().resolve(ApiPulumi);\n\n app.addHandler(() => {\n return pulumiHandlers.execute(app as ApiPulumiApp);\n });\n\n const isProduction = app.env.isProduction;\n\n // Register core output as a module available to all the other modules\n const core = app.addModule(CoreOutput);\n\n // Register VPC config module to be available to other modules.\n const vpcEnabled = isVpcEnabled(vpcExtensionsConfig, isProduction);\n const vpcConfig = app.addModule(VpcConfig, {\n enabled: vpcEnabled\n });\n\n // Shared by the buffered `graphql` function and its response-streaming twin: both run the\n // same code bundle, so they must see the same environment.\n const dynamoDbEnv = getDynamoDbLambdaEnv(core, usesPostgres);\n const graphqlEnv = {\n COGNITO_REGION: getEnvVariableAwsRegion(),\n COGNITO_USER_POOL_ID: core.cognitoUserPoolId,\n // The core's DynamoDB tables: none with `<Infra.Postgres />`.\n ...dynamoDbEnv,\n OPENSEARCH_ENDPOINT: core.opensearchDomainEndpoint,\n\n // Not required. Useful for testing purposes / ephemeral environments.\n // https://www.webiny.com/docs/key-topics/ci-cd/testing/slow-ephemeral-environments\n OPENSEARCH_INDEX_PREFIX: process.env.OPENSEARCH_INDEX_PREFIX,\n OPENSEARCH_SHARED_INDEXES: process.env.OPENSEARCH_SHARED_INDEXES,\n OPENSEARCH_USERNAME: process.env.OPENSEARCH_USERNAME,\n OPENSEARCH_PASSWORD: process.env.OPENSEARCH_PASSWORD,\n\n S3_BUCKET: core.fileManagerBucketId,\n EVENT_BUS: core.eventBusArn,\n // TODO: move to okta plugin\n OKTA_ISSUER: process.env[\"OKTA_ISSUER\"],\n\n // With `<Infra.Postgres />`: the database the API runs on. The background-task,\n // fm-download and schema-setup functions copy this function's env.\n ...(usesPostgres ? getPostgresLambdaEnvFromCore(core) : {})\n };\n\n const graphql = app.addModule(ApiGraphql, { env: graphqlEnv });\n\n // Second Lambda function off the same bundle, fronted by a Function URL instead of API\n // Gateway, because API Gateway buffers the whole response and cannot stream. Added before\n // ApiCloudfront, which resolves this module to wire the `/stream/*` origin and behavior.\n const graphqlStream = app.addModule(ApiGraphqlStream, { env: graphqlEnv });\n\n // On unless the project sets `<Infra.Api.WebFunction enabled={false} />`. With it, the API's\n // HTTP routes go to the web function and there is no HTTP API Gateway; without it, the\n // previous setup. Added before ApiCloudfront, which routes to whichever exists.\n const webFunctionEnabled = isWebFunctionEnabled(projectConfig);\n let graphqlWeb: ApiGraphqlWeb | undefined;\n if (webFunctionEnabled) {\n let graphqlWebVpc: GraphqlWebVpc | null = null;\n const useExistingVpc =\n typeof vpcExtensionsConfig === \"object\" && vpcExtensionsConfig.useExistingVpc;\n if (useExistingVpc) {\n // Same subnets and security groups the enterprise handler above gives the\n // regular Lambdas.\n graphqlWebVpc = useExistingVpc.lambdaFunctionsVpcConfig;\n } else if (vpcEnabled) {\n const functionVpcConfig = vpcConfig.functionVpcConfig;\n // `pulumi.output` unwraps the nested inputs into a plain `string[]` output.\n const subnetIds = pulumi.output(functionVpcConfig.subnetIds);\n const securityGroupIds = pulumi.output(functionVpcConfig.securityGroupIds);\n graphqlWebVpc = { subnetIds, securityGroupIds };\n }\n\n graphqlWeb = app.addModule(ApiGraphqlWeb, {\n namePrefix: pulumiResourceNamePrefix ?? \"\",\n vpc: graphqlWebVpc,\n // With `<Infra.Postgres />`, a bigger pool than the plain Lambdas' 1.\n env: getPostgresWebFunctionEnv(postgresConfig)\n });\n app.addOutputs({\n graphqlWebFunctionName: graphqlWeb.fn.output.functionName,\n graphqlWebEndpointDomain: graphqlWeb.endpoint.output.domainName,\n // Read by `webiny watch` to publish its forwarder revision.\n graphqlWebEndpointName: graphqlWeb.endpoint.output.endpointName,\n graphqlWebCodeBucket: graphqlWeb.codeBucket.output.id\n });\n }\n\n const websocket = app.addModule(ApiWebsocket);\n\n const fileManager = app.addModule(ApiFileManager, {\n env: pick(dynamoDbEnv, [\"DB_TABLE\", \"DB_TABLE_AUDIT_LOGS\"]),\n functionUrl: webFunctionEnabled\n });\n\n let apiGateway: ApiGateway | undefined;\n if (!webFunctionEnabled) {\n apiGateway = createApiGateway(app, graphql, fileManager);\n }\n\n const cloudfront = app.addModule(ApiCloudfront);\n\n const backgroundTask = app.addModule(ApiBackgroundTask);\n const scheduler = app.addModule(ApiScheduler);\n\n // With `<Infra.Postgres />`, every deploy sets the database up and stores the service\n // manifests: the core's (from its stack output), then the api's own: `api` and\n // `scheduler` (see below) and any an extension adds with `addServiceManifest`.\n const schemaSetup = usesPostgres\n ? app.addModule(ApiSchemaSetup, {\n postgres: core,\n serviceManifests: pulumi\n .all([core.serviceManifests, app.getServiceManifests()])\n .apply(([coreManifests, apiManifests]) =>\n getSchemaSetupServiceManifests(coreManifests, apiManifests)\n )\n })\n : null;\n\n const [apiCustomDomains] = projectConfig.extensionsByType(apiCustomDomainsExt);\n if (apiCustomDomains) {\n const { domains, sslMethod, certificateArn, minimumProtocolVersion } =\n apiCustomDomains.params;\n applyCustomDomain(cloudfront, {\n domains,\n sslSupportMethod: sslMethod,\n acmCertificateArn: certificateArn,\n minimumProtocolVersion\n });\n }\n\n app.addOutputs({\n awsAccountId: getAwsAccountId(app),\n region: aws.config.region,\n cognitoUserPoolId: core.cognitoUserPoolId,\n cognitoAppClientId: core.cognitoAppClientId,\n cognitoUserPoolPasswordPolicy: core.cognitoUserPoolPasswordPolicy,\n graphqlLambdaName: graphql.functions.graphql.output.name,\n graphqlLambdaRole: graphql.role.output.arn,\n graphqlLambdaRoleName: graphql.role.output.name,\n graphqlStreamLambdaName: graphqlStream.functions.graphqlStream.output.name,\n graphqlStreamFunctionUrl: graphqlStream.functionUrl.output.functionUrl,\n backgroundTaskLambdaArn: backgroundTask.backgroundTask.output.arn,\n backgroundTaskStepFunctionArn: backgroundTask.stepFunction.output.arn,\n fileManagerDownloadLambdaArn: fileManager.functions.download.output.arn,\n websocketApiId: websocket.websocketApi.output.id,\n websocketApiUrl: websocket.websocketApiUrl,\n schedulerLambdaInvokeRole: scheduler.invokeRole.output.arn\n });\n\n // The core's DynamoDB tables: none with `<Infra.Postgres />`.\n addDynamoDbOutputs(app, core, usesPostgres);\n\n if (schemaSetup) {\n app.addOutputs({\n schemaSetupLambdaArn: schemaSetup.functions.schemaSetup.output.arn\n });\n }\n\n // Only add `dynamoDbOpensearchTable` output if using search engine (ES/OS).\n if (searchEngineParams) {\n app.addOutputs({\n dynamoDbOpensearchTable: core.opensearchDynamodbTableName\n });\n }\n\n app.addHandler(() => {\n addDomainsUrlsOutputs({\n app,\n cloudfrontDistribution: cloudfront,\n map: {\n distributionDomain: \"cloudfrontApiDomain\",\n distributionUrl: \"cloudfrontApiUrl\",\n usedDomain: \"apiDomain\",\n usedUrl: \"apiUrl\"\n }\n });\n });\n // /**\n // * We need to attach the Sync System if it exists.\n // */\n // await attachSyncSystem({\n // app,\n // core,\n // env: app.params.run.env\n // });\n\n // Applies internal and user-defined AWS tags.\n await applyAwsResourceTags(\"api\");\n\n return {\n fileManager,\n graphql,\n graphqlStream,\n graphqlWeb,\n apiGateway,\n websocket,\n cloudfront,\n backgroundTask,\n scheduler,\n schemaSetup\n };\n }\n });\n\n const app = withServiceManifest(withCommonLambdaEnvVariables(baseApp), async manifests => {\n // With Postgres, the schema-setup invocation stores them (see `ApiSchemaSetup` above).\n if (await projectUsesPostgres()) {\n return;\n }\n addServiceManifestTableItems(baseApp, manifests);\n });\n\n app.addHandler(() => {\n for (const manifest of createApiServiceManifests(baseApp.resources)) {\n app.addServiceManifest(manifest);\n }\n });\n\n return app;\n};\n\n/**\n * The HTTP API Gateway, used only with `<Infra.Api.WebFunction enabled={false} />`.\n */\nfunction createApiGateway(app: PulumiApp, graphql: ApiGraphql, fileManager: ApiFileManager) {\n return app.addModule(ApiGateway, {\n \"graphql-post\": {\n path: \"/graphql\",\n method: \"POST\",\n function: graphql.functions.graphql.output.arn\n },\n \"graphql-options\": {\n path: \"/graphql\",\n method: \"OPTIONS\",\n function: graphql.functions.graphql.output.arn\n },\n \"files-any\": {\n path: \"/files/{path+}\",\n method: \"ANY\",\n function: fileManager.functions.download.output.arn\n },\n \"private-any\": {\n path: \"/private/{path+}\",\n method: \"ANY\",\n function: fileManager.functions.download.output.arn\n },\n \"cms-post\": {\n path: \"/cms/{key+}\",\n method: \"POST\",\n function: graphql.functions.graphql.output.arn\n },\n \"cms-options\": {\n path: \"/cms/{key+}\",\n method: \"OPTIONS\",\n function: graphql.functions.graphql.output.arn\n },\n \"redirects-get\": {\n path: \"/wb/redirects\",\n method: \"GET\",\n function: graphql.functions.graphql.output.arn\n },\n \"redirects-options\": {\n path: \"/wb/redirects\",\n method: \"OPTIONS\",\n function: graphql.functions.graphql.output.arn\n },\n \"files-catch-all\": {\n path: \"/{path+}\",\n method: \"ANY\",\n function: fileManager.functions.download.output.arn\n }\n });\n}\n"],"names":["createApiPulumiApp","baseApp","createPulumiApp","app","sdk","getAwsProjectSdk","projectConfig","pulumiResourceNamePrefix","vpcExtensionsConfig","getVpcConfigFromExtension","openSearchExtensionConfig","getOsConfigFromExtension","postgresConfig","getPostgresConfigFromExtension","usesPostgres","Boolean","searchEngineParams","params","process","resource","featureFlags","usingAdvancedVpcParams","handleGuardDutyEvents","onResource","addResource","useExistingVpc","Error","isResourceOfType","aws","canUseVpc","apiPulumi","SetApiCustomDomains","DefaultSetApiCustomDomains","pulumiHandlers","ApiPulumi","isProduction","core","CoreOutput","vpcEnabled","isVpcEnabled","vpcConfig","VpcConfig","dynamoDbEnv","getDynamoDbLambdaEnv","graphqlEnv","getEnvVariableAwsRegion","getPostgresLambdaEnvFromCore","graphql","ApiGraphql","graphqlStream","ApiGraphqlStream","webFunctionEnabled","isWebFunctionEnabled","graphqlWeb","graphqlWebVpc","functionVpcConfig","subnetIds","pulumi","securityGroupIds","ApiGraphqlWeb","getPostgresWebFunctionEnv","websocket","ApiWebsocket","fileManager","ApiFileManager","pick","apiGateway","createApiGateway","cloudfront","ApiCloudfront","backgroundTask","ApiBackgroundTask","scheduler","ApiScheduler","schemaSetup","ApiSchemaSetup","coreManifests","apiManifests","getSchemaSetupServiceManifests","apiCustomDomains","apiCustomDomainsExt","domains","sslMethod","certificateArn","minimumProtocolVersion","applyCustomDomain","getAwsAccountId","addDynamoDbOutputs","addDomainsUrlsOutputs","applyAwsResourceTags","withServiceManifest","withCommonLambdaEnvVariables","manifests","projectUsesPostgres","addServiceManifestTableItems","manifest","createApiServiceManifests","ApiGateway"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyDO,MAAMA,qBAAqB;IAC9B,MAAMC,UAAUC,gBAAgB;QAC5B,MAAM;QACN,MAAM;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AG;QACvD;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"pulumi/apps/api/createApiPulumiApp.js","sources":["../../../../src/pulumi/apps/api/createApiPulumiApp.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport pick from \"lodash/pick.js\";\nimport { createPulumiApp, isResourceOfType, type PulumiApp } from \"@webiny/pulumi\";\nimport {\n ApiBackgroundTask,\n ApiCloudfront,\n ApiFileManager,\n ApiGateway,\n ApiGraphql,\n ApiGraphqlStream,\n ApiWebsocket,\n CoreOutput,\n VpcConfig\n} from \"~/pulumi/apps/index.js\";\nimport { ApiGraphqlWeb } from \"~/pulumi/apps/index.js\";\nimport type { GraphqlWebVpc } from \"~/pulumi/apps/index.js\";\nimport {\n addDomainsUrlsOutputs,\n withCommonLambdaEnvVariables,\n withServiceManifest\n} from \"~/pulumi/utils/index.js\";\nimport { getEnvVariableAwsRegion } from \"~/pulumi/env/awsRegion.js\";\n// import { attachSyncSystem } from \"../syncSystem/api/index.js\";\nimport { applyAwsResourceTags, getAwsAccountId } from \"~/pulumi/apps/awsUtils.js\";\nimport {\n addServiceManifestTableItems,\n type WithServiceManifest\n} from \"~/pulumi/utils/withServiceManifest.js\";\nimport { ApiScheduler } from \"~/pulumi/apps/api/ApiScheduler.js\";\nimport { getAwsProjectSdk } from \"~/pulumi/getAwsProjectSdk.js\";\nimport { getVpcConfigFromExtension } from \"~/pulumi/apps/extensions/getVpcConfigFromExtension.js\";\nimport { isVpcEnabled } from \"~/pulumi/apps/extensions/isVpcEnabled.js\";\nimport { isWebFunctionEnabled } from \"~/pulumi/apps/extensions/isWebFunctionEnabled.js\";\nimport { getOsConfigFromExtension } from \"~/pulumi/apps/extensions/getOsConfigFromExtension.js\";\nimport { getPostgresConfigFromExtension } from \"~/pulumi/apps/extensions/getPostgresConfigFromExtension.js\";\nimport { projectUsesPostgres } from \"~/pulumi/apps/extensions/projectUsesPostgres.js\";\nimport {\n ApiSchemaSetup,\n getPostgresLambdaEnvFromCore,\n getPostgresWebFunctionEnv,\n getSchemaSetupServiceManifests\n} from \"./ApiSchemaSetup.js\";\nimport { createApiServiceManifests } from \"./apiServiceManifests.js\";\nimport { addDynamoDbOutputs, getDynamoDbLambdaEnv } from \"./apiDynamoDb.js\";\nimport { handleGuardDutyEvents } from \"./handleGuardDutyEvents.js\";\nimport {\n ApiPulumi,\n SetApiCustomDomains\n} from \"@webiny/project-extensions-aws/abstractions/features/pulumi/index.js\";\nimport { apiPulumi } from \"~/pulumi/features/ApiPulumi/index.js\";\nimport { DefaultSetApiCustomDomains } from \"~/pulumi/features/DefaultSetApiCustomDomains.js\";\nimport { ApiCustomDomains as apiCustomDomainsExt } from \"@webiny/project-extensions-aws/extensions/ApiCustomDomains.js\";\nimport { applyCustomDomain } from \"~/pulumi/apps/customDomain.js\";\n\nexport type ApiPulumiApp = ReturnType<typeof createApiPulumiApp>;\n\nexport const createApiPulumiApp = () => {\n const baseApp = createPulumiApp({\n name: \"api\",\n path: \"apps/api\",\n program: async (app: PulumiApp & WithServiceManifest) => {\n const sdk = await getAwsProjectSdk();\n const projectConfig = await sdk.getProjectConfig();\n\n const pulumiResourceNamePrefix = await sdk.getPulumiResourceNamePrefix();\n const vpcExtensionsConfig = getVpcConfigFromExtension(projectConfig);\n const openSearchExtensionConfig = getOsConfigFromExtension(projectConfig);\n const postgresConfig = getPostgresConfigFromExtension(projectConfig);\n const usesPostgres = Boolean(postgresConfig);\n\n let searchEngineParams: typeof openSearchExtensionConfig | null = null;\n\n if (openSearchExtensionConfig) {\n searchEngineParams = openSearchExtensionConfig;\n }\n\n if (searchEngineParams) {\n const params = searchEngineParams;\n if (typeof params === \"object\") {\n if (params.endpoint) {\n process.env.OPENSEARCH_ENDPOINT = params.endpoint;\n }\n\n if (params.domainName) {\n process.env.AWS_OS_DOMAIN_NAME = params.domainName;\n }\n\n if (params.indexPrefix) {\n process.env.OPENSEARCH_INDEX_PREFIX = params.indexPrefix;\n }\n\n if (params.sharedIndexes) {\n process.env.OPENSEARCH_SHARED_INDEXES = \"true\";\n }\n\n if (params.username) {\n process.env.OPENSEARCH_USERNAME = params.username;\n }\n\n if (params.password) {\n process.env.OPENSEARCH_PASSWORD = params.password;\n }\n }\n }\n\n if (pulumiResourceNamePrefix) {\n app.onResource(resource => {\n if (!resource.name.startsWith(pulumiResourceNamePrefix)) {\n resource.name = `${pulumiResourceNamePrefix}${resource.name}`;\n }\n });\n }\n\n // <-------------------- Enterprise start -------------------->\n app.addHandler(async () => {\n const featureFlags = await sdk.getFeatureFlags();\n\n const usingAdvancedVpcParams =\n vpcExtensionsConfig && typeof vpcExtensionsConfig !== \"boolean\";\n\n if (featureFlags.isEnabled(\"fileManager.threatDetection\")) {\n handleGuardDutyEvents(app as ApiPulumiApp);\n }\n\n // Not using advanced VPC params? Then immediately exit.\n if (usingAdvancedVpcParams) {\n const { onResource, addResource } = app;\n const { useExistingVpc } = vpcExtensionsConfig;\n\n // 1. We first deal with \"existing VPC\" setup.\n if (useExistingVpc) {\n if (!useExistingVpc.lambdaFunctionsVpcConfig) {\n throw new Error(\n \"Cannot specify `useExistingVpc` parameter because the `lambdaFunctionsVpcConfig` parameter wasn't provided.\"\n );\n }\n\n onResource(resource => {\n if (isResourceOfType(resource, aws.lambda.Function)) {\n const canUseVpc = resource.meta.canUseVpc !== false;\n if (canUseVpc) {\n resource.config.vpcConfig(\n useExistingVpc!.lambdaFunctionsVpcConfig\n );\n }\n }\n\n if (isResourceOfType(resource, aws.iam.Role)) {\n if (resource.meta.isLambdaFunctionRole) {\n addResource(aws.iam.RolePolicyAttachment, {\n name: `${resource.name}-vpc-access-execution-role`,\n config: {\n role: resource.output.name,\n policyArn:\n aws.iam.ManagedPolicy\n .AWSLambdaVPCAccessExecutionRole\n }\n });\n }\n }\n });\n }\n }\n });\n // <-------------------- Enterprise end -------------------->\n\n // Overrides must be applied via a handler, registered at the very start of the program.\n // By doing this, we're ensuring user's adjustments are not applied to late.\n sdk.getContainer().registerComposite(apiPulumi);\n\n // Make the `SetApiCustomDomains` service injectable into user-defined `ApiPulumi`\n // implementations. This allows applying custom domains using dynamically created\n // Pulumi resources (e.g. ACM certificates), from within a single implementation file.\n // We register an instance (bound to the current `app`) so that user implementations\n // only need to pass the custom domain params - not the `app` itself.\n sdk.getContainer().registerInstance(\n SetApiCustomDomains,\n new DefaultSetApiCustomDomains(app as ApiPulumiApp)\n );\n\n const pulumiHandlers = sdk.getContainer().resolve(ApiPulumi);\n\n app.addHandler(() => {\n return pulumiHandlers.execute(app as ApiPulumiApp);\n });\n\n const isProduction = app.env.isProduction;\n\n // Register core output as a module available to all the other modules\n const core = app.addModule(CoreOutput);\n\n // Register VPC config module to be available to other modules.\n const vpcEnabled = isVpcEnabled(vpcExtensionsConfig, isProduction);\n const vpcConfig = app.addModule(VpcConfig, {\n enabled: vpcEnabled\n });\n\n // Shared by the buffered `graphql` function and its response-streaming twin: both run the\n // same code bundle, so they must see the same environment.\n const dynamoDbEnv = getDynamoDbLambdaEnv(core, usesPostgres);\n const graphqlEnv = {\n COGNITO_REGION: getEnvVariableAwsRegion(),\n COGNITO_USER_POOL_ID: core.cognitoUserPoolId,\n // The core's DynamoDB tables: none with `<Infra.AuroraPostgres />`.\n ...dynamoDbEnv,\n OPENSEARCH_ENDPOINT: core.opensearchDomainEndpoint,\n\n // Not required. Useful for testing purposes / ephemeral environments.\n // https://www.webiny.com/docs/key-topics/ci-cd/testing/slow-ephemeral-environments\n OPENSEARCH_INDEX_PREFIX: process.env.OPENSEARCH_INDEX_PREFIX,\n OPENSEARCH_SHARED_INDEXES: process.env.OPENSEARCH_SHARED_INDEXES,\n OPENSEARCH_USERNAME: process.env.OPENSEARCH_USERNAME,\n OPENSEARCH_PASSWORD: process.env.OPENSEARCH_PASSWORD,\n\n S3_BUCKET: core.fileManagerBucketId,\n EVENT_BUS: core.eventBusArn,\n // TODO: move to okta plugin\n OKTA_ISSUER: process.env[\"OKTA_ISSUER\"],\n\n // With `<Infra.AuroraPostgres />`: the database the API runs on. The\n // background-task, fm-download and schema-setup functions copy this function's env.\n ...(usesPostgres ? getPostgresLambdaEnvFromCore(core) : {})\n };\n\n const graphql = app.addModule(ApiGraphql, { env: graphqlEnv });\n\n // Second Lambda function off the same bundle, fronted by a Function URL instead of API\n // Gateway, because API Gateway buffers the whole response and cannot stream. Added before\n // ApiCloudfront, which resolves this module to wire the `/stream/*` origin and behavior.\n const graphqlStream = app.addModule(ApiGraphqlStream, { env: graphqlEnv });\n\n // On unless the project sets `<Infra.Api.WebFunction enabled={false} />`. With it, the API's\n // HTTP routes go to the web function and there is no HTTP API Gateway; without it, the\n // previous setup. Added before ApiCloudfront, which routes to whichever exists.\n const webFunctionEnabled = isWebFunctionEnabled(projectConfig);\n let graphqlWeb: ApiGraphqlWeb | undefined;\n if (webFunctionEnabled) {\n let graphqlWebVpc: GraphqlWebVpc | null = null;\n const useExistingVpc =\n typeof vpcExtensionsConfig === \"object\" && vpcExtensionsConfig.useExistingVpc;\n if (useExistingVpc) {\n // Same subnets and security groups the enterprise handler above gives the\n // regular Lambdas.\n graphqlWebVpc = useExistingVpc.lambdaFunctionsVpcConfig;\n } else if (vpcEnabled) {\n const functionVpcConfig = vpcConfig.functionVpcConfig;\n // `pulumi.output` unwraps the nested inputs into a plain `string[]` output.\n const subnetIds = pulumi.output(functionVpcConfig.subnetIds);\n const securityGroupIds = pulumi.output(functionVpcConfig.securityGroupIds);\n graphqlWebVpc = { subnetIds, securityGroupIds };\n }\n\n graphqlWeb = app.addModule(ApiGraphqlWeb, {\n namePrefix: pulumiResourceNamePrefix ?? \"\",\n vpc: graphqlWebVpc,\n // With `<Infra.AuroraPostgres />`, a bigger pool than the plain Lambdas' 1.\n env: getPostgresWebFunctionEnv(postgresConfig)\n });\n app.addOutputs({\n graphqlWebFunctionName: graphqlWeb.fn.output.functionName,\n graphqlWebEndpointDomain: graphqlWeb.endpoint.output.domainName,\n // Read by `webiny watch` to publish its forwarder revision.\n graphqlWebEndpointName: graphqlWeb.endpoint.output.endpointName,\n graphqlWebCodeBucket: graphqlWeb.codeBucket.output.id\n });\n }\n\n const websocket = app.addModule(ApiWebsocket);\n\n const fileManager = app.addModule(ApiFileManager, {\n env: pick(dynamoDbEnv, [\"DB_TABLE\", \"DB_TABLE_AUDIT_LOGS\"]),\n functionUrl: webFunctionEnabled\n });\n\n let apiGateway: ApiGateway | undefined;\n if (!webFunctionEnabled) {\n apiGateway = createApiGateway(app, graphql, fileManager);\n }\n\n const cloudfront = app.addModule(ApiCloudfront);\n\n const backgroundTask = app.addModule(ApiBackgroundTask);\n const scheduler = app.addModule(ApiScheduler);\n\n // With `<Infra.AuroraPostgres />`, every deploy sets the database up and stores the\n // service manifests: the core's (from its stack output), then the api's own: `api` and\n // `scheduler` (see below) and any an extension adds with `addServiceManifest`.\n const schemaSetup = usesPostgres\n ? app.addModule(ApiSchemaSetup, {\n postgres: core,\n serviceManifests: pulumi\n .all([core.serviceManifests, app.getServiceManifests()])\n .apply(([coreManifests, apiManifests]) =>\n getSchemaSetupServiceManifests(coreManifests, apiManifests)\n )\n })\n : null;\n\n const [apiCustomDomains] = projectConfig.extensionsByType(apiCustomDomainsExt);\n if (apiCustomDomains) {\n const { domains, sslMethod, certificateArn, minimumProtocolVersion } =\n apiCustomDomains.params;\n applyCustomDomain(cloudfront, {\n domains,\n sslSupportMethod: sslMethod,\n acmCertificateArn: certificateArn,\n minimumProtocolVersion\n });\n }\n\n app.addOutputs({\n awsAccountId: getAwsAccountId(app),\n region: aws.config.region,\n cognitoUserPoolId: core.cognitoUserPoolId,\n cognitoAppClientId: core.cognitoAppClientId,\n cognitoUserPoolPasswordPolicy: core.cognitoUserPoolPasswordPolicy,\n graphqlLambdaName: graphql.functions.graphql.output.name,\n graphqlLambdaRole: graphql.role.output.arn,\n graphqlLambdaRoleName: graphql.role.output.name,\n graphqlStreamLambdaName: graphqlStream.functions.graphqlStream.output.name,\n graphqlStreamFunctionUrl: graphqlStream.functionUrl.output.functionUrl,\n backgroundTaskLambdaArn: backgroundTask.backgroundTask.output.arn,\n backgroundTaskStepFunctionArn: backgroundTask.stepFunction.output.arn,\n fileManagerDownloadLambdaArn: fileManager.functions.download.output.arn,\n websocketApiId: websocket.websocketApi.output.id,\n websocketApiUrl: websocket.websocketApiUrl,\n schedulerLambdaInvokeRole: scheduler.invokeRole.output.arn\n });\n\n // The core's DynamoDB tables: none with `<Infra.AuroraPostgres />`.\n addDynamoDbOutputs(app, core, usesPostgres);\n\n if (schemaSetup) {\n app.addOutputs({\n schemaSetupLambdaArn: schemaSetup.functions.schemaSetup.output.arn\n });\n }\n\n // Only add `dynamoDbOpensearchTable` output if using search engine (ES/OS).\n if (searchEngineParams) {\n app.addOutputs({\n dynamoDbOpensearchTable: core.opensearchDynamodbTableName\n });\n }\n\n app.addHandler(() => {\n addDomainsUrlsOutputs({\n app,\n cloudfrontDistribution: cloudfront,\n map: {\n distributionDomain: \"cloudfrontApiDomain\",\n distributionUrl: \"cloudfrontApiUrl\",\n usedDomain: \"apiDomain\",\n usedUrl: \"apiUrl\"\n }\n });\n });\n // /**\n // * We need to attach the Sync System if it exists.\n // */\n // await attachSyncSystem({\n // app,\n // core,\n // env: app.params.run.env\n // });\n\n // Applies internal and user-defined AWS tags.\n await applyAwsResourceTags(\"api\");\n\n return {\n fileManager,\n graphql,\n graphqlStream,\n graphqlWeb,\n apiGateway,\n websocket,\n cloudfront,\n backgroundTask,\n scheduler,\n schemaSetup\n };\n }\n });\n\n const app = withServiceManifest(withCommonLambdaEnvVariables(baseApp), async manifests => {\n // With Postgres, the schema-setup invocation stores them (see `ApiSchemaSetup` above).\n if (await projectUsesPostgres()) {\n return;\n }\n addServiceManifestTableItems(baseApp, manifests);\n });\n\n app.addHandler(() => {\n for (const manifest of createApiServiceManifests(baseApp.resources)) {\n app.addServiceManifest(manifest);\n }\n });\n\n return app;\n};\n\n/**\n * The HTTP API Gateway, used only with `<Infra.Api.WebFunction enabled={false} />`.\n */\nfunction createApiGateway(app: PulumiApp, graphql: ApiGraphql, fileManager: ApiFileManager) {\n return app.addModule(ApiGateway, {\n \"graphql-post\": {\n path: \"/graphql\",\n method: \"POST\",\n function: graphql.functions.graphql.output.arn\n },\n \"graphql-options\": {\n path: \"/graphql\",\n method: \"OPTIONS\",\n function: graphql.functions.graphql.output.arn\n },\n \"files-any\": {\n path: \"/files/{path+}\",\n method: \"ANY\",\n function: fileManager.functions.download.output.arn\n },\n \"private-any\": {\n path: \"/private/{path+}\",\n method: \"ANY\",\n function: fileManager.functions.download.output.arn\n },\n \"cms-post\": {\n path: \"/cms/{key+}\",\n method: \"POST\",\n function: graphql.functions.graphql.output.arn\n },\n \"cms-options\": {\n path: \"/cms/{key+}\",\n method: \"OPTIONS\",\n function: graphql.functions.graphql.output.arn\n },\n \"redirects-get\": {\n path: \"/wb/redirects\",\n method: \"GET\",\n function: graphql.functions.graphql.output.arn\n },\n \"redirects-options\": {\n path: \"/wb/redirects\",\n method: \"OPTIONS\",\n function: graphql.functions.graphql.output.arn\n },\n \"files-catch-all\": {\n path: \"/{path+}\",\n method: \"ANY\",\n function: fileManager.functions.download.output.arn\n }\n });\n}\n"],"names":["createApiPulumiApp","baseApp","createPulumiApp","app","sdk","getAwsProjectSdk","projectConfig","pulumiResourceNamePrefix","vpcExtensionsConfig","getVpcConfigFromExtension","openSearchExtensionConfig","getOsConfigFromExtension","postgresConfig","getPostgresConfigFromExtension","usesPostgres","Boolean","searchEngineParams","params","process","resource","featureFlags","usingAdvancedVpcParams","handleGuardDutyEvents","onResource","addResource","useExistingVpc","Error","isResourceOfType","aws","canUseVpc","apiPulumi","SetApiCustomDomains","DefaultSetApiCustomDomains","pulumiHandlers","ApiPulumi","isProduction","core","CoreOutput","vpcEnabled","isVpcEnabled","vpcConfig","VpcConfig","dynamoDbEnv","getDynamoDbLambdaEnv","graphqlEnv","getEnvVariableAwsRegion","getPostgresLambdaEnvFromCore","graphql","ApiGraphql","graphqlStream","ApiGraphqlStream","webFunctionEnabled","isWebFunctionEnabled","graphqlWeb","graphqlWebVpc","functionVpcConfig","subnetIds","pulumi","securityGroupIds","ApiGraphqlWeb","getPostgresWebFunctionEnv","websocket","ApiWebsocket","fileManager","ApiFileManager","pick","apiGateway","createApiGateway","cloudfront","ApiCloudfront","backgroundTask","ApiBackgroundTask","scheduler","ApiScheduler","schemaSetup","ApiSchemaSetup","coreManifests","apiManifests","getSchemaSetupServiceManifests","apiCustomDomains","apiCustomDomainsExt","domains","sslMethod","certificateArn","minimumProtocolVersion","applyCustomDomain","getAwsAccountId","addDynamoDbOutputs","addDomainsUrlsOutputs","applyAwsResourceTags","withServiceManifest","withCommonLambdaEnvVariables","manifests","projectUsesPostgres","addServiceManifestTableItems","manifest","createApiServiceManifests","ApiGateway"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyDO,MAAMA,qBAAqB;IAC9B,MAAMC,UAAUC,gBAAgB;QAC5B,MAAM;QACN,MAAM;QACN,SAAS,OAAOC;YACZ,MAAMC,MAAM,MAAMC;YAClB,MAAMC,gBAAgB,MAAMF,IAAI,gBAAgB;YAEhD,MAAMG,2BAA2B,MAAMH,IAAI,2BAA2B;YACtE,MAAMI,sBAAsBC,0BAA0BH;YACtD,MAAMI,4BAA4BC,yBAAyBL;YAC3D,MAAMM,iBAAiBC,+BAA+BP;YACtD,MAAMQ,eAAeC,QAAQH;YAE7B,IAAII,qBAA8D;YAElE,IAAIN,2BACAM,qBAAqBN;YAGzB,IAAIM,oBAAoB;gBACpB,MAAMC,SAASD;gBACf,IAAI,AAAkB,YAAlB,OAAOC,QAAqB;oBAC5B,IAAIA,OAAO,QAAQ,EACfC,QAAQ,GAAG,CAAC,mBAAmB,GAAGD,OAAO,QAAQ;oBAGrD,IAAIA,OAAO,UAAU,EACjBC,QAAQ,GAAG,CAAC,kBAAkB,GAAGD,OAAO,UAAU;oBAGtD,IAAIA,OAAO,WAAW,EAClBC,QAAQ,GAAG,CAAC,uBAAuB,GAAGD,OAAO,WAAW;oBAG5D,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QAAQ;YACR,UAAUA,YAAY,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG;QACvD;QACA,YAAY;YACR,MAAM;YACN,QAAQ;YACR,UAAUhB,QAAQ,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG;QAClD;QACA,eAAe;YACX,MAAM;YACN,QAAQ;YACR,UAAUA,QAAQ,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG;QAClD;QACA,iBAAiB;YACb,MAAM;YACN,QAAQ;YACR,UAAUA,QAAQ,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG;QAClD;QACA,qBAAqB;YACjB,MAAM;YACN,QAAQ;YACR,UAAUA,QAAQ,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG;QAClD;QACA,mBAAmB;YACf,MAAM;YACN,QAAQ;YACR,UAAUgB,YAAY,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG;QACvD;IACJ;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulumi/apps/common/CoreOutput.js","sources":["../../../../src/pulumi/apps/common/CoreOutput.ts"],"sourcesContent":["import { createAppModule, type PulumiAppModule } from \"@webiny/pulumi\";\nimport { getAwsProjectSdk } from \"~/pulumi/getAwsProjectSdk.js\";\nimport type { ApiStackOutputService } from \"@webiny/project-extensions-aws/abstractions/services/ApiStackOutputService.js\";\nimport type { ServiceManifest } from \"~/pulumi/utils/addServiceManifestTableItem.js\";\n\nexport type CoreOutput = PulumiAppModule<typeof CoreOutput>;\n\nexport interface ICoreOutput {\n deploymentId: string;\n region: string;\n dynamoDbTable: string;\n iotAuthorizerName: string;\n cognitoUserPoolArn: string;\n cognitoAppClientId: string;\n cognitoUserPoolId: string;\n cognitoUserPoolPasswordPolicy: ApiStackOutputService.PasswordPolicy;\n fileManagerBucketId: string;\n fileManagerBucketArn: string;\n /*\n * The core's DynamoDB tables. Absent with `<Infra.
|
|
1
|
+
{"version":3,"file":"pulumi/apps/common/CoreOutput.js","sources":["../../../../src/pulumi/apps/common/CoreOutput.ts"],"sourcesContent":["import { createAppModule, type PulumiAppModule } from \"@webiny/pulumi\";\nimport { getAwsProjectSdk } from \"~/pulumi/getAwsProjectSdk.js\";\nimport type { ApiStackOutputService } from \"@webiny/project-extensions-aws/abstractions/services/ApiStackOutputService.js\";\nimport type { ServiceManifest } from \"~/pulumi/utils/addServiceManifestTableItem.js\";\n\nexport type CoreOutput = PulumiAppModule<typeof CoreOutput>;\n\nexport interface ICoreOutput {\n deploymentId: string;\n region: string;\n dynamoDbTable: string;\n iotAuthorizerName: string;\n cognitoUserPoolArn: string;\n cognitoAppClientId: string;\n cognitoUserPoolId: string;\n cognitoUserPoolPasswordPolicy: ApiStackOutputService.PasswordPolicy;\n fileManagerBucketId: string;\n fileManagerBucketArn: string;\n /*\n * The core's DynamoDB tables. Absent with `<Infra.AuroraPostgres />`: the core creates none.\n * The types stay non-optional so existing `CorePulumi` / `ApiPulumi` code keeps compiling.\n */\n primaryDynamodbTableArn: string;\n primaryDynamodbTableName: string;\n primaryDynamodbTableHashKey: string;\n primaryDynamodbTableRangeKey: string;\n auditLogsDynamodbTableArn: string;\n auditLogsDynamodbTableName: string;\n auditLogsDynamodbTableHashKey: string;\n auditLogsDynamodbTableRangeKey: string;\n eventBusName: string;\n eventBusArn: string;\n vpcPublicSubnetIds: string[] | undefined;\n vpcPrivateSubnetIds: string[] | undefined;\n vpcSecurityGroupIds: string[] | undefined;\n opensearchDomainArn: string | undefined;\n opensearchDomainEndpoint: string | undefined;\n opensearchDynamodbTableHashKey: string;\n opensearchDynamodbTableRangeKey: string;\n opensearchDynamodbTableArn: string | undefined;\n opensearchDynamodbTableName: string | undefined;\n /*\n * Set with `<Infra.AuroraPostgres />`. The password is in the `pgSecretArn` secret, never here.\n * `pgProxyHost` is set with `<Infra.AuroraPostgres rdsProxy />` only.\n */\n pgWriterHost: string | undefined;\n pgReaderHost: string | undefined;\n pgProxyHost: string | undefined;\n pgPort: number | undefined;\n pgDatabase: string | undefined;\n pgUser: string | undefined;\n pgSecretArn: string | undefined;\n /*\n * Set with `<Infra.AuroraPostgres />`: the core's service manifests (`core`, and any a\n * `CorePulumi` extension adds). The core deploys before the api's schema-setup function exists,\n * so the api deploy stores them in the database.\n */\n serviceManifests: ServiceManifest[] | undefined;\n}\n\nconst POSTGRES_OUTPUTS = [\n \"pgWriterHost\",\n \"pgReaderHost\",\n \"pgProxyHost\",\n \"pgPort\",\n \"pgDatabase\",\n \"pgUser\",\n \"pgSecretArn\"\n] as const;\n\nexport type PostgresOutputs = Pick<ICoreOutput, (typeof POSTGRES_OUTPUTS)[number]>;\n\n/* The Postgres connection outputs of the core stack, for the API app. No password among them. */\nexport const pickPostgresOutputs = (output: Record<string, unknown>): PostgresOutputs => {\n return Object.fromEntries(\n POSTGRES_OUTPUTS.map(name => [name, output[name]])\n ) as unknown as PostgresOutputs;\n};\n\nexport const CoreOutput = createAppModule({\n name: \"CoreOutput\",\n config(app) {\n return app.addHandler(async () => {\n const sdk = await getAwsProjectSdk();\n\n const output = await sdk.getAppStackOutput(\"core\");\n if (!output) {\n throw new Error(\"Core application is not deployed.\");\n }\n\n return {\n fileManagerBucketId: output[\"fileManagerBucketId\"],\n primaryDynamodbTableArn: output[\"primaryDynamodbTableArn\"],\n primaryDynamodbTableName: output[\"primaryDynamodbTableName\"],\n primaryDynamodbTableHashKey: output[\"primaryDynamodbTableHashKey\"],\n primaryDynamodbTableRangeKey: output[\"primaryDynamodbTableRangeKey\"],\n auditLogsDynamodbTableArn: output[\"auditLogsDynamodbTableArn\"],\n auditLogsDynamodbTableName: output[\"auditLogsDynamodbTableName\"],\n auditLogsDynamodbTableHashKey: output[\"auditLogsDynamodbTableHashKey\"],\n auditLogsDynamodbTableRangeKey: output[\"auditLogsDynamodbTableRangeKey\"],\n cognitoUserPoolId: output[\"cognitoUserPoolId\"],\n cognitoUserPoolArn: output[\"cognitoUserPoolArn\"],\n cognitoUserPoolPasswordPolicy: output[\"cognitoUserPoolPasswordPolicy\"],\n cognitoAppClientId: output[\"cognitoAppClientId\"],\n eventBusName: output[\"eventBusName\"],\n eventBusArn: output[\"eventBusArn\"],\n // These outputs are optional, since VPC is not always enabled.\n vpcPublicSubnetIds: output[\"vpcPublicSubnetIds\"],\n vpcPrivateSubnetIds: output[\"vpcPrivateSubnetIds\"],\n vpcSecurityGroupIds: output[\"vpcSecurityGroupIds\"],\n // These outputs are optional, since Opensearch is not always enabled.\n opensearchDomainArn: output[\"opensearchDomainArn\"],\n opensearchDomainEndpoint: output[\"opensearchDomainEndpoint\"],\n opensearchDynamodbTableArn: output[\"opensearchDynamodbTableArn\"],\n opensearchDynamodbTableName: output[\"opensearchDynamodbTableName\"],\n // These outputs are optional, since Postgres is not always enabled.\n ...pickPostgresOutputs(output),\n serviceManifests: output[\"serviceManifests\"]\n } as ICoreOutput;\n });\n }\n});\n"],"names":["POSTGRES_OUTPUTS","pickPostgresOutputs","output","Object","name","CoreOutput","createAppModule","app","sdk","getAwsProjectSdk","Error"],"mappings":";;AA4DA,MAAMA,mBAAmB;IACrB;IACA;IACA;IACA;IACA;IACA;IACA;CACH;AAKM,MAAMC,sBAAsB,CAACC,SACzBC,OAAO,WAAW,CACrBH,iBAAiB,GAAG,CAACI,CAAAA,OAAQ;YAACA;YAAMF,MAAM,CAACE,KAAK;SAAC;AAIlD,MAAMC,aAAaC,gBAAgB;IACtC,MAAM;IACN,QAAOC,GAAG;QACN,OAAOA,IAAI,UAAU,CAAC;YAClB,MAAMC,MAAM,MAAMC;YAElB,MAAMP,SAAS,MAAMM,IAAI,iBAAiB,CAAC;YAC3C,IAAI,CAACN,QACD,MAAM,IAAIQ,MAAM;YAGpB,OAAO;gBACH,qBAAqBR,MAAM,CAAC,sBAAsB;gBAClD,yBAAyBA,MAAM,CAAC,0BAA0B;gBAC1D,0BAA0BA,MAAM,CAAC,2BAA2B;gBAC5D,6BAA6BA,MAAM,CAAC,8BAA8B;gBAClE,8BAA8BA,MAAM,CAAC,+BAA+B;gBACpE,2BAA2BA,MAAM,CAAC,4BAA4B;gBAC9D,4BAA4BA,MAAM,CAAC,6BAA6B;gBAChE,+BAA+BA,MAAM,CAAC,gCAAgC;gBACtE,gCAAgCA,MAAM,CAAC,iCAAiC;gBACxE,mBAAmBA,MAAM,CAAC,oBAAoB;gBAC9C,oBAAoBA,MAAM,CAAC,qBAAqB;gBAChD,+BAA+BA,MAAM,CAAC,gCAAgC;gBACtE,oBAAoBA,MAAM,CAAC,qBAAqB;gBAChD,cAAcA,MAAM,CAAC,eAAe;gBACpC,aAAaA,MAAM,CAAC,cAAc;gBAElC,oBAAoBA,MAAM,CAAC,qBAAqB;gBAChD,qBAAqBA,MAAM,CAAC,sBAAsB;gBAClD,qBAAqBA,MAAM,CAAC,sBAAsB;gBAElD,qBAAqBA,MAAM,CAAC,sBAAsB;gBAClD,0BAA0BA,MAAM,CAAC,2BAA2B;gBAC5D,4BAA4BA,MAAM,CAAC,6BAA6B;gBAChE,6BAA6BA,MAAM,CAAC,8BAA8B;gBAElE,GAAGD,oBAAoBC,OAAO;gBAC9B,kBAAkBA,MAAM,CAAC,mBAAmB;YAChD;QACJ;IACJ;AACJ"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as aws from "@pulumi/aws";
|
|
2
|
+
import * as pulumi from "@pulumi/pulumi";
|
|
1
3
|
import { type PulumiAppModule } from "@webiny/pulumi";
|
|
2
4
|
export interface CoreCognitoParams {
|
|
3
5
|
protect: boolean;
|
|
@@ -5,6 +7,18 @@ export interface CoreCognitoParams {
|
|
|
5
7
|
mfa?: boolean;
|
|
6
8
|
}
|
|
7
9
|
export type CoreCognito = PulumiAppModule<typeof CoreCognito>;
|
|
10
|
+
/**
|
|
11
|
+
* Attributes that users must never change themselves. `custom:id` is the Webiny identity id:
|
|
12
|
+
* a user who could write it would sign in as any other user. Webiny sets it with Cognito admin
|
|
13
|
+
* APIs, which `writeAttributes` doesn't restrict.
|
|
14
|
+
*/
|
|
15
|
+
export declare const USER_PROTECTED_ATTRIBUTES: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Everything users could write before (all standard and all custom attributes of the pool,
|
|
18
|
+
* including custom attributes a project adds to the schema), except the protected ones.
|
|
19
|
+
* Cognito has no deny list for app clients, so the allowed list is built from the pool schema.
|
|
20
|
+
*/
|
|
21
|
+
export declare const getUserWritableAttributes: (schemas: pulumi.Input<aws.types.input.cognito.UserPoolSchema[] | undefined>) => pulumi.Output<string[]>;
|
|
8
22
|
export declare const CoreCognito: import("@webiny/pulumi").PulumiAppModuleDefinition<{
|
|
9
23
|
userPool: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/cognito/userPool").UserPool>;
|
|
10
24
|
userPoolClient: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/cognito/userPoolClient").UserPoolClient>;
|
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
import { createAppModule } from "@webiny/pulumi";
|
|
2
2
|
import * as __rspack_external__pulumi_aws_9e2bee2d from "@pulumi/aws";
|
|
3
|
+
import * as __rspack_external__pulumi_pulumi_f3e773ed from "@pulumi/pulumi";
|
|
4
|
+
const STANDARD_USER_WRITABLE_ATTRIBUTES = [
|
|
5
|
+
"address",
|
|
6
|
+
"birthdate",
|
|
7
|
+
"email",
|
|
8
|
+
"family_name",
|
|
9
|
+
"gender",
|
|
10
|
+
"given_name",
|
|
11
|
+
"locale",
|
|
12
|
+
"middle_name",
|
|
13
|
+
"name",
|
|
14
|
+
"nickname",
|
|
15
|
+
"phone_number",
|
|
16
|
+
"picture",
|
|
17
|
+
"preferred_username",
|
|
18
|
+
"profile",
|
|
19
|
+
"updated_at",
|
|
20
|
+
"website",
|
|
21
|
+
"zoneinfo"
|
|
22
|
+
];
|
|
23
|
+
const USER_PROTECTED_ATTRIBUTES = [
|
|
24
|
+
"custom:id"
|
|
25
|
+
];
|
|
26
|
+
const getUserWritableAttributes = (schemas)=>__rspack_external__pulumi_pulumi_f3e773ed.output(schemas).apply((items)=>{
|
|
27
|
+
const custom = (items || []).map((schema)=>schema.name).filter((name)=>!STANDARD_USER_WRITABLE_ATTRIBUTES.includes(name)).filter((name)=>!name.endsWith("_verified")).map((name)=>name.startsWith("custom:") ? name : `custom:${name}`);
|
|
28
|
+
return [
|
|
29
|
+
...new Set([
|
|
30
|
+
...STANDARD_USER_WRITABLE_ATTRIBUTES,
|
|
31
|
+
...custom
|
|
32
|
+
])
|
|
33
|
+
].filter((name)=>!USER_PROTECTED_ATTRIBUTES.includes(name));
|
|
34
|
+
});
|
|
3
35
|
const CoreCognito = createAppModule({
|
|
4
36
|
name: "Cognito",
|
|
5
37
|
config (app, params) {
|
|
@@ -103,6 +135,7 @@ const CoreCognito = createAppModule({
|
|
|
103
135
|
name: "user-pool-client",
|
|
104
136
|
config: {
|
|
105
137
|
userPoolId: userPool.output.id,
|
|
138
|
+
writeAttributes: getUserWritableAttributes(userPool.output.schemas),
|
|
106
139
|
accessTokenValidity: 60,
|
|
107
140
|
idTokenValidity: 60,
|
|
108
141
|
refreshTokenValidity: 30,
|
|
@@ -119,6 +152,6 @@ const CoreCognito = createAppModule({
|
|
|
119
152
|
};
|
|
120
153
|
}
|
|
121
154
|
});
|
|
122
|
-
export { CoreCognito };
|
|
155
|
+
export { CoreCognito, USER_PROTECTED_ATTRIBUTES, getUserWritableAttributes };
|
|
123
156
|
|
|
124
157
|
//# sourceMappingURL=CoreCognito.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulumi/apps/core/CoreCognito.js","sources":["../../../../src/pulumi/apps/core/CoreCognito.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport { createAppModule, type PulumiApp, type PulumiAppModule } from \"@webiny/pulumi\";\n\nexport interface CoreCognitoParams {\n protect: boolean;\n useEmailAsUsername: boolean;\n mfa?: boolean;\n}\n\nexport type CoreCognito = PulumiAppModule<typeof CoreCognito>;\n\nexport const CoreCognito = createAppModule({\n name: \"Cognito\",\n config(app: PulumiApp, params: CoreCognitoParams) {\n const userPool = app.addResource(aws.cognito.UserPool, {\n name: \"user-pool\",\n config: {\n passwordPolicy: {\n minimumLength: 8,\n requireLowercase: false,\n requireNumbers: false,\n requireSymbols: false,\n requireUppercase: false,\n temporaryPasswordValidityDays: 7\n },\n adminCreateUserConfig: {\n allowAdminCreateUserOnly: true\n },\n autoVerifiedAttributes: [\"email\"],\n emailConfiguration: {\n emailSendingAccount: \"COGNITO_DEFAULT\"\n },\n // In a legacy setup we use email as username.\n // We need to provide a way for users to have this setup,\n // because changing it would require whole cognito pool to be recreated.\n usernameAttributes: params.useEmailAsUsername ? [\"email\"] : undefined,\n aliasAttributes: params.useEmailAsUsername ? undefined : [\"preferred_username\"],\n lambdaConfig: {},\n mfaConfiguration: params.mfa ? \"ON\" : \"OFF\",\n softwareTokenMfaConfiguration: params.mfa ? { enabled: true } : undefined,\n userPoolAddOns: {\n advancedSecurityMode: \"OFF\" /* required */\n },\n verificationMessageTemplate: {\n defaultEmailOption: \"CONFIRM_WITH_CODE\"\n },\n accountRecoverySetting: {\n recoveryMechanisms: [{ name: \"verified_email\", priority: 1 }]\n },\n schemas: [\n {\n attributeDataType: \"String\",\n name: \"email\",\n required: true,\n developerOnlyAttribute: false,\n mutable: true,\n stringAttributeConstraints: {\n maxLength: \"2048\",\n minLength: \"0\"\n }\n },\n {\n attributeDataType: \"String\",\n name: \"family_name\",\n required: true,\n developerOnlyAttribute: false,\n mutable: true,\n stringAttributeConstraints: {\n maxLength: \"2048\",\n minLength: \"0\"\n }\n },\n {\n attributeDataType: \"String\",\n name: \"given_name\",\n required: true,\n developerOnlyAttribute: false,\n mutable: true,\n stringAttributeConstraints: {\n maxLength: \"2048\",\n minLength: \"0\"\n }\n },\n {\n attributeDataType: \"String\",\n name: \"id\",\n required: false,\n developerOnlyAttribute: false,\n mutable: true,\n stringAttributeConstraints: {\n maxLength: \"36\",\n minLength: \"0\"\n }\n }\n ]\n },\n opts: {\n protect: params.protect\n }\n });\n\n const userPoolClient = app.addResource(aws.cognito.UserPoolClient, {\n name: \"user-pool-client\",\n config: {\n userPoolId: userPool.output.id,\n accessTokenValidity: 60,\n idTokenValidity: 60,\n refreshTokenValidity: 30,\n tokenValidityUnits: {\n accessToken: \"minutes\",\n idToken: \"minutes\",\n refreshToken: \"days\"\n }\n }\n });\n\n return {\n userPool,\n userPoolClient\n };\n }\n});\n"],"names":["CoreCognito","createAppModule","app","params","userPool","aws","undefined","userPoolClient"],"mappings":"
|
|
1
|
+
{"version":3,"file":"pulumi/apps/core/CoreCognito.js","sources":["../../../../src/pulumi/apps/core/CoreCognito.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport { createAppModule, type PulumiApp, type PulumiAppModule } from \"@webiny/pulumi\";\n\nexport interface CoreCognitoParams {\n protect: boolean;\n useEmailAsUsername: boolean;\n mfa?: boolean;\n}\n\nexport type CoreCognito = PulumiAppModule<typeof CoreCognito>;\n\n/**\n * Standard attributes users may change themselves (with their own access token). The\n * `*_verified` flags are left out, so users can't mark an address they don't own as verified.\n */\nconst STANDARD_USER_WRITABLE_ATTRIBUTES = [\n \"address\",\n \"birthdate\",\n \"email\",\n \"family_name\",\n \"gender\",\n \"given_name\",\n \"locale\",\n \"middle_name\",\n \"name\",\n \"nickname\",\n \"phone_number\",\n \"picture\",\n \"preferred_username\",\n \"profile\",\n \"updated_at\",\n \"website\",\n \"zoneinfo\"\n];\n\n/**\n * Attributes that users must never change themselves. `custom:id` is the Webiny identity id:\n * a user who could write it would sign in as any other user. Webiny sets it with Cognito admin\n * APIs, which `writeAttributes` doesn't restrict.\n */\nexport const USER_PROTECTED_ATTRIBUTES = [\"custom:id\"];\n\n/**\n * Everything users could write before (all standard and all custom attributes of the pool,\n * including custom attributes a project adds to the schema), except the protected ones.\n * Cognito has no deny list for app clients, so the allowed list is built from the pool schema.\n */\nexport const getUserWritableAttributes = (\n schemas: pulumi.Input<aws.types.input.cognito.UserPoolSchema[] | undefined>\n): pulumi.Output<string[]> => {\n return pulumi.output(schemas).apply(items => {\n const custom = (items || [])\n .map(schema => schema.name)\n .filter(name => !STANDARD_USER_WRITABLE_ATTRIBUTES.includes(name))\n .filter(name => !name.endsWith(\"_verified\"))\n .map(name => (name.startsWith(\"custom:\") ? name : `custom:${name}`));\n\n return [...new Set([...STANDARD_USER_WRITABLE_ATTRIBUTES, ...custom])].filter(name => {\n return !USER_PROTECTED_ATTRIBUTES.includes(name);\n });\n });\n};\n\nexport const CoreCognito = createAppModule({\n name: \"Cognito\",\n config(app: PulumiApp, params: CoreCognitoParams) {\n const userPool = app.addResource(aws.cognito.UserPool, {\n name: \"user-pool\",\n config: {\n passwordPolicy: {\n minimumLength: 8,\n requireLowercase: false,\n requireNumbers: false,\n requireSymbols: false,\n requireUppercase: false,\n temporaryPasswordValidityDays: 7\n },\n adminCreateUserConfig: {\n allowAdminCreateUserOnly: true\n },\n autoVerifiedAttributes: [\"email\"],\n emailConfiguration: {\n emailSendingAccount: \"COGNITO_DEFAULT\"\n },\n // In a legacy setup we use email as username.\n // We need to provide a way for users to have this setup,\n // because changing it would require whole cognito pool to be recreated.\n usernameAttributes: params.useEmailAsUsername ? [\"email\"] : undefined,\n aliasAttributes: params.useEmailAsUsername ? undefined : [\"preferred_username\"],\n lambdaConfig: {},\n mfaConfiguration: params.mfa ? \"ON\" : \"OFF\",\n softwareTokenMfaConfiguration: params.mfa ? { enabled: true } : undefined,\n userPoolAddOns: {\n advancedSecurityMode: \"OFF\" /* required */\n },\n verificationMessageTemplate: {\n defaultEmailOption: \"CONFIRM_WITH_CODE\"\n },\n accountRecoverySetting: {\n recoveryMechanisms: [{ name: \"verified_email\", priority: 1 }]\n },\n schemas: [\n {\n attributeDataType: \"String\",\n name: \"email\",\n required: true,\n developerOnlyAttribute: false,\n mutable: true,\n stringAttributeConstraints: {\n maxLength: \"2048\",\n minLength: \"0\"\n }\n },\n {\n attributeDataType: \"String\",\n name: \"family_name\",\n required: true,\n developerOnlyAttribute: false,\n mutable: true,\n stringAttributeConstraints: {\n maxLength: \"2048\",\n minLength: \"0\"\n }\n },\n {\n attributeDataType: \"String\",\n name: \"given_name\",\n required: true,\n developerOnlyAttribute: false,\n mutable: true,\n stringAttributeConstraints: {\n maxLength: \"2048\",\n minLength: \"0\"\n }\n },\n {\n attributeDataType: \"String\",\n name: \"id\",\n required: false,\n developerOnlyAttribute: false,\n mutable: true,\n stringAttributeConstraints: {\n maxLength: \"36\",\n minLength: \"0\"\n }\n }\n ]\n },\n opts: {\n protect: params.protect\n }\n });\n\n const userPoolClient = app.addResource(aws.cognito.UserPoolClient, {\n name: \"user-pool-client\",\n config: {\n userPoolId: userPool.output.id,\n writeAttributes: getUserWritableAttributes(userPool.output.schemas),\n accessTokenValidity: 60,\n idTokenValidity: 60,\n refreshTokenValidity: 30,\n tokenValidityUnits: {\n accessToken: \"minutes\",\n idToken: \"minutes\",\n refreshToken: \"days\"\n }\n }\n });\n\n return {\n userPool,\n userPoolClient\n };\n }\n});\n"],"names":["STANDARD_USER_WRITABLE_ATTRIBUTES","USER_PROTECTED_ATTRIBUTES","getUserWritableAttributes","schemas","pulumi","items","custom","schema","name","Set","CoreCognito","createAppModule","app","params","userPool","aws","undefined","userPoolClient"],"mappings":";;;AAgBA,MAAMA,oCAAoC;IACtC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACH;AAOM,MAAMC,4BAA4B;IAAC;CAAY;AAO/C,MAAMC,4BAA4B,CACrCC,UAEOC,0CAAAA,MAAa,CAACD,SAAS,KAAK,CAACE,CAAAA;QAChC,MAAMC,SAAUD,AAAAA,CAAAA,SAAS,EAAC,EACrB,GAAG,CAACE,CAAAA,SAAUA,OAAO,IAAI,EACzB,MAAM,CAACC,CAAAA,OAAQ,CAACR,kCAAkC,QAAQ,CAACQ,OAC3D,MAAM,CAACA,CAAAA,OAAQ,CAACA,KAAK,QAAQ,CA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;wBACT,4BAA4B;4BACxB,WAAW;4BACX,WAAW;wBACf;oBACJ;oBACA;wBACI,mBAAmB;wBACnB,MAAM;wBACN,UAAU;wBACV,wBAAwB;wBACxB,SAAS;wBACT,4BAA4B;4BACxB,WAAW;4BACX,WAAW;wBACf;oBACJ;oBACA;wBACI,mBAAmB;wBACnB,MAAM;wBACN,UAAU;wBACV,wBAAwB;wBACxB,SAAS;wBACT,4BAA4B;4BACxB,WAAW;4BACX,WAAW;wBACf;oBACJ;iBACH;YACL;YACA,MAAM;gBACF,SAASH,OAAO,OAAO;YAC3B;QACJ;QAEA,MAAMI,iBAAiBL,IAAI,WAAW,CAACG,uCAAAA,OAAAA,CAAAA,cAA0B,EAAE;YAC/D,MAAM;YACN,QAAQ;gBACJ,YAAYD,SAAS,MAAM,CAAC,EAAE;gBAC9B,iBAAiBZ,0BAA0BY,SAAS,MAAM,CAAC,OAAO;gBAClE,qBAAqB;gBACrB,iBAAiB;gBACjB,sBAAsB;gBACtB,oBAAoB;oBAChB,aAAa;oBACb,SAAS;oBACT,cAAc;gBAClB;YACJ;QACJ;QAEA,OAAO;YACHA;YACAG;QACJ;IACJ;AACJ"}
|
|
@@ -18,10 +18,10 @@ export interface CorePostgresParams {
|
|
|
18
18
|
getEngineVersion?: () => pulumi.Input<string>;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* The Postgres database of a project with `<Infra.
|
|
22
|
-
* v2 cluster with a writer and `readers` reader instances, and its credentials in a
|
|
23
|
-
* secret (`{ username, password }`). With `rdsProxy`, an RDS Proxy in front of it,
|
|
24
|
-
* same secret.
|
|
21
|
+
* The Postgres database of a project with `<Infra.AuroraPostgres />`: an Aurora PostgreSQL 17
|
|
22
|
+
* Serverless v2 cluster with a writer and `readers` reader instances, and its credentials in a
|
|
23
|
+
* Secrets Manager secret (`{ username, password }`). With `rdsProxy`, an RDS Proxy in front of it,
|
|
24
|
+
* which reads the same secret.
|
|
25
25
|
*
|
|
26
26
|
* The cluster, its instances and the proxy go into `network`: the private subnets of the VPC the
|
|
27
27
|
* core app creates and its default security group, which the API functions use too, or the
|
|
@@ -117,7 +117,8 @@ const CorePostgres = createAppModule({
|
|
|
117
117
|
],
|
|
118
118
|
copyTagsToSnapshot: true,
|
|
119
119
|
deletionProtection: protect,
|
|
120
|
-
backupRetentionPeriod: protect ?
|
|
120
|
+
backupRetentionPeriod: protect ? 35 : 1,
|
|
121
|
+
deleteAutomatedBackups: protect ? false : void 0,
|
|
121
122
|
skipFinalSnapshot: !protect,
|
|
122
123
|
finalSnapshotIdentifier: finalSnapshotSuffix ? __rspack_external__pulumi_pulumi_f3e773ed.interpolate`webiny-pg-final-${finalSnapshotSuffix.output.hex}` : void 0,
|
|
123
124
|
applyImmediately: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulumi/apps/core/CorePostgres.js","sources":["../../../../src/pulumi/apps/core/CorePostgres.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport * as random from \"@pulumi/random\";\nimport {\n createAppModule,\n type PulumiApp,\n type PulumiAppModule,\n type PulumiAppResource\n} from \"@webiny/pulumi\";\n\nexport type CorePostgres = PulumiAppModule<typeof CorePostgres>;\n\nexport const POSTGRES_DATABASE = \"webiny\";\nexport const POSTGRES_USER = \"webiny\";\nexport const POSTGRES_PORT = 5432;\n\n/* Aurora PostgreSQL's major version, and its cluster parameter group family. */\nconst ENGINE = \"aurora-postgresql\";\nconst ENGINE_MAJOR_VERSION = \"17\";\nconst PARAMETER_GROUP_FAMILY = \"aurora-postgresql17\";\n\nexport interface PostgresNetwork {\n subnetIds: pulumi.Input<pulumi.Input<string>[]>;\n securityGroupIds: pulumi.Input<pulumi.Input<string>[]>;\n}\n\nexport interface CorePostgresParams {\n minCapacity: number;\n maxCapacity: number;\n readers: number;\n rdsProxy: boolean;\n network: PostgresNetwork;\n /* On in production: deletion protection, a week of backups and a final snapshot. */\n protect: boolean;\n /*\n * The engine version a new cluster gets: the latest 17.x. Replaced in tests, where there is no\n * AWS to ask.\n */\n getEngineVersion?: () => pulumi.Input<string>;\n}\n\nconst getLatestEngineVersion = () => {\n return pulumi.output(\n aws.rds.getEngineVersion({ engine: ENGINE, version: ENGINE_MAJOR_VERSION, latest: true })\n ).versionActual;\n};\n\nconst assumeRolePolicy = (service: string) =>\n JSON.stringify({\n Version: \"2012-10-17\",\n Statement: [{ Effect: \"Allow\", Principal: { Service: service }, Action: \"sts:AssumeRole\" }]\n });\n\n/**\n * The Postgres database of a project with `<Infra.Postgres />`: an Aurora PostgreSQL 17 Serverless\n * v2 cluster with a writer and `readers` reader instances, and its credentials in a Secrets Manager\n * secret (`{ username, password }`). With `rdsProxy`, an RDS Proxy in front of it, which reads the\n * same secret.\n *\n * The cluster, its instances and the proxy go into `network`: the private subnets of the VPC the\n * core app creates and its default security group, which the API functions use too, or the\n * `postgresVpcConfig` of an existing VPC.\n *\n * No password leaves this module: the API reads it from the secret.\n */\nexport const CorePostgres = createAppModule({\n name: \"CorePostgres\",\n config(app: PulumiApp, params: CorePostgresParams) {\n const { network, protect } = params;\n const getEngineVersion = params.getEngineVersion ?? getLatestEngineVersion;\n\n const password = app.addResource(random.RandomPassword, {\n name: \"pg-db-password\",\n config: { length: 32, special: false }\n });\n\n const secret = app.addResource(aws.secretsmanager.Secret, {\n name: \"pg-db\",\n config: {\n description: \"Credentials of the Webiny Postgres database.\",\n // Outside production, a destroyed project can be deployed again at once.\n recoveryWindowInDays: protect ? 7 : 0\n },\n opts: { protect }\n });\n\n app.addResource(aws.secretsmanager.SecretVersion, {\n name: \"pg-db\",\n config: {\n secretId: secret.output.id,\n secretString: pulumi\n .all([password.output.result])\n .apply(([value]) =>\n JSON.stringify({ username: POSTGRES_USER, password: value })\n )\n }\n });\n\n const subnetGroup = app.addResource(aws.rds.SubnetGroup, {\n name: \"pg-db\",\n config: {\n description: \"Subnets of the Webiny Postgres database.\",\n subnetIds: network.subnetIds\n }\n });\n\n /*\n * The server notices a client that went away without closing its connection (a Lambda\n * environment that was recycled) within about two minutes, and frees the connection.\n */\n const parameterGroup = app.addResource(aws.rds.ClusterParameterGroup, {\n name: \"pg-db\",\n config: {\n family: PARAMETER_GROUP_FAMILY,\n description: \"Webiny Postgres database: TCP keepalives.\",\n parameters: [\n { name: \"tcp_keepalives_idle\", value: \"60\" },\n { name: \"tcp_keepalives_interval\", value: \"10\" },\n { name: \"tcp_keepalives_count\", value: \"6\" }\n ]\n }\n });\n\n // A final snapshot needs a name that no earlier snapshot of the account has.\n const finalSnapshotSuffix = protect\n ? app.addResource(random.RandomId, {\n name: \"pg-db-final-snapshot\",\n config: { byteLength: 4 }\n })\n : null;\n\n const cluster = app.addResource(aws.rds.Cluster, {\n name: \"pg-db\",\n config: {\n engine: ENGINE,\n engineMode: \"provisioned\",\n engineVersion: getEngineVersion(),\n databaseName: POSTGRES_DATABASE,\n masterUsername: POSTGRES_USER,\n masterPassword: password.output.result,\n port: POSTGRES_PORT,\n storageType: \"aurora\",\n storageEncrypted: true,\n dbSubnetGroupName: subnetGroup.output.name,\n dbClusterParameterGroupName: parameterGroup.output.name,\n vpcSecurityGroupIds: network.securityGroupIds,\n serverlessv2ScalingConfiguration: {\n minCapacity: params.minCapacity,\n maxCapacity: params.maxCapacity\n },\n enabledCloudwatchLogsExports: [\"postgresql\"],\n copyTagsToSnapshot: true,\n deletionProtection: protect,\n backupRetentionPeriod: protect ? 7 : 1,\n skipFinalSnapshot: !protect,\n finalSnapshotIdentifier: finalSnapshotSuffix\n ? pulumi.interpolate`webiny-pg-final-${finalSnapshotSuffix.output.hex}`\n : undefined,\n // Capacity changes apply now, not in the next maintenance window.\n applyImmediately: true\n },\n opts: {\n protect,\n // The version is picked when the cluster is created; AWS applies minor upgrades.\n // A newer 17.x must not make a later deploy upgrade the cluster.\n ignoreChanges: [\"engineVersion\"]\n }\n });\n\n const instances = [];\n for (let index = 0; index <= params.readers; index++) {\n const isWriter = index === 0;\n instances.push(\n app.addResource(aws.rds.ClusterInstance, {\n name: isWriter ? \"pg-db-writer\" : `pg-db-reader-${index}`,\n config: {\n clusterIdentifier: cluster.output.id,\n instanceClass: \"db.serverless\",\n engine: ENGINE,\n engineVersion: cluster.output.engineVersion,\n publiclyAccessible: false,\n performanceInsightsEnabled: true,\n // Readers in tier 0–1 scale with the writer, so a failover lands on a warm one.\n promotionTier: isWriter ? 0 : 1,\n applyImmediately: true\n },\n opts: { ignoreChanges: [\"engineVersion\"] }\n })\n );\n }\n\n let proxy: ReturnType<typeof addProxy> | null = null;\n if (params.rdsProxy) {\n proxy = addProxy(app, { secret, cluster, instances, network });\n }\n\n return {\n cluster,\n instances,\n secret,\n subnetGroup,\n parameterGroup,\n proxy: proxy?.proxy ?? null,\n outputs: {\n pgWriterHost: cluster.output.endpoint,\n pgReaderHost: cluster.output.readerEndpoint,\n ...(proxy ? { pgProxyHost: proxy.proxy.output.endpoint } : {}),\n pgPort: POSTGRES_PORT,\n pgDatabase: POSTGRES_DATABASE,\n pgUser: POSTGRES_USER,\n pgSecretArn: secret.output.arn\n }\n };\n }\n});\n\ninterface AddProxyParams {\n secret: PulumiAppResource<typeof aws.secretsmanager.Secret>;\n cluster: PulumiAppResource<typeof aws.rds.Cluster>;\n instances: PulumiAppResource<typeof aws.rds.ClusterInstance>[];\n network: PostgresNetwork;\n}\n\nfunction addProxy(app: PulumiApp, params: AddProxyParams) {\n const { secret, cluster, instances, network } = params;\n\n const role = app.addResource(aws.iam.Role, {\n name: \"pg-proxy\",\n config: { assumeRolePolicy: assumeRolePolicy(\"rds.amazonaws.com\") }\n });\n\n app.addResource(aws.iam.RolePolicy, {\n name: \"pg-proxy\",\n config: {\n role: role.output.id,\n policy: pulumi.all([secret.output.arn]).apply(([arn]) =>\n JSON.stringify({\n Version: \"2012-10-17\",\n Statement: [\n {\n Effect: \"Allow\",\n Action: [\"secretsmanager:GetSecretValue\"],\n Resource: [arn]\n }\n ]\n })\n )\n }\n });\n\n const proxy = app.addResource(aws.rds.Proxy, {\n name: \"pg-proxy\",\n config: {\n engineFamily: \"POSTGRESQL\",\n auths: [{ authScheme: \"SECRETS\", iamAuth: \"DISABLED\", secretArn: secret.output.arn }],\n roleArn: role.output.arn,\n vpcSubnetIds: network.subnetIds,\n vpcSecurityGroupIds: network.securityGroupIds,\n requireTls: true,\n idleClientTimeout: 900,\n debugLogging: false\n }\n });\n\n const targetGroup = app.addResource(aws.rds.ProxyDefaultTargetGroup, {\n name: \"pg-proxy\",\n config: {\n dbProxyName: proxy.output.name,\n connectionPoolConfig: {\n maxConnectionsPercent: 70,\n maxIdleConnectionsPercent: 50,\n connectionBorrowTimeout: 10\n }\n }\n });\n\n app.addResource(aws.rds.ProxyTarget, {\n name: \"pg-proxy\",\n config: {\n dbProxyName: proxy.output.name,\n targetGroupName: targetGroup.output.name,\n dbClusterIdentifier: cluster.output.id\n },\n // The proxy can only register a cluster whose instances are available.\n opts: { dependsOn: instances.map(instance => instance.output) }\n });\n\n return { role, proxy, targetGroup };\n}\n"],"names":["POSTGRES_DATABASE","POSTGRES_USER","POSTGRES_PORT","ENGINE","ENGINE_MAJOR_VERSION","PARAMETER_GROUP_FAMILY","getLatestEngineVersion","pulumi","aws","assumeRolePolicy","service","JSON","CorePostgres","createAppModule","app","params","network","protect","getEngineVersion","password","random","secret","value","subnetGroup","parameterGroup","finalSnapshotSuffix","cluster","undefined","instances","index","isWriter","proxy","addProxy","role","arn","targetGroup","instance"],"mappings":";;;;AAYO,MAAMA,oBAAoB;AAC1B,MAAMC,gBAAgB;AACtB,MAAMC,gBAAgB;AAG7B,MAAMC,SAAS;AACf,MAAMC,uBAAuB;AAC7B,MAAMC,yBAAyB;AAsB/B,MAAMC,yBAAyB,IACpBC,0CAAAA,MAAa,CAChBC,uCAAAA,GAAAA,CAAAA,gBAAwB,CAAC;QAAE,QAAQL;QAAQ,SAASC;QAAsB,QAAQ;IAAK,IACzF,aAAa;AAGnB,MAAMK,mBAAmB,CAACC,UACtBC,KAAK,SAAS,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AC,CAAC,CAACa,IAAI,GAChDvB,KAAK,SAAS,CAAC;oBACX,SAAS;oBACT,WAAW;wBACP;4BACI,QAAQ;4BACR,QAAQ;gCAAC;6BAAgC;4BACzC,UAAU;gCAACuB;6BAAI;wBACnB;qBACH;gBACL;QAER;IACJ;IAEA,MAAMH,QAAQjB,IAAI,WAAW,CAACN,uCAAAA,GAAAA,CAAAA,KAAa,EAAE;QACzC,MAAM;QACN,QAAQ;YACJ,cAAc;YACd,OAAO;gBAAC;oBAAE,YAAY;oBAAW,SAAS;oBAAY,WAAWa,OAAO,MAAM,CAAC,GAAG;gBAAC;aAAE;YACrF,SAASY,KAAK,MAAM,CAAC,GAAG;YACxB,cAAcjB,QAAQ,SAAS;YAC/B,qBAAqBA,QAAQ,gBAAgB;YAC7C,YAAY;YACZ,mBAAmB;YACnB,cAAc;QAClB;IACJ;IAEA,MAAMmB,cAAcrB,IAAI,WAAW,CAACN,uCAAAA,GAAAA,CAAAA,uBAA+B,EAAE;QACjE,MAAM;QACN,QAAQ;YACJ,aAAauB,MAAM,MAAM,CAAC,IAAI;YAC9B,sBAAsB;gBAClB,uBAAuB;gBACvB,2BAA2B;gBAC3B,yBAAyB;YAC7B;QACJ;IACJ;IAEAjB,IAAI,WAAW,CAACN,uCAAAA,GAAAA,CAAAA,WAAmB,EAAE;QACjC,MAAM;QACN,QAAQ;YACJ,aAAauB,MAAM,MAAM,CAAC,IAAI;YAC9B,iBAAiBI,YAAY,MAAM,CAAC,IAAI;YACxC,qBAAqBT,QAAQ,MAAM,CAAC,EAAE;QAC1C;QAEA,MAAM;YAAE,WAAWE,UAAU,GAAG,CAACQ,CAAAA,WAAYA,SAAS,MAAM;QAAE;IAClE;IAEA,OAAO;QAAEH;QAAMF;QAAOI;IAAY;AACtC"}
|
|
1
|
+
{"version":3,"file":"pulumi/apps/core/CorePostgres.js","sources":["../../../../src/pulumi/apps/core/CorePostgres.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport * as random from \"@pulumi/random\";\nimport {\n createAppModule,\n type PulumiApp,\n type PulumiAppModule,\n type PulumiAppResource\n} from \"@webiny/pulumi\";\n\nexport type CorePostgres = PulumiAppModule<typeof CorePostgres>;\n\nexport const POSTGRES_DATABASE = \"webiny\";\nexport const POSTGRES_USER = \"webiny\";\nexport const POSTGRES_PORT = 5432;\n\n/* Aurora PostgreSQL's major version, and its cluster parameter group family. */\nconst ENGINE = \"aurora-postgresql\";\nconst ENGINE_MAJOR_VERSION = \"17\";\nconst PARAMETER_GROUP_FAMILY = \"aurora-postgresql17\";\n\nexport interface PostgresNetwork {\n subnetIds: pulumi.Input<pulumi.Input<string>[]>;\n securityGroupIds: pulumi.Input<pulumi.Input<string>[]>;\n}\n\nexport interface CorePostgresParams {\n minCapacity: number;\n maxCapacity: number;\n readers: number;\n rdsProxy: boolean;\n network: PostgresNetwork;\n /*\n * On in production: deletion protection, 35 days of backups that outlive the cluster, and a\n * final snapshot.\n */\n protect: boolean;\n /*\n * The engine version a new cluster gets: the latest 17.x. Replaced in tests, where there is no\n * AWS to ask.\n */\n getEngineVersion?: () => pulumi.Input<string>;\n}\n\nconst getLatestEngineVersion = () => {\n return pulumi.output(\n aws.rds.getEngineVersion({ engine: ENGINE, version: ENGINE_MAJOR_VERSION, latest: true })\n ).versionActual;\n};\n\nconst assumeRolePolicy = (service: string) =>\n JSON.stringify({\n Version: \"2012-10-17\",\n Statement: [{ Effect: \"Allow\", Principal: { Service: service }, Action: \"sts:AssumeRole\" }]\n });\n\n/**\n * The Postgres database of a project with `<Infra.AuroraPostgres />`: an Aurora PostgreSQL 17\n * Serverless v2 cluster with a writer and `readers` reader instances, and its credentials in a\n * Secrets Manager secret (`{ username, password }`). With `rdsProxy`, an RDS Proxy in front of it,\n * which reads the same secret.\n *\n * The cluster, its instances and the proxy go into `network`: the private subnets of the VPC the\n * core app creates and its default security group, which the API functions use too, or the\n * `postgresVpcConfig` of an existing VPC.\n *\n * No password leaves this module: the API reads it from the secret.\n */\nexport const CorePostgres = createAppModule({\n name: \"CorePostgres\",\n config(app: PulumiApp, params: CorePostgresParams) {\n const { network, protect } = params;\n const getEngineVersion = params.getEngineVersion ?? getLatestEngineVersion;\n\n const password = app.addResource(random.RandomPassword, {\n name: \"pg-db-password\",\n config: { length: 32, special: false }\n });\n\n const secret = app.addResource(aws.secretsmanager.Secret, {\n name: \"pg-db\",\n config: {\n description: \"Credentials of the Webiny Postgres database.\",\n // Outside production, a destroyed project can be deployed again at once.\n recoveryWindowInDays: protect ? 7 : 0\n },\n opts: { protect }\n });\n\n app.addResource(aws.secretsmanager.SecretVersion, {\n name: \"pg-db\",\n config: {\n secretId: secret.output.id,\n secretString: pulumi\n .all([password.output.result])\n .apply(([value]) =>\n JSON.stringify({ username: POSTGRES_USER, password: value })\n )\n }\n });\n\n const subnetGroup = app.addResource(aws.rds.SubnetGroup, {\n name: \"pg-db\",\n config: {\n description: \"Subnets of the Webiny Postgres database.\",\n subnetIds: network.subnetIds\n }\n });\n\n /*\n * The server notices a client that went away without closing its connection (a Lambda\n * environment that was recycled) within about two minutes, and frees the connection.\n */\n const parameterGroup = app.addResource(aws.rds.ClusterParameterGroup, {\n name: \"pg-db\",\n config: {\n family: PARAMETER_GROUP_FAMILY,\n description: \"Webiny Postgres database: TCP keepalives.\",\n parameters: [\n { name: \"tcp_keepalives_idle\", value: \"60\" },\n { name: \"tcp_keepalives_interval\", value: \"10\" },\n { name: \"tcp_keepalives_count\", value: \"6\" }\n ]\n }\n });\n\n // A final snapshot needs a name that no earlier snapshot of the account has.\n const finalSnapshotSuffix = protect\n ? app.addResource(random.RandomId, {\n name: \"pg-db-final-snapshot\",\n config: { byteLength: 4 }\n })\n : null;\n\n const cluster = app.addResource(aws.rds.Cluster, {\n name: \"pg-db\",\n config: {\n engine: ENGINE,\n engineMode: \"provisioned\",\n engineVersion: getEngineVersion(),\n databaseName: POSTGRES_DATABASE,\n masterUsername: POSTGRES_USER,\n masterPassword: password.output.result,\n port: POSTGRES_PORT,\n storageType: \"aurora\",\n storageEncrypted: true,\n dbSubnetGroupName: subnetGroup.output.name,\n dbClusterParameterGroupName: parameterGroup.output.name,\n vpcSecurityGroupIds: network.securityGroupIds,\n serverlessv2ScalingConfiguration: {\n minCapacity: params.minCapacity,\n maxCapacity: params.maxCapacity\n },\n enabledCloudwatchLogsExports: [\"postgresql\"],\n copyTagsToSnapshot: true,\n deletionProtection: protect,\n // Point-in-time restore is always on in Aurora; this is its window. Production\n // keeps the maximum, 35 days, the same as DynamoDB's point-in-time recovery.\n // Backup storage up to the cluster volume's size is free. Elsewhere, 1 day.\n backupRetentionPeriod: protect ? 35 : 1,\n // Production keeps its automated backups when the cluster is deleted, so it can\n // still be restored to a point in time until the window runs out. The first day is\n // free, later days are billed, and a region holds at most 40 retained automated\n // backups. Elsewhere the default (true) applies: a destroyed environment leaves\n // nothing behind.\n deleteAutomatedBackups: protect ? false : undefined,\n skipFinalSnapshot: !protect,\n finalSnapshotIdentifier: finalSnapshotSuffix\n ? pulumi.interpolate`webiny-pg-final-${finalSnapshotSuffix.output.hex}`\n : undefined,\n // Capacity changes apply now, not in the next maintenance window.\n applyImmediately: true\n },\n opts: {\n protect,\n // The version is picked when the cluster is created; AWS applies minor upgrades.\n // A newer 17.x must not make a later deploy upgrade the cluster.\n ignoreChanges: [\"engineVersion\"]\n }\n });\n\n const instances = [];\n for (let index = 0; index <= params.readers; index++) {\n const isWriter = index === 0;\n instances.push(\n app.addResource(aws.rds.ClusterInstance, {\n name: isWriter ? \"pg-db-writer\" : `pg-db-reader-${index}`,\n config: {\n clusterIdentifier: cluster.output.id,\n instanceClass: \"db.serverless\",\n engine: ENGINE,\n engineVersion: cluster.output.engineVersion,\n publiclyAccessible: false,\n performanceInsightsEnabled: true,\n // Readers in tier 0–1 scale with the writer, so a failover lands on a warm one.\n promotionTier: isWriter ? 0 : 1,\n applyImmediately: true\n },\n opts: { ignoreChanges: [\"engineVersion\"] }\n })\n );\n }\n\n let proxy: ReturnType<typeof addProxy> | null = null;\n if (params.rdsProxy) {\n proxy = addProxy(app, { secret, cluster, instances, network });\n }\n\n return {\n cluster,\n instances,\n secret,\n subnetGroup,\n parameterGroup,\n proxy: proxy?.proxy ?? null,\n outputs: {\n pgWriterHost: cluster.output.endpoint,\n pgReaderHost: cluster.output.readerEndpoint,\n ...(proxy ? { pgProxyHost: proxy.proxy.output.endpoint } : {}),\n pgPort: POSTGRES_PORT,\n pgDatabase: POSTGRES_DATABASE,\n pgUser: POSTGRES_USER,\n pgSecretArn: secret.output.arn\n }\n };\n }\n});\n\ninterface AddProxyParams {\n secret: PulumiAppResource<typeof aws.secretsmanager.Secret>;\n cluster: PulumiAppResource<typeof aws.rds.Cluster>;\n instances: PulumiAppResource<typeof aws.rds.ClusterInstance>[];\n network: PostgresNetwork;\n}\n\nfunction addProxy(app: PulumiApp, params: AddProxyParams) {\n const { secret, cluster, instances, network } = params;\n\n const role = app.addResource(aws.iam.Role, {\n name: \"pg-proxy\",\n config: { assumeRolePolicy: assumeRolePolicy(\"rds.amazonaws.com\") }\n });\n\n app.addResource(aws.iam.RolePolicy, {\n name: \"pg-proxy\",\n config: {\n role: role.output.id,\n policy: pulumi.all([secret.output.arn]).apply(([arn]) =>\n JSON.stringify({\n Version: \"2012-10-17\",\n Statement: [\n {\n Effect: \"Allow\",\n Action: [\"secretsmanager:GetSecretValue\"],\n Resource: [arn]\n }\n ]\n })\n )\n }\n });\n\n const proxy = app.addResource(aws.rds.Proxy, {\n name: \"pg-proxy\",\n config: {\n engineFamily: \"POSTGRESQL\",\n auths: [{ authScheme: \"SECRETS\", iamAuth: \"DISABLED\", secretArn: secret.output.arn }],\n roleArn: role.output.arn,\n vpcSubnetIds: network.subnetIds,\n vpcSecurityGroupIds: network.securityGroupIds,\n requireTls: true,\n idleClientTimeout: 900,\n debugLogging: false\n }\n });\n\n const targetGroup = app.addResource(aws.rds.ProxyDefaultTargetGroup, {\n name: \"pg-proxy\",\n config: {\n dbProxyName: proxy.output.name,\n connectionPoolConfig: {\n maxConnectionsPercent: 70,\n maxIdleConnectionsPercent: 50,\n connectionBorrowTimeout: 10\n }\n }\n });\n\n app.addResource(aws.rds.ProxyTarget, {\n name: \"pg-proxy\",\n config: {\n dbProxyName: proxy.output.name,\n targetGroupName: targetGroup.output.name,\n dbClusterIdentifier: cluster.output.id\n },\n // The proxy can only register a cluster whose instances are available.\n opts: { dependsOn: instances.map(instance => instance.output) }\n });\n\n return { role, proxy, targetGroup };\n}\n"],"names":["POSTGRES_DATABASE","POSTGRES_USER","POSTGRES_PORT","ENGINE","ENGINE_MAJOR_VERSION","PARAMETER_GROUP_FAMILY","getLatestEngineVersion","pulumi","aws","assumeRolePolicy","service","JSON","CorePostgres","createAppModule","app","params","network","protect","getEngineVersion","password","random","secret","value","subnetGroup","parameterGroup","finalSnapshotSuffix","cluster","undefined","instances","index","isWriter","proxy","addProxy","role","arn","targetGroup","instance"],"mappings":";;;;AAYO,MAAMA,oBAAoB;AAC1B,MAAMC,gBAAgB;AACtB,MAAMC,gBAAgB;AAG7B,MAAMC,SAAS;AACf,MAAMC,uBAAuB;AAC7B,MAAMC,yBAAyB;AAyB/B,MAAMC,yBAAyB,IACpBC,0CAAAA,MAAa,CAChBC,uCAAAA,GAAAA,CAAAA,gBAAwB,CAAC;QAAE,QAAQL;QAAQ,SAASC;QAAsB,QAAQ;IAAK,IACzF,aAAa;AAGnB,MAAMK,mBAAmB,CAACC,UACtBC,KAAK,SAAS,CAAC;QACX,SAAS;QACT,WAAW;YAAC;gBAAE,QAAQ;gBAAS,WAAW;oBAAE,SAASD;gBAAQ;gBAAG,QAAQ;YAAiB;SAAE;IAC/F;AAcG,MAAME,eAAeC,gBAAgB;IACxC,MAAM;IACN,QAAOC,GAAc,EAAEC,MAA0B;QAC7C,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE,GAAGF;QAC7B,MAAMG,mBAAmBH,OAAO,gBAAgB,IAAIT;QAEpD,MAAMa,WAAWL,IA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ACJ,cAAc;YACd,OAAO;gBAAC;oBAAE,YAAY;oBAAW,SAAS;oBAAY,WAAWa,OAAO,MAAM,CAAC,GAAG;gBAAC;aAAE;YACrF,SAASY,KAAK,MAAM,CAAC,GAAG;YACxB,cAAcjB,QAAQ,SAAS;YAC/B,qBAAqBA,QAAQ,gBAAgB;YAC7C,YAAY;YACZ,mBAAmB;YACnB,cAAc;QAClB;IACJ;IAEA,MAAMmB,cAAcrB,IAAI,WAAW,CAACN,uCAAAA,GAAAA,CAAAA,uBAA+B,EAAE;QACjE,MAAM;QACN,QAAQ;YACJ,aAAauB,MAAM,MAAM,CAAC,IAAI;YAC9B,sBAAsB;gBAClB,uBAAuB;gBACvB,2BAA2B;gBAC3B,yBAAyB;YAC7B;QACJ;IACJ;IAEAjB,IAAI,WAAW,CAACN,uCAAAA,GAAAA,CAAAA,WAAmB,EAAE;QACjC,MAAM;QACN,QAAQ;YACJ,aAAauB,MAAM,MAAM,CAAC,IAAI;YAC9B,iBAAiBI,YAAY,MAAM,CAAC,IAAI;YACxC,qBAAqBT,QAAQ,MAAM,CAAC,EAAE;QAC1C;QAEA,MAAM;YAAE,WAAWE,UAAU,GAAG,CAACQ,CAAAA,WAAYA,SAAS,MAAM;QAAE;IAClE;IAEA,OAAO;QAAEH;QAAMF;QAAOI;IAAY;AACtC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getIdpConfig } from "./getIdpConfig.js";
|
|
2
|
+
import { getUserWritableAttributes } from "../CoreCognito.js";
|
|
2
3
|
import { getEnvVariableAwsRegion } from "../../../env/awsRegion.js";
|
|
3
4
|
import * as __rspack_external__pulumi_aws_9e2bee2d from "@pulumi/aws";
|
|
4
5
|
import * as __rspack_external__pulumi_pulumi_f3e773ed from "@pulumi/pulumi";
|
|
@@ -41,6 +42,16 @@ const configureAdminCognitoFederation = (app, config)=>{
|
|
|
41
42
|
return config.providerType;
|
|
42
43
|
})
|
|
43
44
|
]);
|
|
45
|
+
const mappedAttributes = idpConfigs.flatMap((config)=>{
|
|
46
|
+
const mapping = config.attributeMapping || {};
|
|
47
|
+
return Object.keys(mapping).filter((name)=>"username" !== name);
|
|
48
|
+
});
|
|
49
|
+
appClient.config.writeAttributes(getUserWritableAttributes(userPool.output.schemas).apply((attributes)=>[
|
|
50
|
+
...new Set([
|
|
51
|
+
...attributes,
|
|
52
|
+
...mappedAttributes
|
|
53
|
+
])
|
|
54
|
+
]));
|
|
44
55
|
appClient.config.allowedOauthScopes([
|
|
45
56
|
"profile",
|
|
46
57
|
"email",
|