Skip to content

Commit bf0df0f

Browse files
committed
PR feedback RE error checking
1 parent 40f0498 commit bf0df0f

4 files changed

Lines changed: 80 additions & 7 deletions

File tree

src/deploy/functions/runtimes/discovery/v1alpha1.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,37 @@ describe("buildFromV1Alpha", () => {
108108
}
109109
}); // Top level function keys
110110

111+
describe("VPC settings", () => {
112+
it("throws when both connector and networkInterfaces are specified", () => {
113+
assertParserError({
114+
endpoints: {
115+
func: {
116+
...MIN_ENDPOINT,
117+
httpsTrigger: {},
118+
vpc: {
119+
connector: "connector",
120+
networkInterfaces: [{ network: "network" }],
121+
},
122+
},
123+
},
124+
});
125+
});
126+
127+
it("throws when neither connector nor networkInterfaces are specified", () => {
128+
assertParserError({
129+
endpoints: {
130+
func: {
131+
...MIN_ENDPOINT,
132+
httpsTrigger: {},
133+
vpc: {
134+
egressSettings: "ALL_TRAFFIC",
135+
},
136+
},
137+
},
138+
});
139+
});
140+
});
141+
111142
describe("Event triggers", () => {
112143
const validTrigger: build.EventTrigger = {
113144
eventType: "google.pubsub.v1.topic.publish",

src/deploy/functions/runtimes/discovery/v1alpha1.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ function assertBuildEndpoint(ep: WireEndpoint, id: string): void {
189189
`VPC settings on ${id} must specify either 'connector' or 'networkInterfaces'`,
190190
);
191191
}
192+
if (ep.vpc.connector && ep.vpc.networkInterfaces) {
193+
throw new FirebaseError(
194+
`VPC settings on ${id} cannot specify both 'connector' and 'networkInterfaces'`,
195+
);
196+
}
192197
}
193198
let triggerCount = 0;
194199
if (ep.httpsTrigger) {

src/gcp/cloudfunctionsv2.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,39 @@ describe("cloudfunctionsv2", () => {
307307
expect(reverted.vpc).to.deep.equal(endpointWithNi.vpc);
308308
});
309309

310+
it("should throw on unexpected VPC egress setting", () => {
311+
expect(() => {
312+
cloudfunctionsv2.endpointFromFunction({
313+
...HAVE_CLOUD_FUNCTION_V2,
314+
serviceConfig: {
315+
...HAVE_CLOUD_FUNCTION_V2.serviceConfig,
316+
directVpcNetworkInterface: [{ network: "my-net" }],
317+
directVpcEgress: "ALL_TRAFFIC" as any,
318+
uri: RUN_URI,
319+
service: "service",
320+
},
321+
} as cloudfunctionsv2.OutputCloudFunction);
322+
}).to.throw("Unexpected VPC egress setting: ALL_TRAFFIC");
323+
});
324+
325+
it("should ignore VPC_EGRESS_UNSPECIFIED", () => {
326+
const gcf = {
327+
...HAVE_CLOUD_FUNCTION_V2,
328+
serviceConfig: {
329+
...HAVE_CLOUD_FUNCTION_V2.serviceConfig,
330+
directVpcNetworkInterface: [{ network: "my-net" }],
331+
directVpcEgress: "VPC_EGRESS_UNSPECIFIED" as any,
332+
uri: RUN_URI,
333+
service: "service",
334+
},
335+
} as cloudfunctionsv2.OutputCloudFunction;
336+
const endpoint = cloudfunctionsv2.endpointFromFunction(gcf);
337+
expect(endpoint.vpc).to.deep.equal({
338+
networkInterfaces: [{ network: "my-net" }],
339+
});
340+
expect(endpoint.vpc?.egressSettings).to.be.undefined;
341+
});
342+
310343
it("should calculate non-trivial fields", () => {
311344
const complexEndpoint: backend.Endpoint = {
312345
...ENDPOINT,

src/gcp/cloudfunctionsv2.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -755,13 +755,17 @@ export function endpointFromFunction(gcfFunction: OutputCloudFunction): backend.
755755
);
756756
} else if (gcfFunction.serviceConfig.directVpcNetworkInterface) {
757757
endpoint.vpc = { networkInterfaces: gcfFunction.serviceConfig.directVpcNetworkInterface };
758-
if (
759-
gcfFunction.serviceConfig.directVpcEgress &&
760-
gcfFunction.serviceConfig.directVpcEgress !== "VPC_EGRESS_UNSPECIFIED"
761-
) {
762-
endpoint.vpc.egressSettings = gcfFunction.serviceConfig.directVpcEgress.substring(
763-
"VPC_EGRESS_".length,
764-
) as backend.VpcEgressSettings;
758+
if (gcfFunction.serviceConfig.directVpcEgress) {
759+
if (!gcfFunction.serviceConfig.directVpcEgress.startsWith("VPC_EGRESS_")) {
760+
throw new FirebaseError(
761+
`Unexpected VPC egress setting: ${gcfFunction.serviceConfig.directVpcEgress}`,
762+
);
763+
}
764+
if (gcfFunction.serviceConfig.directVpcEgress !== "VPC_EGRESS_UNSPECIFIED") {
765+
endpoint.vpc.egressSettings = gcfFunction.serviceConfig.directVpcEgress.substring(
766+
"VPC_EGRESS_".length,
767+
) as backend.VpcEgressSettings;
768+
}
765769
}
766770
}
767771
const serviceName = gcfFunction.serviceConfig.service;

0 commit comments

Comments
 (0)