-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for service account in functions.runWith
#770
Add support for service account in functions.runWith
#770
Conversation
898fb39
to
cacf19c
Compare
@egor-miasnikov thank you for this pull request! All API changes to Firebase SDKs require us to go through an internal API review process, so my apologies in advance this may take a bit longer than expected. @mbleigh do you want to sponsor this one as well? |
@egor-miasnikov thanks for the PR! I'll need to sponsor this through internal API review, which will take a bit of time, but a few things:
This way I can deploy to multiple projects with the same value so long as I've set it to the name of a service account that exists in each project. |
@mbleigh the |
Hey @mbleigh thank you for you comments! point 1 already done, thanks @samtstern ;) Regarding point 2 I propose validate user input by '@' and if ok set as-is otherwise skip input and based on current functionality will be set default service account from the project. Or if we are going to generate email based on name maybe we would like to rename property to 'serviceAccount', what do you think? But I think it will be not so obviously relatively what need to set in it:) |
801177b
to
7e0284b
Compare
@mbleigh Did you have a chance to review this PR? |
@mbleigh @samtstern Could anybody from Firebase Team also look at this PR as well? Has it passed internal API review process? |
Hey @samtstern @mbleigh, any updates with the internal proposal? |
Hey all, sorry for the delay on this, the API review slipped past us for a bit, but it is approved now! There were a few other changes to the API requested, so I'm going to make those this week and do some testing. I'm hoping to get this released sometime later this week if all goes well. Thanks for the contribution and patience! |
src/cloud-functions.ts
Outdated
if (options.serviceAccount) { | ||
if (options.serviceAccount === 'default') { | ||
// Do nothing, since this is equivalent to not setting serviceAccount. | ||
} else if (options.serviceAccount.includes('@')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approved API for this was actually to explicitly put a trailing @
to indicate that it is a named service account for the current project. So the else
should be moved up to an else if
that comes before this something like:
else if (options.serviceAccount.endsWith('@')) {
if (!process.env.GCLOUD_PROJECT) {
throw new Error(
`Unable to determine email for service account '${options.serviceAccount}' because process.env.GCLOUD_PROJECT is not set.`
);
}
trigger.serviceAccountEmail = `${options.serviceAccount}${process.env.GCLOUD_PROJECT}.iam.gserviceaccount.com`;
}
…erros earlier when service account is set to something invalid
@mbleigh Fixed this up and retested all 4 scenarios ('default', 'service-account@', '[email protected]', and 'something-invalid'): the first three work as expected, and the fourth throws an error listing the valid options. PTAL! |
Description
This PR adds support for the service account inside runWith.
My corresponding PR in firebase-tools: #2580
Code sample