From 95179059dec05fee1eaa2863a93af90076d34aa0 Mon Sep 17 00:00:00 2001 From: comyan <1628126452@qq.com> Date: Mon, 18 Oct 2021 11:24:04 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E4=B8=83=E7=89=9B=E4=BA=91?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0ssl=E8=AF=81=E4=B9=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dsl/upload_ssl_node_def.yml | 37 ++++++++++++++++++++++++++ scripts/upload_ssl.js | 53 +++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 dsl/upload_ssl_node_def.yml create mode 100644 scripts/upload_ssl.js diff --git a/dsl/upload_ssl_node_def.yml b/dsl/upload_ssl_node_def.yml new file mode 100644 index 0000000..096c225 --- /dev/null +++ b/dsl/upload_ssl_node_def.yml @@ -0,0 +1,37 @@ +ref: tanglongyan/qiniu_ssl_upload +version: 1.0.0 +resultFile: /tmp/resultFile +inputParameters: + - name: 证书路径 + ref: certificate_path + value: '/root/tmp/fullchain.cer' + description: 证书路径 + type: STRING + - name: 证书密钥路径 + ref: certificate_key_path + value: '/root/tmp/test.huangxi.asia.key' + description: 证书密钥路径 + type: STRING + - name: 域名 + ref: domain + value: 'test.huangxi.asia' + description: 域名 + type: STRING + - name: 七牛accessKey + ref: qiniu_access_key + value: '' + description: 七牛accessKey + type: SECRET + - name: 七牛secretKey + ref: qiniu_secret_key + value: '' + description: 七牛secretKey + type: SECRET +outputParameters: + - name: 证书上传七牛云成功后生成的证书id + ref: cert_id + value: '' + type: STRING + description: 证书上传七牛云成功后生成的证书id +spec: + image: 'jianmudev/jianmu-runner-qiniu:1.1.0' diff --git a/scripts/upload_ssl.js b/scripts/upload_ssl.js new file mode 100644 index 0000000..167d7d8 --- /dev/null +++ b/scripts/upload_ssl.js @@ -0,0 +1,53 @@ +const fs = require('fs'); +const axios = require('axios'); +require('dotenv').config({ path: '.env.example' }); +const url = 'https://api.qiniu.com/sslcert'; +// 生成七牛管理凭证 +const createToken = function () { + const qiniu = require('qiniu'); + const mac = new qiniu.auth.digest.Mac( + process.env.JIANMU_QINIU_ACCESSKEY, + process.env.JIANMU_QINIU_SECRETKEY + ); + function uptoken() { + return qiniu.util.generateAccessToken(mac, url); + } + // 生成上传 Token + const token = uptoken(); + // console.log(token) +}; +createToken(); + +const instance = axios.create(); +const ca = fs.readFileSync(process.env.JIANMU_CERTIFICATE_PATH, 'utf-8'); +const pri = fs.readFileSync(process.env.JIANMU_CERTIFICATE_KEY_PATH, 'utf-8'); +const params = { + name: process.env.JIANMU_DOMAIN, + common_name: process.env.JIANMU_DOMAIN, + pri, + ca, +}; +(() => { + instance + .post(url, params, { + headers: { + 'Content-Type': 'application/json; charset=utf-8', + Authorization: + 'QBox sHOM6lTRDB0gjO1LK2ygJup1UuAGzHs4EQmkNTwQ:eVAQYiDRDhxsT-6yPYR6VVW0pnQ=', + }, + }) + .then(result => { + console.log('证书id:', result.data); + const certID = { + cert_id: result.data.certID, + }; + fs.writeFileSync('/tmp/resultFile', JSON.stringify(certID), 'utf-8'); + }) + .catch(err => { + console.log(err.response.status); + console.log(err.response.statusText); + console.log(err.response.headers); + console.log(err.response.data); + process.exit(1); + }); +})(); -- Gitee From 1462439ce108c5a55d74209fe2d1797438c1c531 Mon Sep 17 00:00:00 2001 From: comyan <1628126452@qq.com> Date: Mon, 18 Oct 2021 11:44:48 +0800 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20=E7=94=9F=E6=88=90token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/upload_ssl.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/upload_ssl.js b/scripts/upload_ssl.js index 167d7d8..25e4def 100644 --- a/scripts/upload_ssl.js +++ b/scripts/upload_ssl.js @@ -13,10 +13,8 @@ const createToken = function () { return qiniu.util.generateAccessToken(mac, url); } // 生成上传 Token - const token = uptoken(); - // console.log(token) + return uptoken(); }; -createToken(); const instance = axios.create(); const ca = fs.readFileSync(process.env.JIANMU_CERTIFICATE_PATH, 'utf-8'); @@ -32,8 +30,7 @@ const params = { .post(url, params, { headers: { 'Content-Type': 'application/json; charset=utf-8', - Authorization: - 'QBox sHOM6lTRDB0gjO1LK2ygJup1UuAGzHs4EQmkNTwQ:eVAQYiDRDhxsT-6yPYR6VVW0pnQ=', + Authorization: createToken(), }, }) .then(result => { -- Gitee From da5d3d88817c7d143ca493114101b3019ae3cc37 Mon Sep 17 00:00:00 2001 From: comyan <1628126452@qq.com> Date: Mon, 18 Oct 2021 13:47:47 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20=E5=8E=BB=E6=8E=89=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=9A=84=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 12 ------------ scripts/upload_ssl.js | 6 ++---- 2 files changed, 2 insertions(+), 16 deletions(-) delete mode 100644 .env.example diff --git a/.env.example b/.env.example deleted file mode 100644 index cfbeccd..0000000 --- a/.env.example +++ /dev/null @@ -1,12 +0,0 @@ -# 七牛bucket -JIANMU_QINIU_BUCKET= -# 七牛accessKey -JIANMU_QINIU_AK= -# 七牛secretKey -JIANMU_QINIU_SK= -# 七牛zone,可选参数,不设置时,自动识别 -JIANMU_QINIU_ZONE= -# 上传后的路径前缀 -JIANMU_QINIU_UPLOAD_URI_PREFIX= -# 要上传的目录 -JIANMU_QINIU_UPLOAD_DIR= \ No newline at end of file diff --git a/scripts/upload_ssl.js b/scripts/upload_ssl.js index 25e4def..b5baa3b 100644 --- a/scripts/upload_ssl.js +++ b/scripts/upload_ssl.js @@ -1,13 +1,12 @@ const fs = require('fs'); const axios = require('axios'); -require('dotenv').config({ path: '.env.example' }); const url = 'https://api.qiniu.com/sslcert'; // 生成七牛管理凭证 const createToken = function () { const qiniu = require('qiniu'); const mac = new qiniu.auth.digest.Mac( - process.env.JIANMU_QINIU_ACCESSKEY, - process.env.JIANMU_QINIU_SECRETKEY + process.env.JIANMU_QINIU_ACCESS_KEY, + process.env.JIANMU_QINIU_SECRET_KEY ); function uptoken() { return qiniu.util.generateAccessToken(mac, url); @@ -15,7 +14,6 @@ const createToken = function () { // 生成上传 Token return uptoken(); }; - const instance = axios.create(); const ca = fs.readFileSync(process.env.JIANMU_CERTIFICATE_PATH, 'utf-8'); const pri = fs.readFileSync(process.env.JIANMU_CERTIFICATE_KEY_PATH, 'utf-8'); -- Gitee From 8bc811baeeb4256aefea53b15734268bba8c6ee2 Mon Sep 17 00:00:00 2001 From: comyan <1628126452@qq.com> Date: Mon, 18 Oct 2021 13:58:34 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/upload_ssl.js | 56 ++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/scripts/upload_ssl.js b/scripts/upload_ssl.js index b5baa3b..44fa33e 100644 --- a/scripts/upload_ssl.js +++ b/scripts/upload_ssl.js @@ -1,6 +1,7 @@ const fs = require('fs'); const axios = require('axios'); const url = 'https://api.qiniu.com/sslcert'; +const encoding = 'utf-8'; // 生成七牛管理凭证 const createToken = function () { const qiniu = require('qiniu'); @@ -8,41 +9,36 @@ const createToken = function () { process.env.JIANMU_QINIU_ACCESS_KEY, process.env.JIANMU_QINIU_SECRET_KEY ); - function uptoken() { - return qiniu.util.generateAccessToken(mac, url); - } // 生成上传 Token - return uptoken(); + return qiniu.util.generateAccessToken(mac, url); }; -const instance = axios.create(); -const ca = fs.readFileSync(process.env.JIANMU_CERTIFICATE_PATH, 'utf-8'); -const pri = fs.readFileSync(process.env.JIANMU_CERTIFICATE_KEY_PATH, 'utf-8'); +const ca = fs.readFileSync(process.env.JIANMU_CERTIFICATE_PATH, encoding); +const pri = fs.readFileSync(process.env.JIANMU_CERTIFICATE_KEY_PATH, encoding); const params = { name: process.env.JIANMU_DOMAIN, common_name: process.env.JIANMU_DOMAIN, pri, ca, }; -(() => { - instance - .post(url, params, { - headers: { - 'Content-Type': 'application/json; charset=utf-8', - Authorization: createToken(), - }, - }) - .then(result => { - console.log('证书id:', result.data); - const certID = { - cert_id: result.data.certID, - }; - fs.writeFileSync('/tmp/resultFile', JSON.stringify(certID), 'utf-8'); - }) - .catch(err => { - console.log(err.response.status); - console.log(err.response.statusText); - console.log(err.response.headers); - console.log(err.response.data); - process.exit(1); - }); -})(); +axios + .create() + .post(url, params, { + headers: { + 'Content-Type': `application/json; charset=${encoding}`, + Authorization: createToken(), + }, + }) + .then(result => { + console.log('证书id:', result.data); + const certID = { + cert_id: result.data.certID, + }; + fs.writeFileSync('/tmp/resultFile', JSON.stringify(certID), encoding); + }) + .catch(err => { + console.log(err.response.status); + console.log(err.response.statusText); + console.log(err.response.headers); + console.log(err.response.data); + process.exit(1); + }); -- Gitee From 5b4fd8007db85a4310ac32ee0d35a93b50778376 Mon Sep 17 00:00:00 2001 From: comyan <1628126452@qq.com> Date: Mon, 18 Oct 2021 14:21:32 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20dsl=20ref=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dsl/upload_ssl_node_def.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dsl/upload_ssl_node_def.yml b/dsl/upload_ssl_node_def.yml index 096c225..e21094a 100644 --- a/dsl/upload_ssl_node_def.yml +++ b/dsl/upload_ssl_node_def.yml @@ -1,4 +1,4 @@ -ref: tanglongyan/qiniu_ssl_upload +ref: qiniu_ssl_upload version: 1.0.0 resultFile: /tmp/resultFile inputParameters: -- Gitee