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.10.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.11.0
Choose a head ref
  • 4 commits
  • 6 files changed
  • 3 contributors

Commits on Aug 20, 2020

  1. Copy the full SHA
    bc9d8ca View commit details
  2. Verified

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

Commits on Aug 21, 2020

  1. Verified

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

    google-oss-bot committed Aug 21, 2020
    Copy the full SHA
    f9d71aa View commit details
Showing with 96 additions and 8 deletions.
  1. +1 −1 CHANGELOG.md
  2. +1 −1 package.json
  3. +39 −0 spec/function-builder.spec.ts
  4. +11 −0 src/cloud-functions.ts
  5. +25 −6 src/function-builder.ts
  6. +19 −0 src/function-configuration.ts
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Adds support for functions failure policies (#482)
- Adds support for `vpcConnector` and `vpcConnectorEgressSettings` fields in `functions.runWith()`. **Must be used in conjunction with firebase-tools v8.9.0 or higher.** Thanks @pcboy! (#752)
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.10.0",
"version": "3.11.0",
"description": "Firebase SDK for Cloud Functions",
"keywords": [
"firebase",
39 changes: 39 additions & 0 deletions spec/function-builder.spec.ts
Original file line number Diff line number Diff line change
@@ -199,4 +199,43 @@ describe('FunctionBuilder', () => {
} as any);
}).to.throw(Error, 'at least one region');
});

it('should allow a vpcConnector to be set', () => {
const fn = functions
.runWith({
vpcConnector: 'test-connector',
})
.auth.user()
.onCreate((user) => user);

expect(fn.__trigger.vpcConnector).to.equal('test-connector');
});

it('should allow a vpcConnectorEgressSettings to be set', () => {
const fn = functions
.runWith({
vpcConnector: 'test-connector',
vpcConnectorEgressSettings: 'PRIVATE_RANGES_ONLY',
})
.auth.user()
.onCreate((user) => user);

expect(fn.__trigger.vpcConnectorEgressSettings).to.equal(
'PRIVATE_RANGES_ONLY'
);
});

it('should throw an error if user chooses an invalid vpcConnectorEgressSettings', () => {
expect(() => {
return functions.runWith({
vpcConnector: 'test-connector',
vpcConnectorEgressSettings: 'INCORRECT_OPTION',
} as any);
}).to.throw(
Error,
`The only valid vpcConnectorEgressSettings values are: ${functions.VPC_EGRESS_SETTINGS_OPTIONS.join(
','
)}`
);
});
});
11 changes: 11 additions & 0 deletions src/cloud-functions.ts
Original file line number Diff line number Diff line change
@@ -270,6 +270,8 @@ export interface TriggerAnnotated {
regions?: string[];
schedule?: Schedule;
timeout?: string;
vpcConnector?: string;
vpcConnectorEgressSettings?: string;
};
}

@@ -514,5 +516,14 @@ export function optionsToTrigger(options: DeploymentOptions) {
if (options.maxInstances) {
trigger.maxInstances = options.maxInstances;
}

if (options.vpcConnector) {
trigger.vpcConnector = options.vpcConnector;
}

if (options.vpcConnectorEgressSettings) {
trigger.vpcConnectorEgressSettings = options.vpcConnectorEgressSettings;
}

return trigger;
}
31 changes: 25 additions & 6 deletions src/function-builder.ts
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ import {
RuntimeOptions,
SUPPORTED_REGIONS,
VALID_MEMORY_OPTIONS,
VPC_EGRESS_SETTINGS_OPTIONS,
} from './function-configuration';
import * as analytics from './providers/analytics';
import * as auth from './providers/auth';
@@ -66,6 +67,21 @@ function assertRuntimeOptionsValid(runtimeOptions: RuntimeOptions): boolean {
`TimeoutSeconds must be between 0 and ${MAX_TIMEOUT_SECONDS}`
);
}

if (
runtimeOptions.vpcConnectorEgressSettings &&
!_.includes(
VPC_EGRESS_SETTINGS_OPTIONS,
runtimeOptions.vpcConnectorEgressSettings
)
) {
throw new Error(
`The only valid vpcConnectorEgressSettings values are: ${VPC_EGRESS_SETTINGS_OPTIONS.join(
','
)}`
);
}

if (runtimeOptions.failurePolicy !== undefined) {
if (
_.isBoolean(runtimeOptions.failurePolicy) === false &&
@@ -116,13 +132,16 @@ export function region(

/**
* Configure runtime options for the function.
* @param runtimeOptions Object with three optional fields:
* 1. failurePolicy: failure policy of the function, with boolean `true` being
* @param runtimeOptions Object with optional fields:
* 1. memory: amount of memory to allocate to the function, possible values
* are: '128MB', '256MB', '512MB', '1GB', and '2GB'.
* 2. timeoutSeconds: timeout for the function in seconds, possible values are
* 0 to 540.
* 3. failurePolicy: failure policy of the function, with boolean `true` being
* equivalent to providing an empty retry object.
* 2. memory: amount of memory to allocate to the function, with possible
* values being '128MB', '256MB', '512MB', '1GB', and '2GB'.
* 3. timeoutSeconds: timeout for the function in seconds, with possible
* values being 0 to 540.
* 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.
*
* Value must not be null.
*/
19 changes: 19 additions & 0 deletions src/function-configuration.ts
Original file line number Diff line number Diff line change
@@ -44,6 +44,15 @@ export const VALID_MEMORY_OPTIONS = [
'2GB',
] as const;

/**
* List of available options for VpcConnectorEgressSettings.
*/
export const VPC_EGRESS_SETTINGS_OPTIONS = [
'VPC_CONNECTOR_EGRESS_SETTINGS_UNSPECIFIED',
'PRIVATE_RANGES_ONLY',
'ALL_TRAFFIC',
] as const;

/**
* Scheduler retry options. Applies only to scheduled functions.
*/
@@ -91,6 +100,16 @@ export interface RuntimeOptions {
* Max number of actual instances allowed to be running in parallel
*/
maxInstances?: number;

/**
* Connect cloud function to specified VPC connector
*/
vpcConnector?: string;

/**
* Egress settings for VPC connector
*/
vpcConnectorEgressSettings?: typeof VPC_EGRESS_SETTINGS_OPTIONS[number];
}

export interface DeploymentOptions extends RuntimeOptions {