-
Notifications
You must be signed in to change notification settings - Fork 3
/
integ.default.ts
54 lines (49 loc) · 1.77 KB
/
integ.default.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { App, Stack } from "aws-cdk-lib";
import * as secrets_manager from "aws-cdk-lib/aws-secretsmanager";
import * as custom_resources from "aws-cdk-lib/custom-resources";
import { AuthOptions } from "./auth";
import { GithubCustomResource } from "./github-custom-resource";
// https://github.com/octokit/authentication-strategies.js/#the-authoptionsfactory-pattern
// export REPO=
// yarn bundle:custom-resource-provider/handler.lambda
// npx cdk deploy --app 'npx ts-node -P tsconfig.json --prefer-ts-exts ./src/integ.default.ts' --require-approval never --no-rollback
const app = new App();
const stack = new Stack(app, "GithubCustomResource");
const repo = process.env.REPO ?? "cdk-github";
const secret = secrets_manager.Secret.fromSecretNameV2(stack, "Auth", "cdk-github/test");
new GithubCustomResource(stack, "GithubRepo", {
onCreate: {
// https://octokit.github.io/rest.js/v19/#repos-create-in-org
endpoint: "repos",
method: "createInOrg",
parameters: {
org: "pepperize",
name: repo,
},
outputPaths: ["id", "full_name"],
physicalResourceId: custom_resources.PhysicalResourceId.fromResponse("full_name"),
ignoreErrorCodesMatching: "name already exists on this account",
},
onUpdate: {
// https://octokit.github.io/rest.js/v19#repos-get
endpoint: "repos",
method: "get",
parameters: {
owner: "pepperize",
repo,
},
outputPaths: ["id", "full_name"],
physicalResourceId: custom_resources.PhysicalResourceId.fromResponse("full_name"),
},
onDelete: {
// https://octokit.github.io/rest.js/v19#repos-delete
endpoint: "repos",
method: "get", // method: "delete",
parameters: {
owner: "pepperize",
repo,
},
outputPaths: [],
},
authOptions: AuthOptions.appAuth(secret),
});