@pattform/api-kit 2.6.1 → 2.6.2
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/dist/index.d.ts +1 -1
- package/dist/index.js +3 -1
- package/dist/pattformHelper.d.ts +3 -0
- package/dist/pattformHelper.js +44 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export { AppComponent, AppComponentArgs, DnsRecordInstruction } from "./AppCompo
|
|
|
4
4
|
export { ClientAccountComponent, ClientAccountComponentArgs } from "./ClientAccountComponent";
|
|
5
5
|
export { GcpProjectComponent, GcpProjectComponentArgs } from "./GcpProjectComponent";
|
|
6
6
|
export { FormComponent, FormComponentArgs, FormFieldSpec, FormDestination } from "./FormComponent";
|
|
7
|
-
export { getClientRoleArn } from "./pattformHelper";
|
|
7
|
+
export { getClientRoleArn, getClientGcpDeploySa, getClientGcpProvider } from "./pattformHelper";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getClientRoleArn = exports.FormComponent = exports.GcpProjectComponent = exports.ClientAccountComponent = exports.AppComponent = exports.ApiComponent = exports.ContainerComponent = void 0;
|
|
3
|
+
exports.getClientGcpProvider = exports.getClientGcpDeploySa = exports.getClientRoleArn = exports.FormComponent = exports.GcpProjectComponent = exports.ClientAccountComponent = exports.AppComponent = exports.ApiComponent = exports.ContainerComponent = void 0;
|
|
4
4
|
var ContainerComponent_1 = require("./ContainerComponent");
|
|
5
5
|
Object.defineProperty(exports, "ContainerComponent", { enumerable: true, get: function () { return ContainerComponent_1.ContainerComponent; } });
|
|
6
6
|
var ApiComponent_1 = require("./ApiComponent");
|
|
@@ -15,3 +15,5 @@ var FormComponent_1 = require("./FormComponent");
|
|
|
15
15
|
Object.defineProperty(exports, "FormComponent", { enumerable: true, get: function () { return FormComponent_1.FormComponent; } });
|
|
16
16
|
var pattformHelper_1 = require("./pattformHelper");
|
|
17
17
|
Object.defineProperty(exports, "getClientRoleArn", { enumerable: true, get: function () { return pattformHelper_1.getClientRoleArn; } });
|
|
18
|
+
Object.defineProperty(exports, "getClientGcpDeploySa", { enumerable: true, get: function () { return pattformHelper_1.getClientGcpDeploySa; } });
|
|
19
|
+
Object.defineProperty(exports, "getClientGcpProvider", { enumerable: true, get: function () { return pattformHelper_1.getClientGcpProvider; } });
|
package/dist/pattformHelper.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import * as pulumi from "@pulumi/pulumi";
|
|
2
|
+
import * as gcp from "@pulumi/gcp";
|
|
2
3
|
export declare function getClientRoleArn(client: string, infrastructureStack?: string): pulumi.Output<string>;
|
|
4
|
+
export declare function getClientGcpDeploySa(client: string, infrastructureStack?: string): pulumi.Output<string>;
|
|
5
|
+
export declare function getClientGcpProvider(client: string, infrastructureStack?: string): gcp.Provider;
|
|
3
6
|
export declare function verifyRegion(awsRegion: string): any;
|
package/dist/pattformHelper.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.verifyRegion = exports.getClientRoleArn = void 0;
|
|
3
|
+
exports.verifyRegion = exports.getClientGcpProvider = exports.getClientGcpDeploySa = exports.getClientRoleArn = void 0;
|
|
4
4
|
const pulumi = require("@pulumi/pulumi");
|
|
5
5
|
const aws = require("@pulumi/aws");
|
|
6
|
+
const gcp = require("@pulumi/gcp");
|
|
6
7
|
const DEFAULT_INFRASTRUCTURE_STACK = "Pattform/pattform-infrastructure/prod";
|
|
7
8
|
// StackReferences are resources, so creating the same one twice in a program
|
|
8
9
|
// would collide on its URN; memoise per stack name.
|
|
@@ -25,6 +26,48 @@ function getClientRoleArn(client, infrastructureStack = DEFAULT_INFRASTRUCTURE_S
|
|
|
25
26
|
});
|
|
26
27
|
}
|
|
27
28
|
exports.getClientRoleArn = getClientRoleArn;
|
|
29
|
+
// Looks up a client's GCP deploy service account from the
|
|
30
|
+
// pattform-infrastructure stack (GCP analog of getClientRoleArn).
|
|
31
|
+
function getClientGcpDeploySa(client, infrastructureStack = DEFAULT_INFRASTRUCTURE_STACK) {
|
|
32
|
+
if (!stackReferences[infrastructureStack]) {
|
|
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
|
+
});
|
|
44
|
+
}
|
|
45
|
+
exports.getClientGcpDeploySa = getClientGcpDeploySa;
|
|
46
|
+
// Providers are resources; memoise so a program can call this repeatedly.
|
|
47
|
+
const gcpProviders = {};
|
|
48
|
+
// GCP provider that deploys as the client's deploy SA: the base identity from
|
|
49
|
+
// the shared Common gcp-login impersonates deploy@<project>, mirroring the
|
|
50
|
+
// assume-role hop AWS components make with getClientRoleArn. Pass it to GCP
|
|
51
|
+
// resources/components:
|
|
52
|
+
// const gcpProvider = getClientGcpProvider(client);
|
|
53
|
+
// new ContainerComponent(name, args, { providers: [gcpProvider] });
|
|
54
|
+
function getClientGcpProvider(client, infrastructureStack = DEFAULT_INFRASTRUCTURE_STACK) {
|
|
55
|
+
const key = `${infrastructureStack}/${client}`;
|
|
56
|
+
if (!gcpProviders[key]) {
|
|
57
|
+
const gcpConfig = new pulumi.Config("gcp");
|
|
58
|
+
gcpProviders[key] = new gcp.Provider(`pattform-gcp-${client}`, {
|
|
59
|
+
// Explicit providers do not inherit gcp:* stack config (same trap
|
|
60
|
+
// as aws:accessKey on explicit AWS providers), so the base token
|
|
61
|
+
// performing the impersonation must be passed through.
|
|
62
|
+
accessToken: gcpConfig.get("accessToken"),
|
|
63
|
+
project: gcpConfig.get("project"),
|
|
64
|
+
region: gcpConfig.get("region"),
|
|
65
|
+
impersonateServiceAccount: getClientGcpDeploySa(client, infrastructureStack),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return gcpProviders[key];
|
|
69
|
+
}
|
|
70
|
+
exports.getClientGcpProvider = getClientGcpProvider;
|
|
28
71
|
function verifyRegion(awsRegion) {
|
|
29
72
|
for (const [key, value] of Object.entries(aws.Region)) {
|
|
30
73
|
if (value == awsRegion) {
|