@mxpicture/gcp-functions-generator 1.1.75 → 1.1.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/types.common.d.ts +1 -22
- package/dist/common/types.common.d.ts.map +1 -1
- package/package.json +5 -7
- package/dist/tasks/TaskHandler.d.ts +0 -21
- package/dist/tasks/TaskHandler.d.ts.map +0 -1
- package/dist/tasks/TaskHandler.js +0 -79
- package/dist/tasks/TaskHandler.js.map +0 -1
- package/dist/tasks/TaskSetup.d.ts +0 -2
- package/dist/tasks/TaskSetup.d.ts.map +0 -1
- package/dist/tasks/TaskSetup.js +0 -173
- package/dist/tasks/TaskSetup.js.map +0 -1
- package/dist/tasks/index.d.ts +0 -3
- package/dist/tasks/index.d.ts.map +0 -1
- package/dist/tasks/index.js +0 -4
- package/dist/tasks/index.js.map +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DecoFileExtension, DecoFileType, DecoTargetType } from "@mxpicture/gcp-functions-common/decorator";
|
|
1
|
+
import { DecoFileExtension, DecoFileType } from "@mxpicture/gcp-functions-common/decorator";
|
|
3
2
|
/**
|
|
4
3
|
* Decomposed parts of a dot-separated decorator filename.
|
|
5
4
|
*/
|
|
@@ -15,14 +14,6 @@ export interface ExtractFileParts {
|
|
|
15
14
|
/** Whether this file is a generated artifact. */
|
|
16
15
|
generated?: boolean;
|
|
17
16
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Represents a target package with its location and parsed `package.json`.
|
|
20
|
-
*/
|
|
21
|
-
export interface TargetPackage {
|
|
22
|
-
targetType: DecoTargetType;
|
|
23
|
-
filePath: string;
|
|
24
|
-
pkg: PackageJson;
|
|
25
|
-
}
|
|
26
17
|
/**
|
|
27
18
|
* Environment variables required by generators that produce deployment-aware code.
|
|
28
19
|
*/
|
|
@@ -54,16 +45,4 @@ export interface JobParams {
|
|
|
54
45
|
runServiceName: string;
|
|
55
46
|
runServiceRegion: string;
|
|
56
47
|
}
|
|
57
|
-
export interface TaskConfig {
|
|
58
|
-
projectId: string;
|
|
59
|
-
region: string;
|
|
60
|
-
serviceAccount: string;
|
|
61
|
-
queueId: string;
|
|
62
|
-
targetUrl: string;
|
|
63
|
-
}
|
|
64
|
-
export interface TaskScheduleParams extends TaskConfig {
|
|
65
|
-
days: number;
|
|
66
|
-
payload?: string;
|
|
67
|
-
taskId?: string;
|
|
68
|
-
}
|
|
69
48
|
//# sourceMappingURL=types.common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.common.d.ts","sourceRoot":"","sources":["../../src/common/types.common.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"types.common.d.ts","sourceRoot":"","sources":["../../src/common/types.common.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,YAAY,EACb,MAAM,2CAA2C,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,IAAI,EAAE,YAAY,CAAC;IACnB,yCAAyC;IACzC,GAAG,EAAE,iBAAiB,CAAC;IACvB,qEAAqE;IACrE,UAAU,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IAEpB,uBAAuB,EAAE,OAAO,CAAC;IAEjC,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;CAC1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mxpicture/gcp-functions-generator",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.77",
|
|
4
4
|
"description": "Tools for google cloud functions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "MXPicture",
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
"./common": "./dist/common/index.js",
|
|
14
14
|
"./package.json": "./package.json",
|
|
15
15
|
"./decorator": "./dist/decorator/index.js",
|
|
16
|
-
"./generator": "./dist/generator/index.js"
|
|
17
|
-
"./tasks": "./dist/tasks/index.js"
|
|
16
|
+
"./generator": "./dist/generator/index.js"
|
|
18
17
|
},
|
|
19
18
|
"files": [
|
|
20
19
|
"dist"
|
|
@@ -36,11 +35,10 @@
|
|
|
36
35
|
},
|
|
37
36
|
"dependencies": {
|
|
38
37
|
"@google-cloud/scheduler": "^5.3.1",
|
|
39
|
-
"@google-cloud/tasks": "^6.2.1",
|
|
40
38
|
"@mxpicture/build-api": "^0.2.59",
|
|
41
|
-
"@mxpicture/gcp-functions-backend": "^1.1.
|
|
42
|
-
"@mxpicture/gcp-functions-common": "^1.1.
|
|
43
|
-
"@mxpicture/gcp-functions-frontend": "^1.1.
|
|
39
|
+
"@mxpicture/gcp-functions-backend": "^1.1.77",
|
|
40
|
+
"@mxpicture/gcp-functions-common": "^1.1.77",
|
|
41
|
+
"@mxpicture/gcp-functions-frontend": "^1.1.77",
|
|
44
42
|
"google-auth-library": "^10.6.2",
|
|
45
43
|
"googleapis": "^171.4.0",
|
|
46
44
|
"json5": "^2.2.3"
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { CloudTasksClient } from "@google-cloud/tasks";
|
|
2
|
-
import { TaskConfig, TaskScheduleParams } from "../common/types.common.js";
|
|
3
|
-
export declare const scheduleTask: (params: TaskScheduleParams) => Promise<string | null>;
|
|
4
|
-
export declare class TaskHandler {
|
|
5
|
-
protected readonly config: TaskConfig;
|
|
6
|
-
protected tasksClient: CloudTasksClient;
|
|
7
|
-
constructor(config: TaskConfig);
|
|
8
|
-
ensureTaskName(taskId: string | undefined | null): string | null;
|
|
9
|
-
add(days: number, payload?: string, taskId?: string): Promise<string | null>;
|
|
10
|
-
/**
|
|
11
|
-
* Returns a Date in UTC in the allowed window (23:00–06:00).
|
|
12
|
-
* Strategy:
|
|
13
|
-
* - base = now + days
|
|
14
|
-
* - if base hour in [0..5] => keep base (rounded up to next 5 min)
|
|
15
|
-
* - if base hour in [23] => keep base (rounded up to next 5 min)
|
|
16
|
-
* - else => task at 23:30:00 UTC same date as base
|
|
17
|
-
*/
|
|
18
|
-
computeNightScheduleTimeUtc(base: Date): Date;
|
|
19
|
-
protected assertDays(days: number): void;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=TaskHandler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TaskHandler.d.ts","sourceRoot":"","sources":["../../src/tasks/TaskHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE3E,eAAO,MAAM,YAAY,GACvB,QAAQ,kBAAkB,KACzB,OAAO,CAAC,MAAM,GAAG,IAAI,CACiD,CAAC;AAE1E,qBAAa,WAAW;IAGH,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,UAAU;IAFxD,SAAS,CAAC,WAAW,EAAE,gBAAgB,CAAC;gBAEF,MAAM,EAAE,UAAU;IAIjD,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI;IAO1D,GAAG,CACd,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA2CzB;;;;;;;OAOG;IACI,2BAA2B,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAkBpD,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM;CAIlC"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { CloudTasksClient } from "@google-cloud/tasks";
|
|
2
|
-
export const scheduleTask = async (params) => new TaskHandler(params).add(params.days, params.payload, params.taskId);
|
|
3
|
-
export class TaskHandler {
|
|
4
|
-
config;
|
|
5
|
-
tasksClient;
|
|
6
|
-
constructor(config) {
|
|
7
|
-
this.config = config;
|
|
8
|
-
this.tasksClient = new CloudTasksClient();
|
|
9
|
-
}
|
|
10
|
-
ensureTaskName(taskId) {
|
|
11
|
-
if (!taskId)
|
|
12
|
-
return null;
|
|
13
|
-
const prefix = `projects/${this.config.projectId}/locations/${this.config.region}/queues/${this.config.queueId}/tasks/`;
|
|
14
|
-
if (taskId.startsWith(prefix))
|
|
15
|
-
return taskId;
|
|
16
|
-
return `${prefix}${taskId}`;
|
|
17
|
-
}
|
|
18
|
-
async add(days, payload, taskId) {
|
|
19
|
-
this.assertDays(days);
|
|
20
|
-
const name = this.ensureTaskName(taskId);
|
|
21
|
-
const base = new Date(Date.now() + days * 24 * 60 * 60 * 1000);
|
|
22
|
-
const targetAt = this.computeNightScheduleTimeUtc(base);
|
|
23
|
-
const queuePath = this.tasksClient.queuePath(this.config.projectId, this.config.region, this.config.queueId);
|
|
24
|
-
let body = null;
|
|
25
|
-
let headers = null;
|
|
26
|
-
if (payload) {
|
|
27
|
-
body = Buffer.from(payload, "utf8").toString("base64");
|
|
28
|
-
headers = {
|
|
29
|
-
"Content-Type": "application/json",
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
const [task] = await this.tasksClient.createTask({
|
|
33
|
-
parent: queuePath,
|
|
34
|
-
task: {
|
|
35
|
-
scheduleTime: { seconds: Math.floor(targetAt.getTime() / 1000) },
|
|
36
|
-
name,
|
|
37
|
-
httpRequest: {
|
|
38
|
-
httpMethod: "POST",
|
|
39
|
-
url: this.config.targetUrl,
|
|
40
|
-
headers,
|
|
41
|
-
body,
|
|
42
|
-
oidcToken: {
|
|
43
|
-
serviceAccountEmail: this.config.serviceAccount,
|
|
44
|
-
// Optional: set audience; often leave unset, or set to the URL depending on your auth expectations
|
|
45
|
-
// audience: EXEC_ENDPOINT_URL,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
return task.name ?? null;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Returns a Date in UTC in the allowed window (23:00–06:00).
|
|
54
|
-
* Strategy:
|
|
55
|
-
* - base = now + days
|
|
56
|
-
* - if base hour in [0..5] => keep base (rounded up to next 5 min)
|
|
57
|
-
* - if base hour in [23] => keep base (rounded up to next 5 min)
|
|
58
|
-
* - else => task at 23:30:00 UTC same date as base
|
|
59
|
-
*/
|
|
60
|
-
computeNightScheduleTimeUtc(base) {
|
|
61
|
-
const d = new Date(base.getTime());
|
|
62
|
-
const hour = d.getUTCHours();
|
|
63
|
-
const inNight = hour >= 23 || hour < 6;
|
|
64
|
-
if (!inNight) {
|
|
65
|
-
d.setUTCHours(23, 30, 0, 0);
|
|
66
|
-
return d;
|
|
67
|
-
}
|
|
68
|
-
// Round up to next 5 minutes to avoid "task in the past by milliseconds" issues
|
|
69
|
-
const ms = d.getTime();
|
|
70
|
-
const fiveMin = 5 * 60 * 1000;
|
|
71
|
-
const rounded = Math.ceil(ms / fiveMin) * fiveMin;
|
|
72
|
-
return new Date(rounded);
|
|
73
|
-
}
|
|
74
|
-
assertDays(days) {
|
|
75
|
-
if (!Number.isInteger(days) || days < 1 || days > 100)
|
|
76
|
-
throw new Error("days must be an integer between 1 and 100");
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=TaskHandler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TaskHandler.js","sourceRoot":"","sources":["../../src/tasks/TaskHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,MAA0B,EACF,EAAE,CAC1B,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AAE1E,MAAM,OAAO,WAAW;IAGgB;IAF5B,WAAW,CAAmB;IAExC,YAAsC,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QACtD,IAAI,CAAC,WAAW,GAAG,IAAI,gBAAgB,EAAE,CAAC;IAC5C,CAAC;IAEM,cAAc,CAAC,MAAiC;QACrD,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QACzB,MAAM,MAAM,GAAG,YAAY,IAAI,CAAC,MAAM,CAAC,SAAS,cAAc,IAAI,CAAC,MAAM,CAAC,MAAM,WAAW,IAAI,CAAC,MAAM,CAAC,OAAO,SAAS,CAAC;QACxH,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC;YAAE,OAAO,MAAM,CAAC;QAC7C,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;IAC9B,CAAC;IAEM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// todo not usable / untested!!!!!!!
|
|
2
|
-
// import { CloudTasksClient } from "@google-cloud/tasks";
|
|
3
|
-
// import {
|
|
4
|
-
// GeneratorEnv,
|
|
5
|
-
// TaskConfig,
|
|
6
|
-
// TaskParams,
|
|
7
|
-
// } from "../common/types.common.js";
|
|
8
|
-
// import { google } from "googleapis";
|
|
9
|
-
export {};
|
|
10
|
-
// export class TaskSetup {
|
|
11
|
-
// protected config: TaskConfig;
|
|
12
|
-
// public constructor(
|
|
13
|
-
// protected readonly params: TaskParams,
|
|
14
|
-
// protected readonly env: GeneratorEnv,
|
|
15
|
-
// ) {
|
|
16
|
-
// this.config = this.prepareConfig(params, env);
|
|
17
|
-
// }
|
|
18
|
-
// public async run() {
|
|
19
|
-
// const tasks = new CloudTasksClient();
|
|
20
|
-
// const queueName = await this.ensureQueue(tasks);
|
|
21
|
-
// const { saEmail } = await this.ensureServiceAccount();
|
|
22
|
-
// console.log(`\nSummary`);
|
|
23
|
-
// console.log(`- Project: ${this.config.projectId}`);
|
|
24
|
-
// console.log(`- Region: ${this.config.region}`);
|
|
25
|
-
// console.log(`- Queue: ${queueName}`);
|
|
26
|
-
// console.log(`- Task OIDC service account: ${saEmail}`);
|
|
27
|
-
// console.log(`- Exec endpoint: ${this.config.functionUrl}`);
|
|
28
|
-
// // console.log(`- Dummy Firestore path (replace): ${DUMMY_FIRESTORE_DOC_PATH}`);
|
|
29
|
-
// if (this.config.ensureRunInvokerBinding) {
|
|
30
|
-
// // Best-effort guidance (automatic binding is hard without more info/permissions).
|
|
31
|
-
// await this.tryGrantInvokerBinding(saEmail);
|
|
32
|
-
// } else {
|
|
33
|
-
// console.log(
|
|
34
|
-
// `\nInvoker IAM not applied (APPLY_INVOKER_BINDING=false). You must grant roles/run.invoker to ${saEmail} for the target service.`,
|
|
35
|
-
// );
|
|
36
|
-
// }
|
|
37
|
-
// }
|
|
38
|
-
// protected prepareConfig(params: TaskParams, env: GeneratorEnv): TaskConfig {
|
|
39
|
-
// const { projectId, region, serviceAccount } = env;
|
|
40
|
-
// // If you prefer not to hardcode URL, pass FUNCTION_URL explicitly after deploy.
|
|
41
|
-
// const functionUrl =
|
|
42
|
-
// params.functionUrl ??
|
|
43
|
-
// `https://${region}-${projectId}.cloudfunctions.net/${params.runServiceName}`;
|
|
44
|
-
// return {
|
|
45
|
-
// projectId,
|
|
46
|
-
// region,
|
|
47
|
-
// serviceAccount,
|
|
48
|
-
// queueId: params.queueId ?? `${params.runServiceName}-task`,
|
|
49
|
-
// functionUrl,
|
|
50
|
-
// ensureRunInvokerBinding: !!params.ensureRunInvokerBinding,
|
|
51
|
-
// runServiceName: params.runServiceName,
|
|
52
|
-
// runServiceRegion: region,
|
|
53
|
-
// };
|
|
54
|
-
// }
|
|
55
|
-
// public async ensureQueue(tasks: CloudTasksClient) {
|
|
56
|
-
// const parent = tasks.locationPath(
|
|
57
|
-
// this.config.projectId,
|
|
58
|
-
// this.config.region,
|
|
59
|
-
// );
|
|
60
|
-
// const queueName = tasks.queuePath(
|
|
61
|
-
// this.config.projectId,
|
|
62
|
-
// this.config.region,
|
|
63
|
-
// this.config.queueId,
|
|
64
|
-
// );
|
|
65
|
-
// try {
|
|
66
|
-
// await tasks.getQueue({ name: queueName });
|
|
67
|
-
// console.log(`Queue exists: ${queueName}`);
|
|
68
|
-
// return queueName;
|
|
69
|
-
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
-
// } catch (e: any) {
|
|
71
|
-
// // Not found => create
|
|
72
|
-
// if (String(e?.code) !== "5") {
|
|
73
|
-
// console.warn(`getQueue error (continuing to create):`, e?.message || e);
|
|
74
|
-
// }
|
|
75
|
-
// }
|
|
76
|
-
// const [queue] = await tasks.createQueue({
|
|
77
|
-
// parent,
|
|
78
|
-
// queue: {
|
|
79
|
-
// name: queueName,
|
|
80
|
-
// // These defaults are fine; tune as desired.
|
|
81
|
-
// rateLimits: {
|
|
82
|
-
// maxDispatchesPerSecond: 1,
|
|
83
|
-
// maxConcurrentDispatches: 1,
|
|
84
|
-
// },
|
|
85
|
-
// retryConfig: {
|
|
86
|
-
// maxAttempts: 10,
|
|
87
|
-
// minBackoff: { seconds: 10 },
|
|
88
|
-
// maxBackoff: { seconds: 3600 },
|
|
89
|
-
// maxDoublings: 5,
|
|
90
|
-
// },
|
|
91
|
-
// },
|
|
92
|
-
// });
|
|
93
|
-
// console.log(`Queue created: ${queue.name}`);
|
|
94
|
-
// return queue.name!;
|
|
95
|
-
// }
|
|
96
|
-
// public async ensureServiceAccount() {
|
|
97
|
-
// const auth = await google.auth.getClient({
|
|
98
|
-
// scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
99
|
-
// });
|
|
100
|
-
// const iam = google.iam({ version: "v1", auth });
|
|
101
|
-
// const saEmail = `${this.config.serviceAccount}@${this.config.projectId}.iam.gserviceaccount.com`;
|
|
102
|
-
// const saName = `projects/${this.config.projectId}/serviceAccounts/${saEmail}`;
|
|
103
|
-
// try {
|
|
104
|
-
// const existing = await iam.projects.serviceAccounts.get({ name: saName });
|
|
105
|
-
// console.log(`Service account exists: ${existing.data.email}`);
|
|
106
|
-
// return { saEmail, saName };
|
|
107
|
-
// } catch {
|
|
108
|
-
// // continue to create
|
|
109
|
-
// }
|
|
110
|
-
// const created = await iam.projects.serviceAccounts.create({
|
|
111
|
-
// name: `projects/${this.config.projectId}`,
|
|
112
|
-
// requestBody: {
|
|
113
|
-
// accountId: this.config.serviceAccount,
|
|
114
|
-
// },
|
|
115
|
-
// });
|
|
116
|
-
// console.log(`Service account created: ${created.data.email}`);
|
|
117
|
-
// return { saEmail, saName };
|
|
118
|
-
// }
|
|
119
|
-
// /**
|
|
120
|
-
// * Cloud Functions gen2 uses Cloud Run under the hood.
|
|
121
|
-
// * The clean way is to grant roles/run.invoker on the underlying Cloud Run service.
|
|
122
|
-
// *
|
|
123
|
-
// * Problem: mapping from your exec URL to Cloud Run service name programmatically is non-trivial
|
|
124
|
-
// * without calling the Cloud Functions API to resolve it. So:
|
|
125
|
-
// * - We offer a best-effort attempt using Cloud Functions v2 API to look up the function,
|
|
126
|
-
// * if you provide FUNCTION_NAME (e.g. picpadMedicationService).
|
|
127
|
-
// * - Otherwise, we print manual steps.
|
|
128
|
-
// */
|
|
129
|
-
// public async tryGrantInvokerBinding(saEmail: string) {
|
|
130
|
-
// // todo function name
|
|
131
|
-
// const functionName = process.env.FUNCTION_NAME; // e.g. picpadMedicationService
|
|
132
|
-
// if (!functionName) {
|
|
133
|
-
// console.log(
|
|
134
|
-
// `Skipping IAM binding: set FUNCTION_NAME=picpadMedicationService (or your function name) to enable lookup.`,
|
|
135
|
-
// );
|
|
136
|
-
// console.log(
|
|
137
|
-
// `Manual action needed: grant roles/run.invoker to ${saEmail} on the exec endpoint.`,
|
|
138
|
-
// );
|
|
139
|
-
// return;
|
|
140
|
-
// }
|
|
141
|
-
// const auth = await google.auth.getClient({
|
|
142
|
-
// scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
143
|
-
// });
|
|
144
|
-
// // 1) Resolve function -> underlying Cloud Run service
|
|
145
|
-
// const cloudfunctions = google.cloudfunctions({ version: "v2", auth });
|
|
146
|
-
// const fnFullName = `projects/${this.config.projectId}/locations/${this.config.region}/functions/${functionName}`;
|
|
147
|
-
// const fn = await cloudfunctions.projects.locations.functions.get({
|
|
148
|
-
// name: fnFullName,
|
|
149
|
-
// });
|
|
150
|
-
// const serviceUri = fn.data?.serviceConfig?.uri;
|
|
151
|
-
// if (!serviceUri) {
|
|
152
|
-
// console.log(
|
|
153
|
-
// `Could not resolve Cloud Run URI for function ${fnFullName}.`,
|
|
154
|
-
// );
|
|
155
|
-
// console.log(
|
|
156
|
-
// `Manual action needed: grant roles/run.invoker to ${saEmail}.`,
|
|
157
|
-
// );
|
|
158
|
-
// return;
|
|
159
|
-
// }
|
|
160
|
-
// // Cloud Run service name is not directly the URI, but we can still tell the user exactly what URI it is.
|
|
161
|
-
// console.log(`Function resolved. Cloud Run URI: ${serviceUri}`);
|
|
162
|
-
// console.log(
|
|
163
|
-
// `NOTE: Automatically applying IAM to Cloud Run via URI alone isn't supported here; do it via gcloud or console.`,
|
|
164
|
-
// );
|
|
165
|
-
// // We can still verify the URI matches what you think you're calling.
|
|
166
|
-
// console.log(`Your EXEC_ENDPOINT_URL: ${this.config.functionUrl}`);
|
|
167
|
-
// console.log(`Resolved serviceConfig.uri: ${serviceUri}`);
|
|
168
|
-
// console.log(
|
|
169
|
-
// `If these differ, Cloud Tasks can still call EXEC_ENDPOINT_URL, but IAM must allow the OIDC SA.`,
|
|
170
|
-
// );
|
|
171
|
-
// }
|
|
172
|
-
// }
|
|
173
|
-
//# sourceMappingURL=TaskSetup.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TaskSetup.js","sourceRoot":"","sources":["../../src/tasks/TaskSetup.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,0DAA0D;AAC1D,WAAW;AACX,kBAAkB;AAClB,gBAAgB;AAChB,gBAAgB;AAChB,sCAAsC;AACtC,uCAAuC;;AAEvC,2BAA2B;AAC3B,kCAAkC;AAElC,wBAAwB;AACxB,6CAA6C;AAC7C,4CAA4C;AAC5C,QAAQ;AACR,qDAAqD;AACrD,MAAM;AAEN,yBAAyB;AACzB,4CAA4C;AAE5C,uDAAuD;AACvD,6DAA6D;AAE7D,gCAAgC;AAChC,0DAA0D;AAC1D,sDAAsD;AACtD,4CAA4C;AAC5C,8DAA8D;AAC9D,kEAAkE;AAClE,uFAAuF;AAEvF,iDAAiD;AACjD,2FAA2F;AAC3F,oDAAoD;AACpD,eAAe;AACf,qBAAqB;AACrB,6IAA6I;AAC7I,WAAW;AACX,QAAQ;AACR,MAAM;AAEN,iFAAiF;AACjF,yDAAyD;AAEzD,uFAAuF;AACvF,0BAA0B;AAC1B,8BAA8B;AAC9B,sFAAsF;AAEtF,eAAe;AACf,mBAAmB;AACnB,gBAAgB;AAChB,wBAAwB;AACxB,oEAAoE;AACpE,qBAAqB;AACrB,mEAAmE;AAC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gBAAgB;AAChB,QAAQ;AAER,iDAAiD;AACjD,oEAAoE;AACpE,UAAU;AAEV,6DAA6D;AAC7D,6EAA6E;AAE7E,wHAAwH;AACxH,yEAAyE;AACzE,0BAA0B;AAC1B,UAAU;AAEV,sDAAsD;AACtD,yBAAyB;AACzB,qBAAqB;AACrB,yEAAyE;AACzE,WAAW;AACX,qBAAqB;AACrB,0EAA0E;AAC1E,WAAW;AACX,gBAAgB;AAChB,QAAQ;AAER,gHAAgH;AAChH,sEAAsE;AACtE,mBAAmB;AACnB,0HAA0H;AAC1H,SAAS;AAET,4EAA4E;AAC5E,yEAAyE;AACzE,gEAAgE;AAChE,mBAAmB;AACnB,0GAA0G;AAC1G,SAAS;AACT,MAAM;AACN,IAAI"}
|
package/dist/tasks/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tasks/index.ts"],"names":[],"mappings":"AACA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
|
package/dist/tasks/index.js
DELETED
package/dist/tasks/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tasks/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
|