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

Commit

Permalink
Docs: sst.aws.iamEdit
Browse files Browse the repository at this point in the history
  • Loading branch information
fwang committed Oct 15, 2024
1 parent 25349a9 commit 96eccab
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
26 changes: 26 additions & 0 deletions platform/src/components/aws/iam-edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,32 @@ type PartialUnwrappedPolicyDocument = {
Statement: Input<iam.PolicyStatement>[];
};

/**
* 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<iam.PolicyDocument | string>,
cb: (doc: Prettify<PartialUnwrappedPolicyDocument>) => void,
Expand Down
20 changes: 16 additions & 4 deletions www/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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(
Expand All @@ -477,6 +485,9 @@ async function generateGlobalConfigDoc(module: TypeDoc.DeclarationReflection) {
renderFunctions(module, useModuleFunctions(module), {
title: "Functions",
}),
renderFunctions(module, useModuleFunctions(iamEditComponent), {
title: "AWS",
}),
renderBodyEnd(),
]
.flat()
Expand Down Expand Up @@ -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",
],
Expand Down

0 comments on commit 96eccab

Please sign in to comment.