Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: firebase/firebase-functions
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.12.0
Choose a base ref
...
head repository: firebase/firebase-functions
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.13.0
Choose a head ref
  • 5 commits
  • 7 files changed
  • 5 contributors

Commits on Nov 30, 2020

  1. Copy the full SHA
    9055e0f View commit details

Commits on Dec 7, 2020

  1. Add support for service account in functions.runWith (#770)

    * Add support for service account in `functions.runWith`
    
    * Add email validation and email generation by project id
    
    * Changing to serviceAccount, and adding default as an option
    
    * adds a test case for default
    
    * refactoring to checxk for @ at the end of service account, and throw erros earlier when service account is set to something invalid
    
    * gets rid of repeated @ for generated service account emails
    
    Co-authored-by: joehan <joehanley@google.com>
    egor-miasnikov and joehan authored Dec 7, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    07139c8 View commit details
  2. Bump highlight.js from 10.2.0 to 10.4.1 (#823)

    Bumps [highlight.js](https://github.com/highlightjs/highlight.js) from 10.2.0 to 10.4.1.
    - [Release notes](https://github.com/highlightjs/highlight.js/releases)
    - [Changelog](https://github.com/highlightjs/highlight.js/blob/master/CHANGES.md)
    - [Commits](highlightjs/highlight.js@10.2.0...10.4.1)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: joehan <joehanley@google.com>
    dependabot[bot] and joehan authored Dec 7, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    07ca97f View commit details
  3. Adds changelog entries for v3.13.0 (#824)

    * adds changelog entries for 3.13.0
    
    * formats
    
    * Update CHANGELOG.md
    
    Co-authored-by: Sam Stern <samstern@google.com>
    
    * Update CHANGELOG.md
    
    Co-authored-by: Sam Stern <samstern@google.com>
    
    * Update CHANGELOG.md
    
    Co-authored-by: Sam Stern <samstern@google.com>
    
    * formats
    
    * formats
    
    Co-authored-by: Sam Stern <samstern@google.com>
    joehan and samtstern authored Dec 7, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    df59271 View commit details
  4. 3.13.0

    google-oss-bot committed Dec 7, 2020
    Copy the full SHA
    21d2c0b View commit details
Showing with 112 additions and 10 deletions.
  1. +18 −2 CHANGELOG.md
  2. +4 −4 package-lock.json
  3. +1 −1 package.json
  4. +48 −0 spec/function-builder.spec.ts
  5. +20 −0 src/cloud-functions.ts
  6. +16 −3 src/function-builder.ts
  7. +5 −0 src/function-configuration.ts
20 changes: 18 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
- Adds `4GB` as a `memory` option for `runWith()`.
- Adds support for choosing `ingressSettings` via `runWith()`.
- Adds `serviceAccount` option to `runtimeOptions` to specify which service account Cloud Function should use at runtime. For example:

```
const functions = require('firebase-functions');
exports.myFunction = functions.runWith({
serviceAccount: 'test-sa@project.iam.gserviceaccount.com'
// OR
// serviceAcount: 'test-sa@"
// OR
// serviceAccount: 'default'
})
```

Requires firebase-tools@8.18.0 or later. Thanks @egor-miasnikov!

- Upgrades `highlight.js` to `10.4.1` to fix a vulnerability.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firebase-functions",
"version": "3.12.0",
"version": "3.13.0",
"description": "Firebase SDK for Cloud Functions",
"keywords": [
"firebase",
48 changes: 48 additions & 0 deletions spec/function-builder.spec.ts
Original file line number Diff line number Diff line change
@@ -238,4 +238,52 @@ describe('FunctionBuilder', () => {
)}`
);
});

it('should allow a serviceAccount to be set as-is', () => {
const serviceAccount = 'test-service-account@test.iam.gserviceaccount.com';
const fn = functions
.runWith({
serviceAccount,
})
.auth.user()
.onCreate((user) => user);

expect(fn.__trigger.serviceAccountEmail).to.equal(serviceAccount);
});

it('should allow a serviceAccount to be set with generated service account email', () => {
const serviceAccount = 'test-service-account@';
const projectId = process.env.GCLOUD_PROJECT;
const fn = functions
.runWith({
serviceAccount,
})
.auth.user()
.onCreate((user) => user);

expect(fn.__trigger.serviceAccountEmail).to.equal(
`test-service-account@${projectId}.iam.gserviceaccount.com`
);
});

it('should not set a serviceAccountEmail if service account is set to `default`', () => {
const serviceAccount = 'default';
const fn = functions
.runWith({
serviceAccount,
})
.auth.user()
.onCreate((user) => user);

expect(fn.__trigger.serviceAccountEmail).to.be.undefined;
});

it('should throw an error if serviceAccount is set to an invalid value', () => {
const serviceAccount = 'test-service-account';
expect(() => {
functions.runWith({
serviceAccount,
});
}).to.throw();
});
});
20 changes: 20 additions & 0 deletions src/cloud-functions.ts
Original file line number Diff line number Diff line change
@@ -272,6 +272,7 @@ export interface TriggerAnnotated {
timeout?: string;
vpcConnector?: string;
vpcConnectorEgressSettings?: string;
serviceAccountEmail?: string;
};
}

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

if (options.serviceAccount) {
if (options.serviceAccount === 'default') {
// Do nothing, since this is equivalent to not setting serviceAccount.
} 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`;
} else if (options.serviceAccount.includes('@')) {
trigger.serviceAccountEmail = options.serviceAccount;
} else {
throw new Error(
`Invalid option for serviceAccount: '${options.serviceAccount}'. Valid options are 'default', a service account email, or '{serviceAccountName}@'`
);
}
}

return trigger;
}
19 changes: 16 additions & 3 deletions src/function-builder.ts
Original file line number Diff line number Diff line change
@@ -99,6 +99,16 @@ function assertRuntimeOptionsValid(runtimeOptions: RuntimeOptions): boolean {
}
}
}

if (
runtimeOptions.serviceAccount &&
runtimeOptions.serviceAccount !== 'default' &&
!_.includes(runtimeOptions.serviceAccount, '@')
) {
throw new Error(
`serviceAccount must be set to 'default', a service account email, or '{serviceAccountName}@'`
);
}
return true;
}

@@ -139,9 +149,12 @@ export function region(
* 0 to 540.
* 3. `failurePolicy`: failure policy of the function, with boolean `true` being
* equivalent to providing an empty retry object.
* 4. `vpcConnector`: id of a VPC connector in the same project and region
* 5. `vpcConnectorEgressSettings`: when a `vpcConnector` is set, control which
* egress traffic is sent through the `vpcConnector`.
* 4. `vpcConnector`: id of a VPC connector in same project and region.
* 5. `vpcConnectorEgressSettings`: when a vpcConnector is set, control which
* egress traffic is sent through the vpcConnector.
* 6. `serviceAccount`: Specific service account for the function.
* 7. `ingressSettings`: ingress settings for the function, which control where a HTTPS
* function can be called from.
*
* Value must not be null.
*/
5 changes: 5 additions & 0 deletions src/function-configuration.ts
Original file line number Diff line number Diff line change
@@ -122,6 +122,11 @@ export interface RuntimeOptions {
*/
vpcConnectorEgressSettings?: typeof VPC_EGRESS_SETTINGS_OPTIONS[number];

/**
* Specific service account for the function to run as
*/
serviceAccount?: 'default' | string;

/**
* Ingress settings
*/