This commit is contained in:
Sven Sauleau 2023-02-09 17:23:45 +00:00
parent 179aa61048
commit 9760ebbb68
2 changed files with 48 additions and 3 deletions

View File

@ -0,0 +1,45 @@
import { API_TOKEN_TEMPLATE } from "./generate-one-click-deploy-button.mjs"
import https from "node:https"
const token = process.argv[2]
function get(url) {
return new Promise(resolve => {
const opts = {
headers: {
'Authorization': 'Bearer ' + token,
'Accept': 'application/json',
}
};
console.log({ opts });
https.get(url, opts, res => {
res.setEncoding('utf8');
let body = "";
res.on('data', function (chunk) {
body += chunk;
});
res.on('end', () => {
resolve({ body: JSON.parse(body), statusCode: res.statusCode })
})
})
})
}
async function getTokenId() {
try {
const res = await get('https://api.cloudflare.com/client/v4/user/tokens/verify')
console.log('statusCode:', res.statusCode);
console.log('statusCode:', JSON.stringify(res.body, 2, 2));
} catch (err) {
throw new Error("failed to get token id: " + err)
}
}
await getTokenId()
// console.log({ API_TOKEN_TEMPLATE });

View File

@ -28,7 +28,7 @@ const FIELDS = [
},
]
const API_TOKEN_TEMPLATE = JSON.stringify([
export const API_TOKEN_TEMPLATE = [
{ key: 'd1', type: 'edit' },
{ key: 'page', type: 'edit' },
{ key: 'images', type: 'edit' },
@ -38,13 +38,13 @@ const API_TOKEN_TEMPLATE = JSON.stringify([
{ key: 'dns', type: 'edit' },
{ key: 'workers_scripts', type: 'edit' },
{ key: 'account_rulesets', type: 'edit' },
])
]
const fields = FIELDS.map((x) => JSON.stringify(x))
.map((v) => `fields=${v}`)
.join('&')
const url = new URL(
`/?url=${PROJECT_URL}&authed=true&${fields}&apiTokenTmpl=${API_TOKEN_TEMPLATE}&apiTokenName=Wildebeest`,
`/?url=${PROJECT_URL}&authed=true&${fields}&apiTokenTmpl=${JSON.stringify(API_TOKEN_TEMPLATE)}&apiTokenName=Wildebeest`,
ONE_CLICK_BASE_URL
)
console.log(url.href)