From 96eccab42ce60a11db3a0c925ab0ba9b9816a54b Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 15 Oct 2024 13:08:22 -0400 Subject: [PATCH] Docs: sst.aws.iamEdit --- platform/src/components/aws/iam-edit.ts | 26 +++++++++++++++++++++++++ www/generate.ts | 20 +++++++++++++++---- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/platform/src/components/aws/iam-edit.ts b/platform/src/components/aws/iam-edit.ts index ea261aa86..0612f60a1 100644 --- a/platform/src/components/aws/iam-edit.ts +++ b/platform/src/components/aws/iam-edit.ts @@ -8,6 +8,32 @@ type PartialUnwrappedPolicyDocument = { Statement: Input[]; }; +/** + * The AWS IAM Edit helper is used to modify the AWS IAM policy. + * + * The IAM policy document is normally in the form of a JSON string. This helper decodes + * the string into a JSON object and allows you to modify the policy document in a type-safe + * manner. + * + * @example + * + * ```ts {4} + * new sst.aws.Bucket("MyBucket", { + * transform: { + * policy: (args) => { + * args.policy = sst.aws.iamEdit(args.policy, (policy) => { + * policy.Statement.push({ + * Effect: "Allow", + * Principal: { Service: "ses.amazonaws.com" }, + * Action: "s3:PutObject", + * Resource: $interpolate`arn:aws:s3:::${args.bucket}/*`, + * }); + * }); + * }, + * }, + * }); + * ``` + */ export function iamEdit( policy: Input, cb: (doc: Prettify) => void, diff --git a/www/generate.ts b/www/generate.ts index cb0b3be74..030f04f75 100644 --- a/www/generate.ts +++ b/www/generate.ts @@ -60,9 +60,14 @@ if (!cmd || cmd === "components") { for (const component of components) { const sourceFile = component.sources![0].fileName; - if (sourceFile === "platform/src/global-config.d.ts") - await generateGlobalConfigDoc(component); - else if (sourceFile === "platform/src/config.ts") + // Skip - generated into the global-config doc + if (sourceFile.endsWith("/aws/iam-edit.ts")) continue; + else if (sourceFile === "platform/src/global-config.d.ts") { + const iamEditComponent = components.find((c) => + c.sources![0].fileName.endsWith("/aws/iam-edit.ts") + ); + await generateGlobalConfigDoc(component, iamEditComponent!); + } else if (sourceFile === "platform/src/config.ts") await generateConfigDoc(component); else if (sourceFile.endsWith("/dns.ts")) await generateDnsDoc(component); else if ( @@ -462,7 +467,10 @@ async function generateExamplesDocs() { } } -async function generateGlobalConfigDoc(module: TypeDoc.DeclarationReflection) { +async function generateGlobalConfigDoc( + module: TypeDoc.DeclarationReflection, + iamEditComponent: TypeDoc.DeclarationReflection +) { console.info(`Generating Global...`); const outputFilePath = `src/content/docs/docs/reference/global.mdx`; fs.writeFileSync( @@ -477,6 +485,9 @@ async function generateGlobalConfigDoc(module: TypeDoc.DeclarationReflection) { renderFunctions(module, useModuleFunctions(module), { title: "Functions", }), + renderFunctions(module, useModuleFunctions(iamEditComponent), { + title: "AWS", + }), renderBodyEnd(), ] .flat() @@ -2112,6 +2123,7 @@ async function buildComponents() { "../platform/src/components/cloudflare/dns.ts", "../platform/src/components/vercel/dns.ts", "../platform/src/components/aws/cdn.ts", + "../platform/src/components/aws/iam-edit.ts", "../platform/src/components/aws/permission.ts", "../platform/src/components/cloudflare/binding.ts", ],