Skip to content

Commit cacf19c

Browse files
Add support for service account in functions.runWith
1 parent 85af5e1 commit cacf19c

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

spec/function-builder.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,17 @@ describe('FunctionBuilder', () => {
238238
)}`
239239
);
240240
});
241+
242+
it('should allow a serviceAccountEmail to be set', () => {
243+
const serviceAccountEmail =
244+
'test-service-account@test.iam.gserviceaccount.com';
245+
const fn = functions
246+
.runWith({
247+
serviceAccountEmail,
248+
})
249+
.auth.user()
250+
.onCreate((user) => user);
251+
252+
expect(fn.__trigger.serviceAccountEmail).to.equal(serviceAccountEmail);
253+
});
241254
});

src/cloud-functions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ export interface TriggerAnnotated {
272272
timeout?: string;
273273
vpcConnector?: string;
274274
vpcConnectorEgressSettings?: string;
275+
serviceAccountEmail?: string;
275276
};
276277
}
277278

@@ -525,5 +526,9 @@ export function optionsToTrigger(options: DeploymentOptions) {
525526
trigger.vpcConnectorEgressSettings = options.vpcConnectorEgressSettings;
526527
}
527528

529+
if (options.serviceAccountEmail) {
530+
trigger.serviceAccountEmail = options.serviceAccountEmail;
531+
}
532+
528533
return trigger;
529534
}

src/function-builder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export function region(
142142
* 4. vpcConnector: id of a VPC connector in same project and region
143143
* 5. vpcConnectorEgressSettings: when a vpcConnector is set, control which
144144
* egress traffic is sent through the vpcConnector.
145+
* 6. serviceAccountEmail: Specific service account for the function
145146
*
146147
* Value must not be null.
147148
*/

src/function-configuration.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ export interface RuntimeOptions {
110110
* Egress settings for VPC connector
111111
*/
112112
vpcConnectorEgressSettings?: typeof VPC_EGRESS_SETTINGS_OPTIONS[number];
113+
114+
/**
115+
* Specific service account
116+
*/
117+
serviceAccountEmail?: string;
113118
}
114119

115120
export interface DeploymentOptions extends RuntimeOptions {

0 commit comments

Comments
 (0)