From 65390ce8d3690d30cf0a9112bb26746fedd49d97 Mon Sep 17 00:00:00 2001 From: Dulana Peiris <57042272+du1ana@users.noreply.github.com> Date: Thu, 7 Dec 2023 20:21:08 +0530 Subject: [PATCH] Added env variable to enable sashi create (#305) --- mb-xrpl/lib/sashi-cli.js | 8 +++++++- sashi-cli/main.cpp | 22 ++++++++++++++++++++++ test/vm-cluster/cluster.sh | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/mb-xrpl/lib/sashi-cli.js b/mb-xrpl/lib/sashi-cli.js index 6c0616a..b57ad4c 100644 --- a/mb-xrpl/lib/sashi-cli.js +++ b/mb-xrpl/lib/sashi-cli.js @@ -49,7 +49,13 @@ class SashiCLI { execSashiCli(msg) { this.#waiting = true; return new Promise((resolve, reject) => { - exec(`${this.cliPath} json -m '${JSON.stringify(msg)}'`, { stdio: 'pipe' }, (err, stdout, stderr) => { + let command = `${this.cliPath} json -m '${JSON.stringify(msg)}'`; + + if (msg.type === "create") { + command = `DEV_MODE=1 ${command}`; + } + + exec(command, { stdio: 'pipe' }, (err, stdout, stderr) => { this.#waiting = false; if (err || stderr) { diff --git a/sashi-cli/main.cpp b/sashi-cli/main.cpp index 1c2fa35..208094d 100644 --- a/sashi-cli/main.cpp +++ b/sashi-cli/main.cpp @@ -5,6 +5,8 @@ #include "cli-manager.hpp" #include "version.hpp" +#define DEV_MODE "DEV_MODE" + std::string exec_dir; /** @@ -90,6 +92,7 @@ int parse_cmd(int argc, char **argv) std::string json_message; json->add_option("-m,--message", json_message, "JSON message"); + create->group(""); //Hides 'create' command from help-all std::string owner, contract_id, image, outbound_ipv6, outbound_net_interface; create->add_option("-o,--owner", owner, "Hex (ed-prefixed) public key of the instance owner"); create->add_option("-c,--contract-id", contract_id, "Contract Id (GUID) of the instance"); @@ -126,6 +129,25 @@ int parse_cmd(int argc, char **argv) } // Verifying subcommands. + + bool is_dev_mode = (getenv(DEV_MODE) != nullptr); + + if (!is_dev_mode) + { + if(create->parsed()){ + std::cout << "Developer mode must be enabled to access this command." << std::endl; + return -1; + } + if(json->parsed()){ + jsoncons::json json_data = jsoncons::json::parse(json_message); + if (json_data.contains("type") && json_data["type"].as_string() == "create") + { + std::cout << "Developer mode must be enabled to access this command." << std::endl; + return -1; + } + } + } + if (version->parsed()) { std::cout << "Sashimono CLI version " << version::CLI_VERSION << std::endl; diff --git a/test/vm-cluster/cluster.sh b/test/vm-cluster/cluster.sh index f6924d5..ffb5b3f 100755 --- a/test/vm-cluster/cluster.sh +++ b/test/vm-cluster/cluster.sh @@ -473,7 +473,7 @@ if [ $mode == "create" ] || [ $mode == "createall" ]; then config=$(echo "$config" | jq -c ".mesh.known_peers = [$peers]" | jq -c ".contract.unl = [\"$pubkey\"]") fi - command="sashi json -m '{\"type\":\"create\",\"owner_pubkey\":\"$ownerpubkey\",\"contract_id\":\"$contractid\",\"image\":\"$image\",\"config\":$config}'" + command="DEV_MODE=1 sashi json -m '{\"type\":\"create\",\"owner_pubkey\":\"$ownerpubkey\",\"contract_id\":\"$contractid\",\"image\":\"$image\",\"config\":$config}'" output=$(sshskp $sshuser@$hostaddr $command | tr '\0' '\n') # If an output received consider updating the json file. if [ ! "$output" = "" ]; then