From ca6bb7fa1d6dfbea8afb4c96037d4cbb04d55904 Mon Sep 17 00:00:00 2001 From: raffis Date: Sat, 17 Nov 2018 00:54:58 +0100 Subject: [PATCH] fixes --- package.json | 4 ++-- src/operations/create.ts | 6 ++---- src/operations/login.ts | 19 ++++++++++++------- src/resources/abstract.create.ts | 7 +++++-- src/resources/abstract.get.ts | 3 ++- src/resources/abstract.sync.ts | 9 +++++---- src/resources/data-objects/get.ts | 2 +- 7 files changed, 29 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 04b5b79..c6fcb01 100644 --- a/package.json +++ b/package.json @@ -41,12 +41,12 @@ "json-stream": "^1.0.0", "keytar": "^4.3.0", "md5-file": "^4.0.0", + "password-prompt": "^1.0.7", "randomstring": "^1.1.5", "rewire": "^3.0.2", "swagger-parser": "^6.0.2", "table": "^5.1.0", - "time-ago": "^0.2.1", - "tmp": "0.0.33" + "time-ago": "^0.2.1" }, "devDependencies": { "@types/jest": "^22.2.3", diff --git a/src/operations/create.ts b/src/operations/create.ts index 810ce70..2ed8276 100644 --- a/src/operations/create.ts +++ b/src/operations/create.ts @@ -15,8 +15,7 @@ const map = [AccessRoles, AccessRules, Mandators, DataTypes, DataObjects, Endpoi export interface CreateOptions { file: string; input: string; - fromTemplate: boolean; - copyFrom: string; + fromTemplate: string; } export interface CreateArgs { @@ -40,8 +39,7 @@ export default class Create { sub .option('-i, --input ', 'Define the input format (One of yaml,json)') .option('-f, -file ', 'File to read from') - .option('--from-template', 'Opens the editor with a predefined template') - .option('--copy-from ', 'Clones an existing objects data'); + .option('--from-template [name]', 'Opens the editor with a predefined template') } } } diff --git a/src/operations/login.ts b/src/operations/login.ts index 1c9be8c..1699339 100644 --- a/src/operations/login.ts +++ b/src/operations/login.ts @@ -7,6 +7,7 @@ import { Config, configPath } from '../tubee.client'; const keytar = require('keytar'); const path = require('path'); const api = require('@gyselroth/tubee-sdk-typescript-node'); +const prompt = require('password-prompt'); export interface LoginOptions { username: string; @@ -29,17 +30,16 @@ export default class Login { /** * Apply cli options */ - public static factory(optparse: Command, client: TubeeClient) { + public static async factory(optparse: Command, client: TubeeClient) { let remote = optparse.subCommand('login').description('Login resources'); remote - .option('-u, --username ', 'Define the output format (One of yaml,json)') - .option('-p, --password ', 'Define the output format (One of yaml,json)') - .option('-P, --prompt ', 'Define the output format (One of yaml,json)') - .option('-s, --server ', 'File to read from') + .option('-u, --username ', 'HTTP basic auth username') + .option('-p, --password ', 'HTTP basic auth password') + .option('-P, --prompt', 'HTTP basuc auth prompt for password input') + .option('-s, --server ', 'URL to tubee server (For example https://example.org)') .option('-a, --allow-self-signed', 'Allow self signed server certificate') .action(async (opts, args, rest) => { var config = {} as Config; - if (opts.username[0]) { config.username = opts.username[0]; } @@ -48,11 +48,16 @@ export default class Login { keytar.setPassword('tubee', config.username || 'admin', opts.password[0]); } + if(opts.prompt) { + let password = await prompt('Enter password: '); + keytar.setPassword('tubee', config.username || 'admin', password); + } + if (opts.server[0]) { config.url = opts.server[0]; } - if (opts.allowSelfSigned[0]) { + if (opts.allowSelfSigned) { process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; config.allowSelfSigned = true; } else { diff --git a/src/resources/abstract.create.ts b/src/resources/abstract.create.ts index 981b67b..bbe844b 100644 --- a/src/resources/abstract.create.ts +++ b/src/resources/abstract.create.ts @@ -52,10 +52,13 @@ export default abstract class AbstractCreate extends AbstractOperation { return this.openEditor(callback, path, opts.input[0]); });*/ - - if (opts.fromTemplate == true) { + if (opts.fromTemplate.length > 0) { var path: string = fspath.join(os.tmpdir(), '.' + randomstring.generate(7) + '.yml'); + if(opts.fromTemplate[0] !== '') { + resourceType = opts.fromTemplate[0]; + } +console.log(opts); SwaggerParser.validate(specPath, async (err, api) => { if (err) { console.error('Failed to retrieve the resource specification', err); diff --git a/src/resources/abstract.get.ts b/src/resources/abstract.get.ts index 13d9224..c3de0fc 100644 --- a/src/resources/abstract.get.ts +++ b/src/resources/abstract.get.ts @@ -62,10 +62,11 @@ export default abstract class AbstractGet extends AbstractOperation { * Execute */ public async getObjects(response, opts, fields = ['Name', 'Version', 'Changed', 'Created'], callback = null) { +console.log(response.response.toJSON().body); if (opts.diff[0]) { return this.compare(response.response.toJSON().body, opts); } - + var body: string; switch (opts.output[0]) { case 'json': diff --git a/src/resources/abstract.sync.ts b/src/resources/abstract.sync.ts index c55dc7c..4512cc4 100644 --- a/src/resources/abstract.sync.ts +++ b/src/resources/abstract.sync.ts @@ -25,11 +25,12 @@ export default abstract class AbstractSync { */ protected async addProcess(resource, opts, args, rest) { var api = await this.client.factory('Jobs', this.optparse.parent.parsedOpts); - resource.loadbalance = false; - resource.ignore = !opts.abortOnError; - resource.log_level = opts.level[0]; + resource.data.loadbalance = false; + resource.data.ignore = !opts.abortOnError; + resource.data.log_level = opts.level[0]; +console.log(resource); var result = await api.addProcess(resource); - console.log(result); +console.log(result); this.sync(result, opts); } diff --git a/src/resources/data-objects/get.ts b/src/resources/data-objects/get.ts index cb3b5a2..75e4257 100644 --- a/src/resources/data-objects/get.ts +++ b/src/resources/data-objects/get.ts @@ -32,7 +32,7 @@ export default class Get extends AbstractGet { } } else { if (args.name) { - if (opts.history) { + if (opts.history || opts.diff[0]) { var response = await category.getObjectHistory(args.mandator, args.datatype, args.name, this.getFields(opts)); this.getObjects(response, opts); } else {