From 2193f5589098de01c3cce817eafda16dd68dc451 Mon Sep 17 00:00:00 2001 From: Oleg Sucharevich Date: Sun, 19 Aug 2018 11:52:24 +0300 Subject: [PATCH] Contexts (#218) * update cli commands to create git contexts --- .../context/create/git/types/bitbucket.cmd.js | 4 +-- .../context/create/git/types/github.cmd.js | 29 ++++++++++--------- .../context/create/git/types/gitlab.cmd.js | 24 ++++++--------- .../context/create/git/types/stash.cmd.js | 17 +++-------- package.json | 2 +- 5 files changed, 31 insertions(+), 45 deletions(-) diff --git a/lib/interface/cli/commands/context/create/git/types/bitbucket.cmd.js b/lib/interface/cli/commands/context/create/git/types/bitbucket.cmd.js index a435821ff..483056661 100644 --- a/lib/interface/cli/commands/context/create/git/types/bitbucket.cmd.js +++ b/lib/interface/cli/commands/context/create/git/types/bitbucket.cmd.js @@ -28,7 +28,7 @@ const command = new Command({ required: true, }) .option('username', { - describe: 'username that has permissions to use app password', + describe: 'username that has permissions to use application password', alias: 'u', required: true, }); @@ -45,8 +45,6 @@ const command = new Command({ type: 'git.bitbucket', data: { sharingPolicy: argv.sharingPolicy, - host: 'bitbucket.org', - useSSL: true, auth: { type: 'basic', username: argv.username, diff --git a/lib/interface/cli/commands/context/create/git/types/github.cmd.js b/lib/interface/cli/commands/context/create/git/types/github.cmd.js index b882e1364..d02866b63 100644 --- a/lib/interface/cli/commands/context/create/git/types/github.cmd.js +++ b/lib/interface/cli/commands/context/create/git/types/github.cmd.js @@ -7,7 +7,8 @@ const { } = require('../../../../../../../logic/index').api; const LINK = 'https://github.com/settings/tokens'; - +const DEFAULT_API_HOST = 'api.github.com'; +const DEFAULT_API_PREFIX = '/'; const command = new Command({ command: 'github ', @@ -27,18 +28,16 @@ const command = new Command({ alias: 't', required: true, }) - .option('use-ssl', { - describe: 'Connect to the git host using ssl', - choices: [true, false], - type: 'boolean', - alias: 's', - default: true, - required: true, - }) .option('host', { describe: 'Host name of your github (without protocol)', alias: 'h', - default: 'github.com', + default: DEFAULT_API_HOST, + required: true, + }) + .option('api', { + describe: 'Prefix of the api on the given host', + alias: 'a', + default: DEFAULT_API_PREFIX, required: true, }); return yargs; @@ -54,17 +53,21 @@ const command = new Command({ type: 'git.github', data: { sharingPolicy: argv.sharingPolicy, - host: argv.host || 'github.com', - useSSL: Boolean(argv.useSSL) || true, auth: { type: 'basic', - username: 'x-oauth-basic', password: argv.accessToken, }, }, }, }; + if (argv.apiPathPrefix !== DEFAULT_API_PREFIX) { + data.spec.data.auth.apiPathPrefix = argv.apiPathPrefix; + } + + if (argv.host !== DEFAULT_API_HOST) { + data.spec.data.auth.apiHost = argv.host; + } if (!data.metadata.name || !data.spec.type) { throw new CFError('Name and type must be provided'); diff --git a/lib/interface/cli/commands/context/create/git/types/gitlab.cmd.js b/lib/interface/cli/commands/context/create/git/types/gitlab.cmd.js index 17e3d8ece..8446b6374 100644 --- a/lib/interface/cli/commands/context/create/git/types/gitlab.cmd.js +++ b/lib/interface/cli/commands/context/create/git/types/gitlab.cmd.js @@ -7,6 +7,7 @@ const { } = require('../../../../../../../logic/index').api; const LINK = 'https://gitlab.com/profile/personal_access_tokens'; +const DEFAULT_API_URL = 'https://gitlab.com/api/v4/'; const command = new Command({ @@ -27,18 +28,10 @@ const command = new Command({ alias: 't', required: true, }) - .option('use-ssl', { - describe: 'Connect to the git host using ssl', - choices: [true, false], - type: 'boolean', - alias: 's', - default: true, - required: true, - }) - .option('host', { - describe: 'Host name of your gitlab (without protocol)', - alias: 'h', - default: 'gitlab.com', + .option('api-url', { + describe: 'URL of the api', + alias: 'a', + default: 'https://gitlab.com/api/v4/', required: true, }); return yargs; @@ -54,17 +47,18 @@ const command = new Command({ type: 'git.gitlab', data: { sharingPolicy: argv.sharingPolicy, - host: argv.host || 'gitlab.com', - useSSL: Boolean(argv.useSSL) || true, auth: { type: 'basic', - username: 'oauth2', password: argv.accessToken, }, }, }, }; + if (argv.apiUrl !== DEFAULT_API_URL) { + data.spec.data.auth.apiURL = argv.apiUrl; + } + if (!data.metadata.name || !data.spec.type) { throw new CFError('Name and type must be provided'); diff --git a/lib/interface/cli/commands/context/create/git/types/stash.cmd.js b/lib/interface/cli/commands/context/create/git/types/stash.cmd.js index 7bcbefc94..b3bc99f38 100644 --- a/lib/interface/cli/commands/context/create/git/types/stash.cmd.js +++ b/lib/interface/cli/commands/context/create/git/types/stash.cmd.js @@ -31,17 +31,9 @@ const command = new Command({ alias: 'p', required: true, }) - .option('host', { - describe: 'Host name of your stash (without protocol, may include port)', - alias: 'h', - required: true, - }) - .option('use-ssl', { - describe: 'Connect to the git host using ssl', - choices: [true, false], - type: 'boolean', - alias: 's', - default: true, + .option('api-url', { + describe: 'URL of the api', + alias: 'a', required: true, }); return yargs; @@ -57,12 +49,11 @@ const command = new Command({ type: 'git.stash', data: { sharingPolicy: argv.sharingPolicy, - host: argv.host || 'stash.com', - useSSL: Boolean(argv.useSSL) || true, auth: { type: 'basic', username: argv.username, password: argv.password, + apiURL: argv.apiUrl, }, }, }, diff --git a/package.json b/package.json index 18e45886f..a4680dd72 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codefresh", - "version": "0.8.73", + "version": "0.8.74", "description": "Codefresh command line utility", "main": "index.js", "preferGlobal": true,