@@ -43,6 +43,12 @@ export class NitricApiGcpApiGateway extends pulumi.ComponentResource {
43
43
public readonly hostname : pulumi . Output < string > ;
44
44
public readonly url : pulumi . Output < string > ;
45
45
46
+ public readonly api : gcp . apigateway . Api ;
47
+ public readonly config : gcp . apigateway . ApiConfig ;
48
+ public readonly gateway : gcp . apigateway . Gateway ;
49
+ public readonly invoker : gcp . serviceaccount . Account ;
50
+ public readonly memberships : gcp . cloudrun . IamMember [ ] ;
51
+
46
52
constructor ( name : string , args : NitricApiGcpApiGatewayArgs , opts ?: pulumi . ComponentResourceOptions ) {
47
53
super ( 'nitric:api:GcpApiGateway' , name , { } , opts ) ;
48
54
const { api, services } = args ;
@@ -54,7 +60,7 @@ export class NitricApiGcpApiGateway extends pulumi.ComponentResource {
54
60
const targetServices = Object . keys ( api . paths ) . reduce ( ( svcs , path ) => {
55
61
const p = api . paths [ path ] as OpenAPIV2 . PathItemObject < NitricAPITarget > ;
56
62
57
- const services = Object . keys ( path )
63
+ const s = Object . keys ( p )
58
64
. filter ( ( k ) => METHOD_KEYS . includes ( k as method ) )
59
65
. reduce ( ( acc , method ) => {
60
66
const pathTarget = p [ method as method ] ?. [ constants . OAI_NITRIC_TARGET_EXT ] ;
@@ -67,7 +73,7 @@ export class NitricApiGcpApiGateway extends pulumi.ComponentResource {
67
73
return acc ;
68
74
} , svcs ) ;
69
75
70
- return svcs ;
76
+ return s ;
71
77
} , [ ] as NitricComputeCloudRun [ ] ) ;
72
78
73
79
// Replace Nitric API Extensions with google api gateway extensions
@@ -131,7 +137,7 @@ export class NitricApiGcpApiGateway extends pulumi.ComponentResource {
131
137
return Buffer . from ( JSON . stringify ( transformedApi ) ) . toString ( 'base64' ) ;
132
138
} ) ;
133
139
134
- const deployedApi = new gcp . apigateway . Api (
140
+ this . api = new gcp . apigateway . Api (
135
141
name ,
136
142
{
137
143
apiId : name ,
@@ -140,7 +146,7 @@ export class NitricApiGcpApiGateway extends pulumi.ComponentResource {
140
146
) ;
141
147
142
148
// Create a new IAM account for invoking
143
- const apiInvoker = new gcp . serviceaccount . Account (
149
+ this . invoker = new gcp . serviceaccount . Account (
144
150
`${ name } -acct` ,
145
151
{
146
152
// Limit to 30 characters for service account name
@@ -151,13 +157,13 @@ export class NitricApiGcpApiGateway extends pulumi.ComponentResource {
151
157
) ;
152
158
153
159
// Bind that IAM account as a member of all available service targets
154
- targetServices . map ( ( svc ) => {
155
- new gcp . cloudrun . IamMember (
156
- `${ name } -acct -binding` ,
160
+ this . memberships = targetServices . map ( ( svc ) => {
161
+ return new gcp . cloudrun . IamMember (
162
+ `${ name } -${ svc . name } -binding` ,
157
163
{
158
164
service : svc . cloudrun . name ,
159
165
location : svc . cloudrun . location ,
160
- member : pulumi . interpolate `serviceAccount:${ apiInvoker . email } ` ,
166
+ member : pulumi . interpolate `serviceAccount:${ this . invoker . email } ` ,
161
167
role : 'roles/run.invoker' ,
162
168
} ,
163
169
defaultResourceOptions ,
@@ -167,10 +173,10 @@ export class NitricApiGcpApiGateway extends pulumi.ComponentResource {
167
173
// Now we need to create the document provided and interpolate the deployed service targets
168
174
// i.e. their Urls...
169
175
// Deploy the config
170
- const deployedConfig = new gcp . apigateway . ApiConfig (
176
+ this . config = new gcp . apigateway . ApiConfig (
171
177
`${ name } -config` ,
172
178
{
173
- api : deployedApi . apiId ,
179
+ api : this . api . apiId ,
174
180
displayName : `${ name } -config` ,
175
181
apiConfigId : `${ name } -config` ,
176
182
openapiDocuments : [
@@ -184,31 +190,36 @@ export class NitricApiGcpApiGateway extends pulumi.ComponentResource {
184
190
gatewayConfig : {
185
191
backendConfig : {
186
192
// Add the service account for the invoker here...
187
- googleServiceAccount : apiInvoker . email ,
193
+ googleServiceAccount : this . invoker . email ,
188
194
} ,
189
195
} ,
190
196
} ,
191
197
defaultResourceOptions ,
192
198
) ;
193
199
194
200
// Deploy the gateway
195
- const gateway = new gcp . apigateway . Gateway (
201
+ this . gateway = new gcp . apigateway . Gateway (
196
202
`${ name } -gateway` ,
197
203
{
198
204
displayName : `${ name } -gateway` ,
199
205
gatewayId : `${ name } -gateway` ,
200
- apiConfig : deployedConfig . id ,
206
+ apiConfig : this . config . id ,
201
207
} ,
202
208
defaultResourceOptions ,
203
209
) ;
204
210
205
- this . hostname = gateway . defaultHostname ;
206
- this . url = gateway . defaultHostname . apply ( ( n ) => `https://${ n } ` ) ;
211
+ this . hostname = this . gateway . defaultHostname ;
212
+ this . url = this . gateway . defaultHostname . apply ( ( n ) => `https://${ n } ` ) ;
207
213
208
214
this . registerOutputs ( {
209
215
name : this . name ,
210
216
hostname : this . hostname ,
211
217
url : this . url ,
218
+ api : this . api ,
219
+ invoker : this . invoker ,
220
+ memberships : this . memberships ,
221
+ config : this . config ,
222
+ gateway : this . gateway ,
212
223
} ) ;
213
224
}
214
225
0 commit comments