Skip to content

Commit bc21990

Browse files
authored
adding global options invoker (#1424)
1 parent c0fffcc commit bc21990

File tree

4 files changed

+78
-2
lines changed

4 files changed

+78
-2
lines changed

spec/v2/providers/https.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe("onRequest", () => {
3737
});
3838

3939
afterEach(() => {
40+
options.setGlobalOptions({});
4041
delete process.env.GCLOUD_PROJECT;
4142
});
4243

@@ -136,6 +137,33 @@ describe("onRequest", () => {
136137
});
137138
});
138139

140+
it("should take globalOptions invoker", () => {
141+
options.setGlobalOptions({
142+
invoker: "private",
143+
});
144+
145+
const result = https.onRequest((req, res) => {
146+
res.send();
147+
});
148+
149+
expect(result.__trigger).to.deep.eq({
150+
platform: "gcfv2",
151+
httpsTrigger: {
152+
allowInsecure: false,
153+
invoker: ["private"],
154+
},
155+
labels: {},
156+
});
157+
expect(result.__endpoint).to.deep.equal({
158+
...MINIMAL_V2_ENDPOINT,
159+
platform: "gcfv2",
160+
httpsTrigger: {
161+
invoker: ["private"],
162+
},
163+
labels: {},
164+
});
165+
});
166+
139167
it("should be an express handler", async () => {
140168
const func = https.onRequest((req, res) => {
141169
res.send("Works");

spec/v2/providers/tasks.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,31 @@ describe("onTaskDispatched", () => {
7070
});
7171
});
7272

73+
it("should take globalOptions invoker", () => {
74+
options.setGlobalOptions({
75+
invoker: "private",
76+
});
77+
78+
const result = onTaskDispatched(() => undefined);
79+
80+
expect(result.__trigger).to.deep.equal({
81+
platform: "gcfv2",
82+
taskQueueTrigger: {
83+
invoker: ["private"],
84+
},
85+
labels: {},
86+
});
87+
expect(result.__endpoint).to.deep.equal({
88+
...MINIMAL_V2_ENDPOINT,
89+
platform: "gcfv2",
90+
labels: {},
91+
taskQueueTrigger: {
92+
...MINIMIAL_TASK_QUEUE_TRIGGER,
93+
invoker: ["private"],
94+
},
95+
});
96+
});
97+
7398
it("should create a complex trigger/endpoint with appropriate values", () => {
7499
const result = onTaskDispatched(
75100
{

src/v2/providers/https.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,25 @@ export function onRequest(
296296
allowInsecure: false,
297297
},
298298
};
299+
convertIfPresent(
300+
trigger.httpsTrigger,
301+
options.getGlobalOptions(),
302+
"invoker",
303+
"invoker",
304+
convertInvoker
305+
);
299306
convertIfPresent(trigger.httpsTrigger, opts, "invoker", "invoker", convertInvoker);
300307
return trigger;
301308
},
302309
});
303310

304-
const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
311+
const globalOpts = options.getGlobalOptions();
312+
const baseOpts = options.optionsToEndpoint(globalOpts);
305313
// global options calls region a scalar and https allows it to be an array,
306314
// but optionsToTriggerAnnotations handles both cases.
307315
const specificOpts = options.optionsToEndpoint(opts as options.GlobalOptions);
308316
const endpoint: Partial<ManifestEndpoint> = {
309-
...initV2Endpoint(options.getGlobalOptions(), opts),
317+
...initV2Endpoint(globalOpts, opts),
310318
platform: "gcfv2",
311319
...baseOpts,
312320
...specificOpts,
@@ -316,6 +324,7 @@ export function onRequest(
316324
},
317325
httpsTrigger: {},
318326
};
327+
convertIfPresent(endpoint.httpsTrigger, globalOpts, "invoker", "invoker", convertInvoker);
319328
convertIfPresent(endpoint.httpsTrigger, opts, "invoker", "invoker", convertInvoker);
320329
(handler as HttpsFunction).__endpoint = endpoint;
321330

src/v2/providers/tasks.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ export function onTaskDispatched<Args = any>(
220220
const specificOpts = options.optionsToTriggerAnnotations(opts as options.GlobalOptions);
221221
const taskQueueTrigger: Record<string, unknown> = {};
222222
copyIfPresent(taskQueueTrigger, opts, "retryConfig", "rateLimits");
223+
convertIfPresent(
224+
taskQueueTrigger,
225+
options.getGlobalOptions(),
226+
"invoker",
227+
"invoker",
228+
convertInvoker
229+
);
223230
convertIfPresent(taskQueueTrigger, opts, "invoker", "invoker", convertInvoker);
224231
return {
225232
platform: "gcfv2",
@@ -266,6 +273,13 @@ export function onTaskDispatched<Args = any>(
266273
"maxConcurrentDispatches",
267274
"maxDispatchesPerSecond"
268275
);
276+
convertIfPresent(
277+
func.__endpoint.taskQueueTrigger,
278+
options.getGlobalOptions(),
279+
"invoker",
280+
"invoker",
281+
convertInvoker
282+
);
269283
convertIfPresent(func.__endpoint.taskQueueTrigger, opts, "invoker", "invoker", convertInvoker);
270284

271285
func.__requiredAPIs = [

0 commit comments

Comments
 (0)