From f1ca0d9e7b048c64da82cc16151680ff41f71f3e Mon Sep 17 00:00:00 2001 From: Ran Date: Tue, 2 Aug 2022 21:09:20 +0800 Subject: [PATCH 1/4] add devTier.js to add dev tier curl Signed-off-by: Ran --- src/devTier.js | 11 +++++++++++ src/main.js | 6 ++++++ 2 files changed, 17 insertions(+) create mode 100644 src/devTier.js diff --git a/src/devTier.js b/src/devTier.js new file mode 100644 index 0000000..ee18214 --- /dev/null +++ b/src/devTier.js @@ -0,0 +1,11 @@ +const fs = require("fs"); + +function devTier(json_file) { + const schema = JSON.parse(fs.readFileSync(json_file, 'utf8')); + schema["paths"]["/api/v1/projects/{project_id}/clusters"]["post"]["x-code-samples"][0]["lang"] = "curl for Dedicated Tier"; + schema["paths"]["/api/v1/projects/{project_id}/clusters"]["post"]["x-code-samples"].push({"lang": "curl for Developer Tier", "source": "dev tier curl example"}); + fs.writeFileSync(json_file, JSON.stringify(schema, null, 2)); + console.log(`Add dev tier to ${json_file}`); +} + +module.exports = devTier; diff --git a/src/main.js b/src/main.js index ec4dc2c..f80c238 100644 --- a/src/main.js +++ b/src/main.js @@ -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") @@ -31,4 +33,8 @@ program.command("gencode") .description("Generate sample code to JSON as x-code-samples") .argument("", "Target JSON file") .action(genSampleCode); +program.command("devtier") + .description("Add sample for creating a dev tier cluster") + .argument(" Date: Wed, 3 Aug 2022 13:45:19 +0800 Subject: [PATCH 2/4] add example curl Signed-off-by: Ran --- src/devTier.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devTier.js b/src/devTier.js index ee18214..9499b4a 100644 --- a/src/devTier.js +++ b/src/devTier.js @@ -3,7 +3,7 @@ const fs = require("fs"); function devTier(json_file) { const schema = JSON.parse(fs.readFileSync(json_file, 'utf8')); schema["paths"]["/api/v1/projects/{project_id}/clusters"]["post"]["x-code-samples"][0]["lang"] = "curl for Dedicated Tier"; - schema["paths"]["/api/v1/projects/{project_id}/clusters"]["post"]["x-code-samples"].push({"lang": "curl for Developer Tier", "source": "dev tier curl example"}); + schema["paths"]["/api/v1/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/v1/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}`); } From c6e67788d4af95a989a91f44224008bce1281b91 Mon Sep 17 00:00:00 2001 From: Ran Date: Wed, 3 Aug 2022 13:48:15 +0800 Subject: [PATCH 3/4] use v1beta Signed-off-by: Ran --- src/devTier.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devTier.js b/src/devTier.js index 9499b4a..16f5db1 100644 --- a/src/devTier.js +++ b/src/devTier.js @@ -2,8 +2,8 @@ const fs = require("fs"); function devTier(json_file) { const schema = JSON.parse(fs.readFileSync(json_file, 'utf8')); - schema["paths"]["/api/v1/projects/{project_id}/clusters"]["post"]["x-code-samples"][0]["lang"] = "curl for Dedicated Tier"; - schema["paths"]["/api/v1/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/v1/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\"}]}}}'"}); + 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/v1/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}`); } From 2d7d4a5e40c18ab37b1b25c96a48e71f39c95818 Mon Sep 17 00:00:00 2001 From: Ran Date: Wed, 3 Aug 2022 13:51:55 +0800 Subject: [PATCH 4/4] Update src/devTier.js Co-authored-by: Aolin --- src/devTier.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devTier.js b/src/devTier.js index 16f5db1..de896cb 100644 --- a/src/devTier.js +++ b/src/devTier.js @@ -3,7 +3,7 @@ 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/v1/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\"}]}}}'"}); + 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}`); }