UNPKG

@xgheaven/nos-cli

Version:
87 lines (86 loc) 4.13 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var nos_node_sdk_1 = require("@xgheaven/nos-node-sdk"); var chalk_1 = __importDefault(require("chalk")); var constant_1 = require("../constant"); var base_command_1 = require("./base-command"); var ClientBaseCommand = /** @class */ (function (_super) { __extends(ClientBaseCommand, _super); function ClientBaseCommand() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._checkBucket = true; return _this; } Object.defineProperty(ClientBaseCommand.prototype, "client", { get: function () { if (this._client) { return this._client; } var _a = this, config = _a.config, args = _a.args; var account = config.accounts[args.account]; if (!account) { this.panic("Cannot found account '" + args.account + "', please try again"); } var nosClientOptions = { accessKey: args.accessKey || account.accessKey, accessSecret: args.accessSecret || account.accessSecret, endpoint: args.endpoint || account.endpoint, defaultBucket: args.bucket || account.defaultBucket, }; if (this.isValidNosClientOption(nosClientOptions)) { return (this._client = new nos_node_sdk_1.NosClient(nosClientOptions)); } else { // 如果检查失败,会直接退出程序,不可能到这里的,这里只是为了跳过错误检查 return null; } }, enumerable: true, configurable: true }); ClientBaseCommand.prototype.isValidNosClientOption = function (options) { if (!options.accessKey || !options.accessSecret) { console.error('Please special AccessKey or AccessSecret by run follow command'); console.error(chalk_1.default.yellow(" " + constant_1.BIN_NAME + " account accessKey accessSecret")); this.panic(); } if (!options.endpoint) { console.error("Please special endpoint by add " + chalk_1.default.blue('--endpoint/-e') + " option or run follow command"); console.error('to set default global endpoint'); console.error(chalk_1.default.green(" " + constant_1.BIN_NAME + " account accessKey accessSecret --endpoint your-endpoint")); this.panic(); } else { var endpoint = options.endpoint; if (!endpoint.startsWith('http')) { console.warn(chalk_1.default.yellow("Warning: No protocol found in \"" + endpoint + "\", \"http\" protocol added automatic")); options.endpoint = "http://" + endpoint; } } if (this._checkBucket && !options.defaultBucket) { console.error("Please special bucket by add " + chalk_1.default.blue('--bucket/-b') + " option or run follow command"); console.error('to set default global endpoint'); console.error(chalk_1.default.green(" " + constant_1.BIN_NAME + " account accessKey accessSecret --defaultBucket your-bucket")); this.panic(); } return true; }; return ClientBaseCommand; }(base_command_1.BaseCommand)); exports.ClientBaseCommand = ClientBaseCommand;