1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | Object.defineProperty(exports, "__esModule", { value: true });
|
24 | exports.__getSpec = exports.optionsToEndpoint = exports.optionsToTriggerAnnotations = exports.getGlobalOptions = exports.setGlobalOptions = exports.RESET_VALUE = void 0;
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | const encoding_1 = require("../common/encoding");
|
30 | const options_1 = require("../common/options");
|
31 | const params_1 = require("../params");
|
32 | const types_1 = require("../params/types");
|
33 | const logger = require("../logger");
|
34 | var options_2 = require("../common/options");
|
35 | Object.defineProperty(exports, "RESET_VALUE", { enumerable: true, get: function () { return options_2.RESET_VALUE; } });
|
36 | const MemoryOptionToMB = {
|
37 | "128MiB": 128,
|
38 | "256MiB": 256,
|
39 | "512MiB": 512,
|
40 | "1GiB": 1024,
|
41 | "2GiB": 2048,
|
42 | "4GiB": 4096,
|
43 | "8GiB": 8192,
|
44 | "16GiB": 16384,
|
45 | "32GiB": 32768,
|
46 | };
|
47 | let globalOptions;
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | function setGlobalOptions(options) {
|
53 | if (globalOptions) {
|
54 | logger.warn("Calling setGlobalOptions twice leads to undefined behavior");
|
55 | }
|
56 | globalOptions = options;
|
57 | }
|
58 | exports.setGlobalOptions = setGlobalOptions;
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | function getGlobalOptions() {
|
65 | return globalOptions || {};
|
66 | }
|
67 | exports.getGlobalOptions = getGlobalOptions;
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | function optionsToTriggerAnnotations(opts) {
|
73 | const annotation = {};
|
74 | (0, encoding_1.copyIfPresent)(annotation, opts, "concurrency", "minInstances", "maxInstances", "ingressSettings", "labels", "vpcConnector", "vpcConnectorEgressSettings", "secrets");
|
75 | (0, encoding_1.convertIfPresent)(annotation, opts, "availableMemoryMb", "memory", (mem) => {
|
76 | return MemoryOptionToMB[mem];
|
77 | });
|
78 | (0, encoding_1.convertIfPresent)(annotation, opts, "regions", "region", (region) => {
|
79 | if (typeof region === "string") {
|
80 | return [region];
|
81 | }
|
82 | return region;
|
83 | });
|
84 | (0, encoding_1.convertIfPresent)(annotation, opts, "serviceAccountEmail", "serviceAccount", encoding_1.serviceAccountFromShorthand);
|
85 | (0, encoding_1.convertIfPresent)(annotation, opts, "timeout", "timeoutSeconds", encoding_1.durationFromSeconds);
|
86 | (0, encoding_1.convertIfPresent)(annotation, opts, "failurePolicy", "retry", (retry) => {
|
87 | return retry ? { retry: true } : null;
|
88 | });
|
89 | return annotation;
|
90 | }
|
91 | exports.optionsToTriggerAnnotations = optionsToTriggerAnnotations;
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | function optionsToEndpoint(opts) {
|
97 | const endpoint = {};
|
98 | (0, encoding_1.copyIfPresent)(endpoint, opts, "omit", "concurrency", "minInstances", "maxInstances", "ingressSettings", "labels", "timeoutSeconds", "cpu");
|
99 | (0, encoding_1.convertIfPresent)(endpoint, opts, "serviceAccountEmail", "serviceAccount");
|
100 | if (opts.vpcConnector !== undefined) {
|
101 | if (opts.vpcConnector === null || opts.vpcConnector instanceof options_1.ResetValue) {
|
102 | endpoint.vpc = options_1.RESET_VALUE;
|
103 | }
|
104 | else {
|
105 | const vpc = { connector: opts.vpcConnector };
|
106 | (0, encoding_1.convertIfPresent)(vpc, opts, "egressSettings", "vpcConnectorEgressSettings");
|
107 | endpoint.vpc = vpc;
|
108 | }
|
109 | }
|
110 | (0, encoding_1.convertIfPresent)(endpoint, opts, "availableMemoryMb", "memory", (mem) => {
|
111 | return typeof mem === "object" ? mem : MemoryOptionToMB[mem];
|
112 | });
|
113 | (0, encoding_1.convertIfPresent)(endpoint, opts, "region", "region", (region) => {
|
114 | if (typeof region === "string") {
|
115 | return [region];
|
116 | }
|
117 | return region;
|
118 | });
|
119 | (0, encoding_1.convertIfPresent)(endpoint, opts, "secretEnvironmentVariables", "secrets", (secrets) => secrets.map((secret) => ({ key: secret instanceof types_1.SecretParam ? secret.name : secret })));
|
120 | return endpoint;
|
121 | }
|
122 | exports.optionsToEndpoint = optionsToEndpoint;
|
123 |
|
124 |
|
125 |
|
126 |
|
127 | function __getSpec() {
|
128 | return {
|
129 | globalOptions: getGlobalOptions(),
|
130 | params: params_1.declaredParams.map((p) => p.toSpec()),
|
131 | };
|
132 | }
|
133 | exports.__getSpec = __getSpec;
|