@pattform/api-kit 2.9.1 → 3.0.0
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/README.md +3 -1
- package/dist/pattformHelper.d.ts +3 -3
- package/dist/pattformHelper.js +23 -37
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -111,7 +111,9 @@ const app = new AppComponent("app", {
|
|
|
111
111
|
});
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
Reads `/pattform/<client>/aws-deploy-role-arn` from SSM in the management account, which `pattform-infrastructure` publishes for every client in its registry. `getClientGcpDeploySa` reads `/pattform/<client>/gcp-deploy-sa` the same way. Both fail with a clear error if the parameter is missing. The stack's default AWS provider must point at the management account in `ap-southeast-2`.
|
|
115
|
+
|
|
116
|
+
Since 3.0.0 these no longer use a StackReference, so they work whichever backend the infrastructure stack's state lives in. The 2.x optional `infrastructureStack` argument is gone.
|
|
115
117
|
|
|
116
118
|
Notes:
|
|
117
119
|
* The account resource is `protect: true` and `closeOnDeletion: false` - a `pulumi destroy` will not close a client's AWS account.
|
package/dist/pattformHelper.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as pulumi from "@pulumi/pulumi";
|
|
2
2
|
import * as gcp from "@pulumi/gcp";
|
|
3
|
-
export declare function getClientRoleArn(client: string
|
|
4
|
-
export declare function getClientGcpDeploySa(client: string
|
|
5
|
-
export declare function getClientGcpProvider(client: string
|
|
3
|
+
export declare function getClientRoleArn(client: string): pulumi.Output<string>;
|
|
4
|
+
export declare function getClientGcpDeploySa(client: string): pulumi.Output<string>;
|
|
5
|
+
export declare function getClientGcpProvider(client: string): gcp.Provider;
|
|
6
6
|
export declare function verifyRegion(awsRegion: string): any;
|
package/dist/pattformHelper.js
CHANGED
|
@@ -4,43 +4,29 @@ exports.verifyRegion = exports.getClientGcpProvider = exports.getClientGcpDeploy
|
|
|
4
4
|
const pulumi = require("@pulumi/pulumi");
|
|
5
5
|
const aws = require("@pulumi/aws");
|
|
6
6
|
const gcp = require("@pulumi/gcp");
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
//
|
|
7
|
+
// Client deploy identities are published to SSM in the management account by
|
|
8
|
+
// pattform-infrastructure (/pattform/<client>/...). Reading SSM instead of a
|
|
9
|
+
// StackReference means no stack depends on where the infra stack's state
|
|
10
|
+
// lives. The read uses the stack's default AWS provider, which must point at
|
|
11
|
+
// the management account in ap-southeast-2 (the base identity every stack
|
|
12
|
+
// starts from).
|
|
13
|
+
function readClientParameter(client, key, hint) {
|
|
14
|
+
const name = `/pattform/${client}/${key}`;
|
|
15
|
+
return pulumi.output(aws.ssm.getParameter({ name }).catch(err => {
|
|
16
|
+
throw new Error(`Client "${client}" has no ${name} in SSM. ${hint} (${err})`);
|
|
17
|
+
})).apply(parameter => parameter.value);
|
|
18
|
+
}
|
|
19
|
+
// Looks up a client's deploy role. Pass the result straight to
|
|
20
|
+
// AppComponent's roleArn:
|
|
13
21
|
// roleArn: getClientRoleArn("kaloblock")
|
|
14
|
-
function getClientRoleArn(client
|
|
15
|
-
|
|
16
|
-
stackReferences[infrastructureStack] = new pulumi.StackReference(infrastructureStack);
|
|
17
|
-
}
|
|
18
|
-
return stackReferences[infrastructureStack].requireOutput("clientDeployRoleArns").apply(roles => {
|
|
19
|
-
const arn = roles[client];
|
|
20
|
-
if (!arn) {
|
|
21
|
-
const known = Object.keys(roles).join(", ") || "<none>";
|
|
22
|
-
throw new Error(`Client "${client}" has no deploy role in ${infrastructureStack} (known clients: ${known}). ` +
|
|
23
|
-
`Add it to the clients registry in pattform-infrastructure and deploy that stack first.`);
|
|
24
|
-
}
|
|
25
|
-
return arn;
|
|
26
|
-
});
|
|
22
|
+
function getClientRoleArn(client) {
|
|
23
|
+
return readClientParameter(client, "aws-deploy-role-arn", "Add it to the clients registry in pattform-infrastructure and deploy that stack first.");
|
|
27
24
|
}
|
|
28
25
|
exports.getClientRoleArn = getClientRoleArn;
|
|
29
|
-
// Looks up a client's GCP deploy service account
|
|
30
|
-
//
|
|
31
|
-
function getClientGcpDeploySa(client
|
|
32
|
-
|
|
33
|
-
stackReferences[infrastructureStack] = new pulumi.StackReference(infrastructureStack);
|
|
34
|
-
}
|
|
35
|
-
return stackReferences[infrastructureStack].requireOutput("clientGcpDeploySas").apply(sas => {
|
|
36
|
-
const sa = sas[client];
|
|
37
|
-
if (!sa) {
|
|
38
|
-
const known = Object.keys(sas).join(", ") || "<none>";
|
|
39
|
-
throw new Error(`Client "${client}" has no GCP deploy service account in ${infrastructureStack} (known clients: ${known}). ` +
|
|
40
|
-
`Add a GcpProjectComponent for it in pattform-infrastructure and deploy that stack first.`);
|
|
41
|
-
}
|
|
42
|
-
return sa;
|
|
43
|
-
});
|
|
26
|
+
// Looks up a client's GCP deploy service account (GCP analog of
|
|
27
|
+
// getClientRoleArn).
|
|
28
|
+
function getClientGcpDeploySa(client) {
|
|
29
|
+
return readClientParameter(client, "gcp-deploy-sa", "Vend a GCP project for it in pattform-infrastructure and deploy that stack first.");
|
|
44
30
|
}
|
|
45
31
|
exports.getClientGcpDeploySa = getClientGcpDeploySa;
|
|
46
32
|
// Providers are resources; memoise so a program can call this repeatedly.
|
|
@@ -51,8 +37,8 @@ const gcpProviders = {};
|
|
|
51
37
|
// resources/components:
|
|
52
38
|
// const gcpProvider = getClientGcpProvider(client);
|
|
53
39
|
// new ContainerComponent(name, args, { providers: [gcpProvider] });
|
|
54
|
-
function getClientGcpProvider(client
|
|
55
|
-
const key =
|
|
40
|
+
function getClientGcpProvider(client) {
|
|
41
|
+
const key = client;
|
|
56
42
|
if (!gcpProviders[key]) {
|
|
57
43
|
const gcpConfig = new pulumi.Config("gcp");
|
|
58
44
|
gcpProviders[key] = new gcp.Provider(`pattform-gcp-${client}`, {
|
|
@@ -62,7 +48,7 @@ function getClientGcpProvider(client, infrastructureStack = DEFAULT_INFRASTRUCTU
|
|
|
62
48
|
accessToken: gcpConfig.get("accessToken"),
|
|
63
49
|
project: gcpConfig.get("project"),
|
|
64
50
|
region: gcpConfig.get("region"),
|
|
65
|
-
impersonateServiceAccount: getClientGcpDeploySa(client
|
|
51
|
+
impersonateServiceAccount: getClientGcpDeploySa(client),
|
|
66
52
|
});
|
|
67
53
|
}
|
|
68
54
|
return gcpProviders[key];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pattform/api-kit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Pulumi infra library for building and deploying an API",
|
|
5
5
|
"author": "Pattform <contact@pattform.io>",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/Pattform/
|
|
21
|
+
"url": "git+https://github.com/Pattform/pattform-api-kit.git"
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
24
|
"test": "echo \"Error: no test specified\"",
|