-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
66 lines (56 loc) · 1.59 KB
/
index.js
File metadata and controls
66 lines (56 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
let _ = require('lodash');
let util = require('util');
let config = require('config');
let logger = config.logger;
let colors = require('colors');
let commandLineArgs = require('command-line-args');
let glib = require('./lib/GLIB.js');
let TCAuth = require('./lib/TCAuth');
let tc = new TCAuth(config.TC, logger);
const options = commandLineArgs([{
name: 'file',
alias: 'f',
type: String
}, {
name: 'username',
alias: 'u',
type: String
}, {
name: 'password',
alias: 'p',
type: String
}, {
name: 'clientId',
alias: 'c',
type: String
}, {
name: 'title',
alias: 't',
type: String
}]);
console.log(options);
var userName = options.username || config.GLIB.USERNAME || '';
var password = options.password || config.GLIB.PASSWORD || '';
var title = options.title || ''; //CWD-- TODO: pull out from file ?
var srcFile = options.file || 'challenge.md'; //CWD-- defaulting to this for now
//CWD-- todo read in file contents if it extsts
if (srcFile) {
console.log('using ' + srcFile + ' to create challenge');
tc.login(userName, password, function(err, accessToken) {
if (err) {
logger.error(err);
} else {
logger.debug('we have a token: %s', accessToken);
glib.createChallenge(config.GLIB, accessToken, srcFile, function(err, res) {
if (err) {
console.log(err);
} else {
console.log(res);
}
})
}
});
} else {
console.log('A file name is required to create a challenge from.');
}