Skip to content

Commit c4c1241

Browse files
authored
Merge pull request #8 from wesreid/feature/gh-oidc-setup-utility
add utility script to deploy the Github OIDC stack in an AWS account
2 parents d4a9da7 + b8358f1 commit c4c1241

File tree

7 files changed

+77
-25
lines changed

7 files changed

+77
-25
lines changed

bin/bootstrap-iam.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/cli.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "dist/index.js",
66
"bin": {
77
"generate-oas": "./bin/generate-swagger.js",
8-
"gh-oidc-iam": "./bin/bootstrap-iam.js"
8+
"aws-lambda-api-tools": "./bin/cli.js",
9+
"create-gha-iam-stack": "./bin/bootstrap-iam.js"
910
},
1011
"types": "dist/index.d.ts",
1112
"scripts": {
@@ -49,9 +50,10 @@
4950
"@types/minimist": "^1.2.2",
5051
"@types/node-fetch": "^2.5.12",
5152
"atob": "^2.1.2",
52-
"aws-cdk": "^2.178.2",
53+
"aws-cdk": "^2.0.0",
5354
"aws-cdk-lib": "^2.0.0",
5455
"axios": "^1.6.3",
56+
"commander": "^11.1.0",
5557
"joi": "^17.12.3",
5658
"joi-to-swagger": "6.2.0",
5759
"joi-to-typescript": "^4.11.0",

scripts/build-binaries.ts

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
import { build } from 'esbuild';
2-
import { chmod, writeFile } from 'fs/promises';
2+
import { chmod } from 'fs/promises';
33
import { join } from 'path';
44

55
async function buildBinary() {
6-
const outFile = join(process.cwd(), 'bin/bootstrap-iam.js');
7-
8-
await build({
9-
entryPoints: ['src/bin/bootstrap-iam.ts'],
10-
bundle: true,
11-
platform: 'node',
12-
target: 'node16',
13-
outfile: outFile,
14-
format: 'cjs',
15-
minify: true,
16-
sourcemap: false,
17-
external: ['aws-cdk-lib', 'aws-cdk-lib/*'],
18-
banner: {
19-
js: '#!/usr/bin/env node',
6+
const files = [
7+
{
8+
entry: 'src/bin/bootstrap-iam.ts',
9+
out: 'bin/bootstrap-iam.js'
2010
},
21-
});
11+
{
12+
entry: 'src/bin/cli.ts',
13+
out: 'bin/cli.js'
14+
}
15+
];
2216

23-
await chmod(outFile, '755');
17+
for (const file of files) {
18+
const outFile = join(process.cwd(), file.out);
19+
20+
await build({
21+
entryPoints: [file.entry],
22+
bundle: true,
23+
platform: 'node',
24+
target: 'node16',
25+
outfile: outFile,
26+
format: 'cjs',
27+
minify: true,
28+
sourcemap: false,
29+
external: ['aws-cdk-lib', 'aws-cdk-lib/*', 'aws-cdk', 'commander'],
30+
banner: {
31+
js: '#!/usr/bin/env node',
32+
},
33+
});
34+
35+
await chmod(outFile, '755');
36+
}
2437
}
2538

2639
buildBinary().catch((err) => {

src/bin/bootstrap-iam.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const policyArg = args.find(t => t.startsWith("--policy="));
1212

1313
if (!repoArg) {
1414
console.error("Error: --repo argument is required");
15-
console.error("Usage: gh-oidc-iam --repo=owner/repo-name [--policy=PolicyName]");
16-
console.error("Example: gh-oidc-iam --repo=myorg/my-repo --policy=AdministratorAccess");
15+
console.error("Usage: create-gha-iam-stack --repo=owner/repo-name [--policy=PolicyName]");
16+
console.error("Example: create-gha-iam-stack --repo=myorg/my-repo --policy=AdministratorAccess");
1717
process.exit(1);
1818
}
1919

src/bin/cli.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env node
2+
import { program } from 'commander';
3+
import { join } from 'path';
4+
5+
program
6+
.name('aws-lambda-api-tools')
7+
.description('CLI tools for AWS Lambda and API Gateway')
8+
.version('0.1.5');
9+
10+
program.command('create-gha-iam-stack')
11+
.description('Create IAM stack for GitHub Actions OIDC authentication')
12+
.requiredOption('--repo <owner/repo>', 'GitHub repository (owner/repo)')
13+
.option('--policy <name>', 'AWS managed policy name', 'AdministratorAccess')
14+
.action(async (options) => {
15+
process.argv = [
16+
process.argv[0],
17+
process.argv[1],
18+
`--repo=${options.repo}`,
19+
`--policy=${options.policy}`
20+
];
21+
require(join(__dirname, 'bootstrap-iam.js'));
22+
});
23+
24+
program.parse();

0 commit comments

Comments
 (0)