Skip to content

Commit

Permalink
Merge pull request #11 from ran-huang/add-2-sample
Browse files Browse the repository at this point in the history
add devTier.js to add dev tier curl
  • Loading branch information
Oreoxmt authored Aug 3, 2022
2 parents 2348f30 + 2d7d4a5 commit 1422aec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/devTier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require("fs");

function devTier(json_file) {
const schema = JSON.parse(fs.readFileSync(json_file, 'utf8'));
schema["paths"]["/api/v1beta/projects/{project_id}/clusters"]["post"]["x-code-samples"][0]["lang"] = "curl for Dedicated Tier";
schema["paths"]["/api/v1beta/projects/{project_id}/clusters"]["post"]["x-code-samples"].push({"lang": "curl for Developer Tier", "source": "curl --digest \\\n --user 'YOUR_PUBLIC_KEY:YOUR_PRIVATE_KEY' \\\n --request POST \\\n --url https://api.tidbcloud.com/api/v1beta/projects/{project_id}/clusters \\\n --header 'content-type: application/json' \\\n --data '{\"name\":\"Cluster0\",\"cluster_type\":\"SHARED\",\"cloud_provider\":\"AWS\",\"region\":\"us-west-2\",\"config\":{\"root_password\":\"password_example\",\"ip_access_list\":{\"items\":[{\"cidr\":\"8.8.8.8/32\",\"description\":\"My IP Address\"}]}}}'"});
fs.writeFileSync(json_file, JSON.stringify(schema, null, 2));
console.log(`Add dev tier to ${json_file}`);
}

module.exports = devTier;
6 changes: 6 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const deref = require("./deref.js");
const importMd = require("./importmd.js");
const addLogo = require("./addlogo.js");
const genSampleCode = require("./gencode.js");
const devTier = require("./devTier.js");

const program = new Command();
program
.name("postprocess")
Expand Down Expand Up @@ -31,4 +33,8 @@ program.command("gencode")
.description("Generate sample code to JSON as x-code-samples")
.argument("<in-filename>", "Target JSON file")
.action(genSampleCode);
program.command("devtier")
.description("Add sample for creating a dev tier cluster")
.argument("<in-filename", "Target JSON file")
.action(devTier)
program.parse();

0 comments on commit 1422aec

Please sign in to comment.