UNPKG

@veecode-platform/safira-cli

Version:

Generate a microservice project from your spec.

68 lines (67 loc) 3.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const core_1 = require("@oclif/core"); const inquirer_1 = tslib_1.__importDefault(require("inquirer")); const string_validator_1 = require("../../../validator/string-validator"); const docker_registry_1 = require("../../../docker/docker-registry"); const credentials_dto_1 = require("../../../vkpr/credentials/credentials-dto"); const credentials_1 = require("../../../vkpr/credentials/credentials"); class DockerCredentialSet extends core_1.Command { async run() { const { args, flags } = await this.parse(DockerCredentialSet); const answers = await inquirer_1.default.prompt([ { when: !flags.provider && !flags.host, type: "list", name: "registry", message: "Select registry", choices: [ { name: "docker hub", value: docker_registry_1.DockerRegistryEnum.dockerHub }, { name: "other", value: docker_registry_1.DockerRegistryEnum.generic }, ], }, { when: answer => !flags.host && docker_registry_1.DockerRegistryEnum[(answer.registry || docker_registry_1.DockerRegistryEnum.generic)] === docker_registry_1.DockerRegistryEnum.generic, type: "input", name: "host", message: "Registry host", validate: host => string_validator_1.StringValidator.isUrl(host) ? true : "Invalid host", }, { when: !flags.username, type: "input", name: "username", message: "username", validate: username => string_validator_1.StringValidator.notEmpty(username) ? true : "username is required", }, { when: !flags.password, type: "input", name: "password", message: "password", validate: password => string_validator_1.StringValidator.notEmpty(password) ? true : "password is required", }, ]); const host = answers.registry === docker_registry_1.DockerRegistryEnum.dockerHub ? "registry.hub.docker.com" : flags.host || answers.host; const username = flags.username || answers.username; const password = flags.password || answers.password; const dockerCredential = new credentials_dto_1.DockerRegistryCredential(host, username, password); await credentials_1.Credentials.instance.setCredential(dockerCredential); } } exports.default = DockerCredentialSet; DockerCredentialSet.hidden = true; DockerCredentialSet.description = "Configure Docker Registry credential"; DockerCredentialSet.examples = [ "<%= config.bin %> <%= command.id %>", ]; DockerCredentialSet.flags = { help: core_1.Flags.help({}), username: core_1.Flags.string({ char: "a", description: "Registry username" }), password: core_1.Flags.string({ char: "s", description: "Registry password" }), "registry-name": core_1.Flags.string({ char: "n", description: "Registry name" }), host: core_1.Flags.string({ char: "h", description: "Registry host" }), provider: core_1.Flags.string({ hidden: true, char: "p", description: "Registry provider" }), }; DockerCredentialSet.args = [];