Skip to content

Commit 6ce8d24

Browse files
committed
feat: add script to delete cloudflare access policy
1 parent 0e8c38c commit 6ce8d24

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

scripts/delete_access_policy.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const https = require('https');
2+
3+
const accountId = '026b92ea77fb94b88f6849fa335e554e';
4+
// Accept token from command line argument
5+
const token = process.argv[2];
6+
7+
if (!token) {
8+
console.error("Usage: node scripts/delete_access_policy.js <YOUR_API_TOKEN>");
9+
process.exit(1);
10+
}
11+
12+
function makeRequest(path, method) {
13+
return new Promise((resolve, reject) => {
14+
const options = {
15+
hostname: 'api.cloudflare.com',
16+
path: path,
17+
method: method,
18+
headers: {
19+
'Authorization': `Bearer ${token}`,
20+
'Content-Type': 'application/json'
21+
}
22+
};
23+
24+
const req = https.request(options, (res) => {
25+
let data = '';
26+
res.on('data', chunk => data += chunk);
27+
res.on('end', () => {
28+
try {
29+
resolve({ statusCode: res.statusCode, data: JSON.parse(data) });
30+
} catch (e) {
31+
reject(e);
32+
}
33+
});
34+
});
35+
36+
req.on('error', reject);
37+
req.end();
38+
});
39+
}
40+
41+
async function main() {
42+
try {
43+
console.log("Searching for Access Applications...");
44+
const listRes = await makeRequest(`/client/v4/accounts/${accountId}/access/apps`, 'GET');
45+
46+
if (!listRes.data.success) {
47+
console.error("Failed to list apps:", JSON.stringify(listRes.data.errors, null, 2));
48+
return;
49+
}
50+
51+
const apps = listRes.data.result;
52+
const targetApp = apps.find(app => app.name.includes('hobbytp-github-io') || app.domain.includes('hobbytp-github-io'));
53+
54+
if (!targetApp) {
55+
console.log("No Access Application found for 'hobbytp-github-io'.");
56+
console.log("Found apps:", apps.map(a => a.name).join(', '));
57+
return;
58+
}
59+
60+
console.log(`Found Application: ${targetApp.name} (ID: ${targetApp.id})`);
61+
console.log("Deleting...");
62+
63+
const deleteRes = await makeRequest(`/client/v4/accounts/${accountId}/access/apps/${targetApp.id}`, 'DELETE');
64+
65+
if (deleteRes.data.success) {
66+
console.log("Successfully deleted Access Policy!");
67+
} else {
68+
console.error("Failed to delete:", JSON.stringify(deleteRes.data.errors, null, 2));
69+
}
70+
71+
} catch (error) {
72+
console.error("Error:", error);
73+
}
74+
}
75+
76+
main();

0 commit comments

Comments
 (0)