From 4e16a69dbb9a9635ed5fbf4c435cec680894c2b2 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 11 Feb 2020 16:01:47 +0000 Subject: [PATCH 1/6] wip: deploy --- main.js | 8 ++++++-- src/command-handler.js | 7 ++++++- src/databot.js | 18 +++--------------- src/deploy.js | 19 +++++++++++++++++++ tests/configs/deploy.json | 13 +++++++++++++ 5 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 src/deploy.js create mode 100644 tests/configs/deploy.json diff --git a/main.js b/main.js index 9c1d5f0..bf4a586 100644 --- a/main.js +++ b/main.js @@ -156,6 +156,9 @@ async function run(commandName, commandProps) { case "token": output = await commandHandler.runTokenCommand(command); break; + case "deploy": + output = await commandHandler.deploy({id, configJson, filepath}); + break; } if (output) console.log(output); @@ -175,6 +178,7 @@ const argv = require("yargs") .command("info [type] [id]", "Output current account info", {}, argumentHandler) .command("config", "Output tdx config", {}, argumentHandler) .command("list [type]", "List all configured aliases or secrets", {}, argumentHandler) + .command("token ", "Get or revoke a token for a give alias", {}, argumentHandler) .command("runapi ", "Run a tdx api command", {}, argumentHandler) .command("download [filepath]", "Download resource", {}, argumentHandler) .command("upload ", "Upload resource", {}, argumentHandler) @@ -182,7 +186,7 @@ const argv = require("yargs") .command("modifyalias ", "Modifies an existing alias configuration", {}, argumentHandler) .command("removealias ", "Removes an existing alias configuration", {}, argumentHandler) .command("databot [configjson]", "Starts, stops or aborts a databot instance", {}, argumentHandler) - .command("token ", "Get or revoke a token for a give alias", {}, argumentHandler) + .command("deploy ", "Deploys a databot abort->upload->start", {}, argumentHandler) .demandCommand(1, 1, "You need at least one command to run.") .option("a", { alias: "alias", @@ -194,7 +198,7 @@ const argv = require("yargs") .option("c", { alias: "credentials", nargs: 1, - describe: "Input credentials in base64", + describe: "TDX credentials {id:\"\",secret:\"\"} in base64", type: "string", requiresArg: true, }) diff --git a/src/command-handler.js b/src/command-handler.js index 23eea1c..c10a23d 100644 --- a/src/command-handler.js +++ b/src/command-handler.js @@ -8,7 +8,7 @@ const {getInfo} = require("./info"); const {runDatabotCommand} = require("./databot"); const {getAliasesArray} = require("./alias"); const {getSecretAliasName} = require("./utils"); - +const {deploy} = require("./deploy"); class CommandHandler { constructor({tdxConfig, secret, token, timeout}) { @@ -116,6 +116,11 @@ class CommandHandler { throw Error("Wrong input list type"); } } + + async deploy({id, configJson, filepath}) { + const api = await this.connect(); + return deploy({id, configJson, filepath, api}); + } } module.exports = CommandHandler; diff --git a/src/databot.js b/src/databot.js index 94ab954..eef9faa 100644 --- a/src/databot.js +++ b/src/databot.js @@ -1,27 +1,15 @@ const nqmUtils = require("@nqminds/nqm-core-utils"); const {readJsonFromFile} = require("./utils"); -function abortDatabot(api, id) { - return api.abortDatabotInstance(id); -} - -function stopDatabot(api, id) { - return api.stopDatabotInstance(id, nqmUtils.constants.stopDatabotInstance); -} - -function startDatabot({api, id, functionPayload}) { - return api.startDatabotInstance(id, functionPayload); -} - async function runDatabotCommand({api, command, id, configJson}) { switch (command) { case "start": const functionPayload = await readJsonFromFile(configJson); - return startDatabot({api, id, functionPayload}); + return api.startDatabotInstance(id, functionPayload); case "stop": - return stopDatabot(api, id); + return api.stopDatabotInstance(id, nqmUtils.constants.stopDatabotInstance); case "abort": - return abortDatabot(api, id); + return api.abortDatabotInstance(id); default: throw Error("Unknown databot command."); } diff --git a/src/deploy.js b/src/deploy.js new file mode 100644 index 0000000..dc15a84 --- /dev/null +++ b/src/deploy.js @@ -0,0 +1,19 @@ +const nqmUtils = require("@nqminds/nqm-core-utils"); +const {readJsonFromFile} = require("./utils"); +async function stop(api, id) { + try { + await api.stopDatabotInstance(id, nqmUtils.constants.stopDatabotInstance); + // eslint-disable-next-line no-empty + } catch (error) { + console.log(error); + } +} +async function deploy({id, configJson, filepath, api}) { + const functionPayload = await readJsonFromFile(configJson); + const databotInstanceId = functionPayload.id || ""; + await stop(api, databotInstanceId); +} + +module.exports = { + deploy, +}; diff --git a/tests/configs/deploy.json b/tests/configs/deploy.json new file mode 100644 index 0000000..0be63da --- /dev/null +++ b/tests/configs/deploy.json @@ -0,0 +1,13 @@ +{ + "inputs": { + "settings": {} + }, + "id": "instanceid", + "name": "somename", + "overwriteExisting": "instanceid", + "schedule": { + "always": true + }, + "shareKeyId": "someappid", + "shareKeySecret": "somesecret" +} \ No newline at end of file From de46488eca7d8f83e73bc440bc9b22ca19848c39 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 11 Feb 2020 20:06:37 +0000 Subject: [PATCH 2/6] wip: deploy --- config.app.json | 5 +++- main.js | 72 ++++++++++++++++++++++++++++++++----------------- src/deploy.js | 2 +- 3 files changed, 52 insertions(+), 27 deletions(-) diff --git a/config.app.json b/config.app.json index 15cbb42..41875f9 100644 --- a/config.app.json +++ b/config.app.json @@ -1,3 +1,6 @@ { - "scraperTimeout": 5000 + "scraperTimeout": 5000, + "tdxcliFoldername": ".tdxcli", + "envFilename": ".env", + "configFilename": "config.json" } \ No newline at end of file diff --git a/main.js b/main.js index bf4a586..22f6d54 100644 --- a/main.js +++ b/main.js @@ -30,26 +30,34 @@ const { const CommandHandler = require("./src"); const homePath = os.homedir(); -const tdxcliConfigPath = path.join(homePath, ".tdxcli"); -const envPath = path.join(tdxcliConfigPath, ".env"); -const configPath = path.join(tdxcliConfigPath, "config.json"); +const tdxcliConfigPath = path.join(homePath, appConfig.tdxcliFoldername); +const envPath = path.join(tdxcliConfigPath, appConfig.envFilename); +const configPath = path.join(tdxcliConfigPath, appConfig.configFilename); require("dotenv").config({path: envPath}); +async function getConfigs(commandlineConfigPath, configPath) { + if (commandlineConfigPath) { + return readJsonFromFile(commandlineConfigPath); + } else { + return readJsonFromFile(configPath); + } +} + async function argumentHandler(argv) { const command = argv._[0]; const commandProps = { alias: numberToString(argv.alias || ""), id: numberToString(argv.id || ""), secret: numberToString(argv.secret || ""), + resourceId: numberToString(argv.rid || ""), type: numberToString(argv.type || ""), command: numberToString(argv.command || ""), filepath: numberToString(argv.filepath || ""), - aliasName: numberToString(argv.aliasname || ""), - configJson: numberToString(argv.configjson || ""), - instanceId: numberToString(argv.instanceid || ""), - databotId: numberToString(argv.databotid || ""), + aliasName: numberToString(argv.name || ""), + configJson: numberToString(argv.config || ""), credentials: numberToString(argv.credentials || ""), + commandlineConfigPath: numberToString(argv["tdx-configs"] || ""), apiArgs: filterObjectByIdentifier(argv, "@"), apiArgsStringify: filterListByIdentifier(argv._.slice(1), "@"), }; @@ -61,15 +69,11 @@ async function run(commandName, commandProps) { let alias = commandProps.alias; let credentials = commandProps.credentials; const { - id, secret, type, command, filepath, - aliasName, configJson, apiArgs, apiArgsStringify, + id, secret, type, command, filepath, commandlineConfigPath, + aliasName, configJson, apiArgs, apiArgsStringify, resourceId, } = commandProps; try { - await mkdir(tdxcliConfigPath); - await createFile(envPath); - await createFile(configPath, JSON.stringify(defaultConfig, null, 2)); - if (alias === "") alias = envToAlias(process.env[TDX_CURRENT_ALIAS] || ""); if (credentials === "") credentials = process.env[TDX_CREDENTIALS] || ""; @@ -77,7 +81,11 @@ async function run(commandName, commandProps) { throw Error("No alias or wrong alias name. Only allowed [a-zA-Z0-9_]"); } - const tdxConfigs = await readJsonFromFile(configPath); + const tdxConfigs = await getConfigs(commandlineConfigPath, configPath); + if (!(alias in tdxConfigs) && (commandName !== "modifyalias")) { + throw Error(`No configuration found for alias=${alias}`); + } + const argumentSecret = {id, secret}; const configArgs = {tdxConfig: tdxConfigs[alias] || {}, timeout: appConfig.scraperTimeout}; let commandHandler; @@ -99,6 +107,11 @@ async function run(commandName, commandProps) { let output; switch (commandName) { case "signin": + // Create the .tdxcli folder in the home directory + await mkdir(tdxcliConfigPath); + await createFile(envPath); + await createFile(configPath, JSON.stringify(defaultConfig, null, 2)); + await commandHandler.signin(argumentSecret); setEnv({key: TDX_CURRENT_ALIAS, value: aliasToEnv(alias), envPath}); @@ -131,10 +144,10 @@ async function run(commandName, commandProps) { output = JSON.stringify(output, null, 2); break; case "download": - await commandHandler.download(id, filepath); + await commandHandler.download(resourceId, filepath); break; case "upload": - output = await commandHandler.upload(id, filepath); + output = await commandHandler.upload(resourceId, filepath); break; case "copyalias": await copyAliasConfig({tdxConfigs, alias, copyAliasName: aliasName, configPath}); @@ -146,7 +159,9 @@ async function run(commandName, commandProps) { output = "OK"; break; case "removealias": - if (alias === aliasName) throw Error("Can't remove the running alias."); + if (alias === aliasName) { + throw Error(`Can't remove the running alias=${alias}.`); + } await removeAliasConfig({tdxConfigs, aliasName, configPath}); output = "OK"; break; @@ -157,7 +172,7 @@ async function run(commandName, commandProps) { output = await commandHandler.runTokenCommand(command); break; case "deploy": - output = await commandHandler.deploy({id, configJson, filepath}); + output = await commandHandler.deploy({id, resourceId, configJson, filepath}); break; } @@ -180,13 +195,13 @@ const argv = require("yargs") .command("list [type]", "List all configured aliases or secrets", {}, argumentHandler) .command("token ", "Get or revoke a token for a give alias", {}, argumentHandler) .command("runapi ", "Run a tdx api command", {}, argumentHandler) - .command("download [filepath]", "Download resource", {}, argumentHandler) - .command("upload ", "Upload resource", {}, argumentHandler) - .command("copyalias ", "Makes a copy of an existing alias configuration", {}, argumentHandler) - .command("modifyalias ", "Modifies an existing alias configuration", {}, argumentHandler) - .command("removealias ", "Removes an existing alias configuration", {}, argumentHandler) - .command("databot [configjson]", "Starts, stops or aborts a databot instance", {}, argumentHandler) - .command("deploy ", "Deploys a databot abort->upload->start", {}, argumentHandler) + .command("download [filepath]", "Download resource", {}, argumentHandler) + .command("upload ", "Upload resource", {}, argumentHandler) + .command("copyalias ", "Makes a copy of an existing alias configuration", {}, argumentHandler) + .command("modifyalias ", "Modifies an existing alias configuration", {}, argumentHandler) + .command("removealias ", "Removes an existing alias configuration", {}, argumentHandler) + .command("databot [config]", "Starts, stops or aborts a databot instance", {}, argumentHandler) + .command("deploy ", "Deploys a databot stop->upload->start", {}, argumentHandler) .demandCommand(1, 1, "You need at least one command to run.") .option("a", { alias: "alias", @@ -202,6 +217,13 @@ const argv = require("yargs") type: "string", requiresArg: true, }) + .option("t", { + alias: "tdx-configs", + nargs: 1, + describe: "The path to the TDX config file", + type: "string", + requiresArg: true, + }) .help("h") .alias("h", "help") .alias("v", "version") diff --git a/src/deploy.js b/src/deploy.js index dc15a84..38df9c3 100644 --- a/src/deploy.js +++ b/src/deploy.js @@ -8,7 +8,7 @@ async function stop(api, id) { console.log(error); } } -async function deploy({id, configJson, filepath, api}) { +async function deploy({id, resourceId, configJson, filepath, api}) { const functionPayload = await readJsonFromFile(configJson); const databotInstanceId = functionPayload.id || ""; await stop(api, databotInstanceId); From 805ba2c17b0d1edc7ec6b63225231eea35fb5a64 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 14 Feb 2020 15:53:14 +0000 Subject: [PATCH 3/6] create config on signing --- main.js | 15 ++++++++++++--- src/command-handler.js | 5 +++++ tests/deploy-test/databot.zip | Bin 0 -> 1035 bytes tests/{configs => deploy-test}/deploy.json | 4 +--- 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 tests/deploy-test/databot.zip rename tests/{configs => deploy-test}/deploy.json (83%) diff --git a/main.js b/main.js index 22f6d54..03832cf 100644 --- a/main.js +++ b/main.js @@ -40,7 +40,12 @@ async function getConfigs(commandlineConfigPath, configPath) { if (commandlineConfigPath) { return readJsonFromFile(commandlineConfigPath); } else { - return readJsonFromFile(configPath); + try { + const output = await readJsonFromFile(configPath); + return output; + } catch (error) { + return {}; + } } } @@ -82,7 +87,7 @@ async function run(commandName, commandProps) { } const tdxConfigs = await getConfigs(commandlineConfigPath, configPath); - if (!(alias in tdxConfigs) && (commandName !== "modifyalias")) { + if (!(alias in tdxConfigs) && (!["signin", "modifyalias"].includes(commandName))) { throw Error(`No configuration found for alias=${alias}`); } @@ -111,12 +116,16 @@ async function run(commandName, commandProps) { await mkdir(tdxcliConfigPath); await createFile(envPath); await createFile(configPath, JSON.stringify(defaultConfig, null, 2)); + const newTdxConfigs = await readJsonFromFile(configPath); + commandHandler.setTdxConfig(newTdxConfigs[alias]); await commandHandler.signin(argumentSecret); setEnv({key: TDX_CURRENT_ALIAS, value: aliasToEnv(alias), envPath}); // Store the argument secret - if (argumentSecret.id) setEnv({key: getSecretAliasName(alias), value: jsonToBase64(argumentSecret), envPath}); + if (argumentSecret.id) { + setEnv({key: getSecretAliasName(alias), value: jsonToBase64(argumentSecret), envPath}); + } setEnv({key: getTokenAliasName(alias), value: commandHandler.getToken(), envPath}); output = "OK"; break; diff --git a/src/command-handler.js b/src/command-handler.js index c10a23d..f5db8c6 100644 --- a/src/command-handler.js +++ b/src/command-handler.js @@ -23,6 +23,11 @@ class CommandHandler { return this.accessToken; } + setTdxConfig({tokenHref = {}, config = {}}) { + this.tokenHref = tokenHref; + this.config = config; + } + async connect() { const api = await connect({ config: this.config, diff --git a/tests/deploy-test/databot.zip b/tests/deploy-test/databot.zip new file mode 100644 index 0000000000000000000000000000000000000000..336852f885aa89f3de8e2b69ce50880837760da8 GIT binary patch literal 1035 zcmWIWW@Zs#U|`^2;96kfnLjsc={80N23cm1hzvt!UP@|(URH5v2qy!xOZ&rc5H79Y zW?*D_0aOAeawqxb&oK~ad;g~^yqa@`wA12mK`ws1tHMHqb=O{5&3rgXH0M$O-+(Ru z_a-y1mZ@T_wE4W}{TYjwd$Q(S;aXepC~|kms*}5Qx0HXppYim?6Qez92ky$&y_>i1 zjoj-h&xS1$t&fs&&qZ7CuC&T^+cED#_Ui@KK5p-MBWD{Y>7BkF5S5Z@G&$Sym!m}! z2P<#9k&DHbLyu}1UuSf+G#k7*wOO~B%k`w9_q%Kh`6Cn7@h;u`baj&V`MUXeb8`OW zZ8EyIW=gpzw~O?}6Yp2@nmMtrK5HrZChe_u{po#Wn*}zrs#z}yUmY5t85SOx>3)s> z-B}IYja>YOEB^fY!+v~Th>gzeMES=i6O?D`PdVDyx#UZzMzzXkPWgBGt2kyst&U$z5V}@m{r~ymc`GK~m2}@_$YS;JB5UydSIgx$+W9M4&VSV$N*+kNM*25y>F?IIk$ca?zX+*2!LW!`ju7l^shSUN#SVP2G-LFsR%YuQ^5 z2ySaFyO$QF@V;d+_jKzAN6*jxKBsquNo!%?ympDbZ(c<`PRv?$ZD!Qm)$S|*SFX}> ztXuw2gk4-nbJw#V!9LlW*W<)xg*EgoioCzxv~^w*6uZ@MdI^W5$)OB!JnCfdLrW3`-h8EJP+_g=8|c42EtRYGfgs c_5)}rYSiH}k(CW(GZPRl0Menryv)D=0Q@nU*#H0l literal 0 HcmV?d00001 diff --git a/tests/configs/deploy.json b/tests/deploy-test/deploy.json similarity index 83% rename from tests/configs/deploy.json rename to tests/deploy-test/deploy.json index 0be63da..d2b095b 100644 --- a/tests/configs/deploy.json +++ b/tests/deploy-test/deploy.json @@ -1,7 +1,5 @@ { - "inputs": { - "settings": {} - }, + "inputs": {}, "id": "instanceid", "name": "somename", "overwriteExisting": "instanceid", From afc746a3df53a2273109e722cd2a17f8aca47f77 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 14 Feb 2020 16:15:39 +0000 Subject: [PATCH 4/6] wip: deploy tests --- tests/deploy-test/deploy.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/deploy-test/deploy.json b/tests/deploy-test/deploy.json index d2b095b..b3c7d6e 100644 --- a/tests/deploy-test/deploy.json +++ b/tests/deploy-test/deploy.json @@ -1,11 +1,11 @@ { "inputs": {}, - "id": "instanceid", - "name": "somename", - "overwriteExisting": "instanceid", + "id": "ryK7fHNX8", + "name": "test-databot 1", + "overwriteExisting": "ryK7fHNX8", "schedule": { "always": true }, - "shareKeyId": "someappid", - "shareKeySecret": "somesecret" + "shareKeyId": "mereacre@gmail.com/tdx.nqminds.com", + "shareKeySecret": "" } \ No newline at end of file From ca457ad7a940322e34a743229bc46168fc5072cb Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 17 Feb 2020 16:45:13 +0000 Subject: [PATCH 5/6] Added deploy command --- CHANGELOG.md | 9 +++ README.md | 108 +++++++++++++++++++++------------- config.default.json | 2 + main.js | 7 ++- package.json | 2 +- src/command-handler.js | 8 +-- src/deploy.js | 10 +++- src/info.js | 11 +++- tests/deploy-test/deploy.json | 2 +- 9 files changed, 107 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 081fa9d..f34b130 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,15 @@ The format is based on and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.0] - 2020-02-17 + +### Changed + - Added databot deploy command. + - Added shortening of the command line arguments. + - Added get app url command. + +### Fixed + ## [0.2.8] - 2020-02-11 ### Changed diff --git a/README.md b/README.md index 923752e..b48f20f 100644 --- a/README.md +++ b/README.md @@ -32,23 +32,25 @@ The client app can be accessed by running the command ```tdxcli```. Usage: tdxcli [options] Commands: - tdxcli signin [id] [secret] Sign in to tdx - tdxcli signout Sign out of tdx - tdxcli info [type] [id] Output current account info - tdxcli config Output tdx config - tdxcli list [type] List all configured aliases or secrets - tdxcli runapi Run a tdx api command - tdxcli download [filepath] Download resource - tdxcli upload Upload resource - tdxcli copyalias Makes a copy of an existing alias configuration - tdxcli modifyalias Modifies an existing alias configuration - tdxcli removealias Removes an existing alias configuration - tdxcli databot [configjson] Starts, stops or aborts a databot instance - tdxcli token Get or revoke a token for a give alias + tdxcli signin [id] [secret] Sign in to tdx + tdxcli signout Sign out of tdx + tdxcli info [type] [id] Output current account info + tdxcli config Output tdx config + tdxcli list [type] List all configured aliases or secrets + tdxcli token Get or revoke a token for a give alias + tdxcli runapi Run a tdx api command + tdxcli download [filepath] Download resource + tdxcli upload Upload resource + tdxcli copyalias Makes a copy of an existing alias configuration + tdxcli modifyalias Modifies an existing alias configuration + tdxcli removealias Removes an existing alias configuration + tdxcli databot [config] Starts, stops or aborts a databot instance + tdxcli deploy Deploys a databot stop->upload->start Options: -a, --alias Alias name [string] - -c, --credentials Input credentials in base64 [string] + -c, --credentials TDX credentials {id:"",secret:""} in base64 [string] + -t, --tdx-configs The path to the TDX config file [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] ``` @@ -74,6 +76,41 @@ tdxcli list credentials ``` The output of the last command will show the credentials under the alias name ```name```. +### Tdx config file +One can also pass a custom tdx config file with param ```--tdx-config``` as follows: +```bash +tdxcli commandtoexecute ...variousparams --alias=name --tdx-config=pathtoconfig +``` + +The config file contains the tdx configuratin for each defined alias as follows: +```json +{ + "nqminds": { + "tokenHref": "https://tbx.nqminds.com", + "config": { + "commandServer": "https://cmd.nqminds.com", + "ddpServer": "https://ddp.nqminds.com", + "queryServer": "https://q.nqminds.com", + "tdxServer": "https://tdx.nqminds.com", + "databotServer": "http://databot.nqminds.com", + "accessTokenTTL": 31622400 + } + }, + "nq_m": { + "tokenHref": "https://tbx.nq-m.com", + "config": { + "commandServer": "https://cmd.nq-m.com", + "ddpServer": "https://ddp.nq-m.com", + "queryServer": "https://q.nq-m.com", + "tdxServer": "https://tdx.nq-m.com", + "databotServer": "http://databot.nq-m.com", + "accessTokenTTL": 31622400 + } + } +} +``` +In the above example there are two defined aliases ```nqminds``` and ```nq-m```. + ### ```signin``` Usage ```bash @@ -89,32 +126,7 @@ tdxcli signin --alias=nqminds tdxcli signin emailorsharetokenid thesecret --alias=nq_m ``` -The aliases configurations are stored in ```config.json```: -```json - "tdxConfigs": { - "nqminds": { - "tokenHref": "https://tbx.nqminds.com", - "config": { - "commandServer": "https://cmd.nqminds.com", - "ddpServer": "https://ddp.nqminds.com", - "queryServer": "https://q.nqminds.com", - "tdxServer": "https://tdx.nqminds.com", - "accessTokenTTL": 31622400 - } - }, - "nq_m": { - "tokenHref": "https://tbx.nq-m.com", - "config": { - "commandServer": "https://cmd.nq-m.com", - "ddpServer": "https://ddp.nq-m.com", - "queryServer": "https://q.nq-m.com", - "tdxServer": "https://tdx.nq-m.com", - "accessTokenTTL": 31622400 - } - } - } -``` -An new alias can be copied from an existing alias, it can be modified or removed. +Note, the aliases configurations are stored in ```config.json``` in home folder ```.tdxcli``` of the user. A new alias can be copied from an existing alias, it can be modified or removed. The ```tdxcli signin``` allows storing access tokens and secrets for every configured alias. So, that the user can change among them by providing the ```tdxcli signin --alias=name``` option. @@ -142,6 +154,7 @@ tdxcli info tdxcli info account tdxcli info serverfolderid appid tdxcli info databotsid +tdxcli info appurl instanceid ``` The above command can also be run with the ```--alias``` option. @@ -151,6 +164,8 @@ The above command can also be run with the ```--alias``` option. ```tdxcli info databotsid``` will return all databot ids. +```tdxcli info appurl instanceid``` will return the app url for databot with instance ```instanceid```. + ## ```config``` Usage ```bash @@ -281,4 +296,15 @@ Usage tdxcli token get ``` -The command returns the access token for a the default alias or an alias passed with ```--alias```. \ No newline at end of file +The command returns the access token for a the default alias or an alias passed with ```--alias```. + +## ```deploy``` +Usage +```bash +tdxcli deploy databotid resourceid databot.json filetoupload +``` + +The above command will deploy a databot with the following steps: +[1] Will stop a running databot instance with the databot instance id from config file ```databot.json```. +[2] Will upload the file ```filetoupload``` to tdx resource id ```resourceid```. +[3] Will start a new databot instance id for the databot ```databotid```. \ No newline at end of file diff --git a/config.default.json b/config.default.json index bafd104..87baf65 100644 --- a/config.default.json +++ b/config.default.json @@ -6,6 +6,7 @@ "ddpServer": "https://ddp.nqminds.com", "queryServer": "https://q.nqminds.com", "tdxServer": "https://tdx.nqminds.com", + "databotServer": "http://databot.nqminds.com", "accessTokenTTL": 31622400 } }, @@ -16,6 +17,7 @@ "ddpServer": "https://ddp.nq-m.com", "queryServer": "https://q.nq-m.com", "tdxServer": "https://tdx.nq-m.com", + "databotServer": "http://databot.nq-m.com", "accessTokenTTL": 31622400 } } diff --git a/main.js b/main.js index 03832cf..9b6e8e8 100644 --- a/main.js +++ b/main.js @@ -135,7 +135,11 @@ async function run(commandName, commandProps) { setEnv({key: getSecretAliasName(alias), value: "", envPath}); break; case "info": - output = await commandHandler.getInfo({id, type}); + output = await commandHandler.getInfo({ + id, + type, + tdxConfig: tdxConfigs[alias] || {}, + }); break; case "config": output = tdxConfigs[alias] || {}; @@ -182,6 +186,7 @@ async function run(commandName, commandProps) { break; case "deploy": output = await commandHandler.deploy({id, resourceId, configJson, filepath}); + output = JSON.stringify(output, null, 2); break; } diff --git a/package.json b/package.json index 70a81bb..d95c4c2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nqminds/nqm-tdx-terminal-cli", - "version": "0.2.8", + "version": "1.0.0", "description": "Command-line interface for accessing the TDX API", "main": "main.js", "directories": { diff --git a/src/command-handler.js b/src/command-handler.js index f5db8c6..b28f516 100644 --- a/src/command-handler.js +++ b/src/command-handler.js @@ -74,9 +74,9 @@ class CommandHandler { return runApi({command, apiArgs, apiArgsStringify, api}); } - async getInfo({id, type}) { + async getInfo({id, type, tdxConfig}) { const api = await this.connect(); - return getInfo({api, type, id}); + return getInfo({api, type, id, tdxConfig}); } async download(id, filepath) { @@ -122,9 +122,9 @@ class CommandHandler { } } - async deploy({id, configJson, filepath}) { + async deploy({id, resourceId, configJson, filepath}) { const api = await this.connect(); - return deploy({id, configJson, filepath, api}); + return deploy({id, resourceId, configJson, filepath, api}); } } diff --git a/src/deploy.js b/src/deploy.js index 38df9c3..1155ca5 100644 --- a/src/deploy.js +++ b/src/deploy.js @@ -1,17 +1,21 @@ const nqmUtils = require("@nqminds/nqm-core-utils"); const {readJsonFromFile} = require("./utils"); +const {uploadResource} = require("./upload"); + async function stop(api, id) { try { await api.stopDatabotInstance(id, nqmUtils.constants.stopDatabotInstance); // eslint-disable-next-line no-empty } catch (error) { - console.log(error); + // console.log(error); } } async function deploy({id, resourceId, configJson, filepath, api}) { - const functionPayload = await readJsonFromFile(configJson); - const databotInstanceId = functionPayload.id || ""; + const startPayload = await readJsonFromFile(configJson); + const databotInstanceId = startPayload.id || ""; await stop(api, databotInstanceId); + await uploadResource({id: resourceId, filepath, api}); + return api.startDatabotInstance(id, startPayload); } module.exports = { diff --git a/src/info.js b/src/info.js index d4749c2..d883a11 100644 --- a/src/info.js +++ b/src/info.js @@ -20,7 +20,14 @@ async function getDatabotsIds(api) { return JSON.stringify(result, 0, 2); } -async function getInfo({api, id = "", type = ""}) { +async function getAppUrl({api, id, tdxConfig}) { + const instance = await api.getDatabotInstance(id); + const urlProtocol = tdxConfig.config.tdxServer.split(":")[0]; + const urlComponents = tdxConfig.config.tdxServer.split("."); + return `${urlProtocol}://${instance.subDomain}.${urlComponents.slice(1).join(".")}`; +} + +async function getInfo({api, id = "", type = "", tdxConfig}) { switch (type) { case "": case "account": @@ -29,6 +36,8 @@ async function getInfo({api, id = "", type = ""}) { return getServerFolderId(id); case "databotsid": return getDatabotsIds(api); + case "appurl": + return getAppUrl({api, id, tdxConfig}); default: throw Error("Unknow info type term.") } diff --git a/tests/deploy-test/deploy.json b/tests/deploy-test/deploy.json index b3c7d6e..b518c57 100644 --- a/tests/deploy-test/deploy.json +++ b/tests/deploy-test/deploy.json @@ -6,6 +6,6 @@ "schedule": { "always": true }, - "shareKeyId": "mereacre@gmail.com/tdx.nqminds.com", + "shareKeyId": "mereacre@nquiringminds.com/tdx.nqminds.com", "shareKeySecret": "" } \ No newline at end of file From 6fbd16af77d30e7cdc93405d9d34089316e20bd4 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 17 Feb 2020 16:47:08 +0000 Subject: [PATCH 6/6] cleanup --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b48f20f..713fa25 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ One can also pass a custom tdx config file with param ```--tdx-config``` as foll tdxcli commandtoexecute ...variousparams --alias=name --tdx-config=pathtoconfig ``` -The config file contains the tdx configuratin for each defined alias as follows: +The config file contains the tdx configuration for each defined alias as follows: ```json { "nqminds": { @@ -305,6 +305,9 @@ tdxcli deploy databotid resourceid databot.json filetoupload ``` The above command will deploy a databot with the following steps: + [1] Will stop a running databot instance with the databot instance id from config file ```databot.json```. + [2] Will upload the file ```filetoupload``` to tdx resource id ```resourceid```. + [3] Will start a new databot instance id for the databot ```databotid```. \ No newline at end of file