Skip to content

Fix IngressSettings support #827

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

Merged
merged 2 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions spec/function-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,27 @@ describe('FunctionBuilder', () => {
}).to.throw(Error, 'at least one region');
});

it('should allow a ingressSettings to be set', () => {
const fn = functions
.runWith({ ingressSettings: 'ALLOW_INTERNAL_ONLY' })
.https.onRequest(() => {});

expect(fn.__trigger.ingressSettings).to.equal('ALLOW_INTERNAL_ONLY');
});

it('should throw an error if user chooses an invalid ingressSettings', () => {
expect(() => {
return functions.runWith({
ingressSettings: 'INVALID_OPTION',
} as any);
}).to.throw(
Error,
`The only valid ingressSettings values are: ${functions.INGRESS_SETTINGS_OPTIONS.join(
','
)}`
);
});

it('should allow a vpcConnector to be set', () => {
const fn = functions
.runWith({
Expand Down
5 changes: 5 additions & 0 deletions src/cloud-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ export interface TriggerAnnotated {
vpcConnector?: string;
vpcConnectorEgressSettings?: string;
serviceAccountEmail?: string;
ingressSettings?: string;
};
}

Expand Down Expand Up @@ -519,6 +520,10 @@ export function optionsToTrigger(options: DeploymentOptions) {
trigger.maxInstances = options.maxInstances;
}

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

if (options.vpcConnector) {
trigger.vpcConnector = options.vpcConnector;
}
Expand Down
12 changes: 12 additions & 0 deletions src/function-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
SUPPORTED_REGIONS,
VALID_MEMORY_OPTIONS,
VPC_EGRESS_SETTINGS_OPTIONS,
INGRESS_SETTINGS_OPTIONS,
} from './function-configuration';
import * as analytics from './providers/analytics';
import * as auth from './providers/auth';
Expand Down Expand Up @@ -68,6 +69,17 @@ function assertRuntimeOptionsValid(runtimeOptions: RuntimeOptions): boolean {
);
}

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

if (
runtimeOptions.vpcConnectorEgressSettings &&
!_.includes(
Expand Down