Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudflare WAF, Cloudflare Lists #336

Merged
merged 21 commits into from
Jan 16, 2025
54 changes: 54 additions & 0 deletions src/appmixer/cloudflare/CloudflareAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module.exports = class CloudflareAPI {

constructor({ email, apiKey, zoneId, token }) {
this.email = email;
this.zoneId = zoneId;
this.email = email;
this.apiKey = apiKey;
this.token = token;
}

getHeaders() {
if (this.token) {
return {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.token}`
};
}

return {
'Content-Type': 'application/json',
'X-Auth-Email': this.email,
'X-Auth-Key': this.apiKey
};
}

async verifyGlobalApiKey(context) {

const headers = this.getHeaders();

return context.httpRequest({
method: 'GET',
url: 'https://api.cloudflare.com/client/v4/accounts',
headers
});
}

async callEndpoint(context, {
action,
method = 'GET',
data,
params
}) {

const headers = this.getHeaders();

return context.httpRequest({
method,
url: `https://api.cloudflare.com/client/v4${action}`,
headers,
data,
params
});
}
};
32 changes: 0 additions & 32 deletions src/appmixer/cloudflare/CloudflareZonesUrlBuilder.js

This file was deleted.

221 changes: 0 additions & 221 deletions src/appmixer/cloudflare/ZoneCloudflareClient.js

This file was deleted.

20 changes: 5 additions & 15 deletions src/appmixer/cloudflare/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const ZoneCloudflareClient = require('./ZoneCloudflareClient');
const CloudflareAPI = require('./CloudflareAPI');

module.exports = {

Expand All @@ -11,11 +11,6 @@ module.exports = {
accountNameFromProfileInfo: 'account',

auth: {
apiToken: {
type: 'text',
name: 'API Token',
tooltip: 'Manage access and permissions for your accounts, sites, and products".'
},
email: {
type: 'text',
name: 'Email',
Expand All @@ -30,23 +25,18 @@ module.exports = {

requestProfileInfo: async function(context) {

const { email, apiToken } = context;
const { email } = context;

if (email) {
return { account: email };
}

const threshold = 10;
if (apiToken.length > threshold) {
return { account: apiToken.slice(0, 5) + ' ... ' + apiToken.slice(-3) };
}
},

validate: async function(context) {

const client = new ZoneCloudflareClient({ token: context.apiToken });

const { data } = await client.verify(context);
const { email, apiKey } = context;
const client = new CloudflareAPI({ email, apiKey });
const { data } = await client.verifyGlobalApiKey(context);
return data.success || false;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "appmixer.cloudflare.lists",
"name": "appmixer.cloudflare",
"version": "1.0.0",
"changelog": []
}
Loading
Loading