UNPKG

@viewdo/dxp-story-cli

Version:

DXP Story Management CLI

70 lines 4.15 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SetSecretCommand = void 0; const app_1 = require("../app"); const CommandBase_1 = require("./support/CommandBase"); const typedi_1 = require("typedi"); let SetSecretCommand = class SetSecretCommand extends CommandBase_1.CommandBase { run(options) { return __awaiter(this, void 0, void 0, function* () { const app = new app_1.App(options); const orgKeys = app.configuration_manager.organization_keys; const returnSecretKey = options.returnSecretKey; if (!(yield app.auth_manager.requireToken(options.client_id, options.client_secret))) { return 1; } const org_key = orgKeys.includes(options.org) ? options.org : orgKeys.length == 1 ? orgKeys[0] : yield app.prompt_service.askWhich("Organization:", orgKeys); let secret_key = options.secretKey; if (!secret_key) secret_key = yield app.prompt_service.askFor("Secret Key", null, app.prompt_service.validateNotEmpty, 'input', true); secret_key = secret_key.toUpperCase(); // validate secret if (!/^[A-Z0-9-]+$/.test(secret_key)) { app.console_service.log(`Invalid secret name, ex: UPPERCASE-ALPHANUMERIC-1`.red); return 1; } const secret_exists = yield app.sync_manager.organizationSecretExists(org_key, secret_key); if (secret_exists) { const continue_anyway = yield app.prompt_service.askIf(`This secret '${secret_key}' has already been set, are you sure you want to create a new version?`); if (!continue_anyway) return 0; } const secret_value = yield app.prompt_service.askSensitive("Enter the secret value: "); const new_secret_version = yield app.sync_manager.setOrganizationSecret(org_key, secret_key, secret_value); app.console_service.log(` '${new_secret_version}'`.blue); app.console_service.log(`Create new Secret Version successful`.green); // hydrate only secrets let orgConfig = app.configuration_manager.getOrganizationConfig(org_key); orgConfig.secrets = yield app.sync_manager.getOrganizationSecrets(org_key); app.configuration_manager.setOrganizationConfig(orgConfig); // When commands call from other commands, return the created SecretAndVersion if (returnSecretKey) return new_secret_version; return 0; }); } }; exports.SetSecretCommand = SetSecretCommand; exports.SetSecretCommand = SetSecretCommand = __decorate([ (0, typedi_1.Service)() ], SetSecretCommand); //# sourceMappingURL=secret-set.js.map