@cloudbase/manager-node 4.6.2 → 4.6.3

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.
@@ -11,6 +11,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CloudRunService = void 0;
13
13
  exports.codeToZip = codeToZip;
14
+ exports.parseObjectToDiffConfigItem = parseObjectToDiffConfigItem;
14
15
  const archiver_1 = __importDefault(require("archiver"));
15
16
  const fs_extra_1 = require("fs-extra");
16
17
  const path_1 = __importDefault(require("path"));
@@ -195,7 +196,7 @@ class CloudRunService {
195
196
  if (await this._checkFunctionExist(serverName)) {
196
197
  // 更新
197
198
  const serverDetail = await this.detail({ serverName });
198
- const _serverConfig = Object.assign(Object.assign(Object.assign({}, ((serverDetail === null || serverDetail === void 0 ? void 0 : serverDetail.ServerConfig) || {})), serverConfig), ((serverDetail === null || serverDetail === void 0 ? void 0 : serverDetail.ServerConfig.Tag) === 'function:' ? { Port: 3000 } : {}) // 函数型不能指定端口,需要固定为3000
199
+ const _serverConfig = Object.assign(Object.assign({}, serverConfig), ((serverDetail === null || serverDetail === void 0 ? void 0 : serverDetail.ServerConfig.Tag) === 'function:' ? { Port: 3000 } : {}) // 函数型不能指定端口,需要固定为3000
199
200
  );
200
201
  deployInfo.ReleaseType = 'FULL';
201
202
  return this._upsertFunction(false, {
@@ -224,7 +225,13 @@ class CloudRunService {
224
225
  RepoLanguage: 'Node.js'
225
226
  };
226
227
  }
227
- const _serverConfig = Object.assign(Object.assign(Object.assign({ OpenAccessTypes: ['OA', 'PUBLIC'], Cpu: 0, Mem: 0, MinNum: 0, MaxNum: 0, PolicyDetails: [], EnvParams: JSON.stringify({}), InitialDelaySeconds: 0, CustomLogs: '', HasDockerfile: true, CreateTime: '', EnvId: envConfig.EnvId, ServerName: serverName, Port: type === 'container' ? 80 : 3000, Dockerfile: 'Dockerfile', BuildDir: '' }, serverConfig), (type === 'function' ? { Port: 3000 } : {})), { Tag: type === 'container' ? '' : 'function:' });
228
+ const _serverConfig = Object.assign(Object.assign(Object.assign({ OpenAccessTypes: ['OA', 'PUBLIC'],
229
+ // Cpu: 0,
230
+ // Mem: 0,
231
+ MinNum: 0,
232
+ // MaxNum: 0,
233
+ // PolicyDetails: [],
234
+ EnvParams: JSON.stringify({}), InitialDelaySeconds: 0, CustomLogs: '', HasDockerfile: true, CreateTime: '', EnvId: envConfig.EnvId, ServerName: serverName, Port: type === 'container' ? 80 : 3000, Dockerfile: 'Dockerfile', BuildDir: '' }, serverConfig), (type === 'function' ? { Port: 3000 } : {})), { Tag: type === 'container' ? '' : 'function:' });
228
235
  return this._upsertFunction(true, {
229
236
  name: serverName,
230
237
  deployInfo,
@@ -258,11 +265,12 @@ class CloudRunService {
258
265
  _upsertFunction(isNew, data) {
259
266
  const { name, deployInfo, serverConfig } = data;
260
267
  const envConfig = this.environment.lazyEnvironmentConfig;
268
+ const Items = parseObjectToDiffConfigItem(serverConfig);
261
269
  return this.tcbrService.request(isNew ? 'CreateCloudRunServer' : 'UpdateCloudRunServer', {
262
270
  EnvId: envConfig.EnvId,
263
271
  ServerName: name,
264
272
  DeployInfo: deployInfo,
265
- ServerConfig: serverConfig
273
+ Items,
266
274
  });
267
275
  }
268
276
  }
@@ -335,3 +343,60 @@ async function codeToZip(cwd, options) {
335
343
  await archive.finalize();
336
344
  return bufferPromise;
337
345
  }
346
+ /**
347
+ * 提交参数变化映射
348
+ */
349
+ const SUBMIT_DIFF_MAP = {
350
+ Cpu: 'CpuSpecs',
351
+ Mem: 'MemSpecs',
352
+ OpenAccessTypes: 'AccessTypes',
353
+ EnvParams: 'EnvParam',
354
+ CustomLogs: 'LogPath'
355
+ };
356
+ /**
357
+ * 将 object 参数转为 [{key:"Port", IntValue:80}] 的格式,并且剔除空字符串
358
+ */
359
+ function parseObjectToDiffConfigItem(data) {
360
+ const kvs = Object.entries(data);
361
+ const Items = [];
362
+ kvs.forEach(([k, v]) => {
363
+ const Key = SUBMIT_DIFF_MAP[k] || k;
364
+ if ([
365
+ 'CustomLogs',
366
+ 'EnvParams',
367
+ 'CreateTime',
368
+ 'Dockerfile',
369
+ 'BuildDir',
370
+ 'LogType',
371
+ 'LogSetId',
372
+ 'LogTopicId',
373
+ 'LogParseType',
374
+ 'Tag',
375
+ 'InternalAccess',
376
+ 'InternalDomain',
377
+ 'OperationMode',
378
+ 'SessionAffinity'
379
+ ].includes(k)) {
380
+ !!v && Items.push({ Key, Value: v });
381
+ }
382
+ else if (['MinNum', 'MaxNum', 'InitialDelaySeconds', 'Port'].includes(k)) {
383
+ Items.push({ Key, IntValue: v });
384
+ }
385
+ else if (['HasDockerfile'].includes(k)) {
386
+ Items.push({ Key, BoolValue: v });
387
+ }
388
+ else if (['Cpu', 'Mem'].includes(k)) {
389
+ Items.push({ Key, FloatValue: v });
390
+ }
391
+ else if (['OpenAccessTypes', 'EntryPoint', 'Cmd'].includes(k)) {
392
+ Items.push({ Key, ArrayValue: v });
393
+ }
394
+ else if (['PolicyDetails'].includes(k)) {
395
+ Items.push({ Key, PolicyDetails: v });
396
+ }
397
+ else if (['TimerScale'].includes(k)) {
398
+ Items.push({ Key, TimerScale: v });
399
+ }
400
+ });
401
+ return Items;
402
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/manager-node",
3
- "version": "4.6.2",
3
+ "version": "4.6.3",
4
4
  "description": "The node manage service api for cloudbase.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,6 +1,6 @@
1
1
  import { Environment } from '../environment';
2
2
  import { IResponseInfo } from '../interfaces';
3
- import { CloudrunServerType, ICloudrunDetailResponse, ICloudrunListResponse, ICloudrunServerBaseConfig, ITemplate } from './type';
3
+ import { CloudrunServerType, ICloudrunDetailResponse, ICloudrunListResponse, ICloudrunServerBaseConfig, ICloudrunServerBaseInfo, IDiffConfigItem, ITemplate } from './type';
4
4
  /**
5
5
  * 云托管服务管理类
6
6
  * 提供云托管服务的初始化、下载、列表查询和删除等功能
@@ -112,3 +112,7 @@ export declare class CloudRunService {
112
112
  export declare function codeToZip(cwd: string, options?: {
113
113
  installDependency?: boolean;
114
114
  }): Promise<Buffer>;
115
+ /**
116
+ * 将 object 参数转为 [{key:"Port", IntValue:80}] 的格式,并且剔除空字符串
117
+ */
118
+ export declare function parseObjectToDiffConfigItem(data: Partial<ICloudrunServerBaseInfo>): IDiffConfigItem[];
@@ -246,6 +246,16 @@ export interface ICloudrunServerBaseConfig {
246
246
  */
247
247
  Cmd?: string[];
248
248
  }
249
+ export interface IDiffConfigItem {
250
+ Key: string;
251
+ Value?: string;
252
+ IntValue?: number;
253
+ BoolValue?: boolean;
254
+ FloatValue?: number;
255
+ ArrayValue?: string[];
256
+ PolicyDetails?: ICloudrunHpaPolicy[];
257
+ TimerScale?: ICloudrunTimerScale[];
258
+ }
249
259
  /**
250
260
  * 在线版本信息
251
261
  */