Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
raffis committed Nov 16, 2018
1 parent ac59348 commit ca6bb7f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 21 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 2 additions & 4 deletions src/operations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -40,8 +39,7 @@ export default class Create {
sub
.option('-i, --input <name>', 'Define the input format (One of yaml,json)')
.option('-f, -file <name>', 'File to read from')
.option('--from-template', 'Opens the editor with a predefined template')
.option('--copy-from <name>', 'Clones an existing objects data');
.option('--from-template [name]', 'Opens the editor with a predefined template')
}
}
}
19 changes: 12 additions & 7 deletions src/operations/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,17 +30,16 @@ export default class Login {
/**
* Apply cli options
*/
public static factory(optparse: Command<RootOptions, RootArgs>, client: TubeeClient) {
public static async factory(optparse: Command<RootOptions, RootArgs>, client: TubeeClient) {
let remote = optparse.subCommand<LoginOptions, LoginArgs>('login').description('Login resources');
remote
.option('-u, --username <name>', 'Define the output format (One of yaml,json)')
.option('-p, --password <name>', 'Define the output format (One of yaml,json)')
.option('-P, --prompt <name>', 'Define the output format (One of yaml,json)')
.option('-s, --server <name>', 'File to read from')
.option('-u, --username <name>', 'HTTP basic auth username')
.option('-p, --password <name>', 'HTTP basic auth password')
.option('-P, --prompt', 'HTTP basuc auth prompt for password input')
.option('-s, --server <name>', '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];
}
Expand All @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions src/resources/abstract.create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/resources/abstract.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
9 changes: 5 additions & 4 deletions src/resources/abstract.sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/resources/data-objects/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ca6bb7f

Please sign in to comment.