@nodeart/cloudflare-provisioning 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cloudflare.js +12 -2
- package/index.js +9 -3
- package/package.json +1 -1
package/cloudflare.js
CHANGED
|
@@ -284,8 +284,13 @@ class CloudFlare {
|
|
|
284
284
|
async rewriteFirewallRules (firewallRules) {
|
|
285
285
|
const { id: rulesetId, rules: currentFirewallRules } = await this.getFirewallRules()
|
|
286
286
|
|
|
287
|
+
if (!rulesetId) {
|
|
288
|
+
console.error(`Could not update firewall rules for domain ${this.domain}: custom firewall ruleset id is not found`)
|
|
289
|
+
throw new Error('Custom firewall ruleset id is not found')
|
|
290
|
+
}
|
|
291
|
+
|
|
287
292
|
for (const firewallRule of firewallRules) {
|
|
288
|
-
const currentFirewallRule = currentFirewallRules
|
|
293
|
+
const currentFirewallRule = currentFirewallRules?.find(
|
|
289
294
|
rule => rule.description === firewallRule.description
|
|
290
295
|
)
|
|
291
296
|
|
|
@@ -420,8 +425,13 @@ class CloudFlare {
|
|
|
420
425
|
async rewriteRedirectRules (redirectRules) {
|
|
421
426
|
const { id: rulesetId, rules: currentRedirectRules } = await this.getRedirectRules()
|
|
422
427
|
|
|
428
|
+
if (!rulesetId) {
|
|
429
|
+
console.error(`Could not update redirect rules for domain ${this.domain}: custom firewall ruleset id is not found`)
|
|
430
|
+
throw new Error('Custom redirect ruleset id is not found')
|
|
431
|
+
}
|
|
432
|
+
|
|
423
433
|
for (const redirectRule of redirectRules) {
|
|
424
|
-
const currentRedirectRule = currentRedirectRules
|
|
434
|
+
const currentRedirectRule = currentRedirectRules?.find(
|
|
425
435
|
rule => rule.description === redirectRule.description
|
|
426
436
|
)
|
|
427
437
|
|
package/index.js
CHANGED
|
@@ -36,6 +36,7 @@ async function applyCloudflareSettings (config) {
|
|
|
36
36
|
|
|
37
37
|
const accountEmail = process.env.CLOUDFLARE_EMAIL
|
|
38
38
|
const accountKey = process.env.CLOUDFLARE_API_KEY
|
|
39
|
+
const accountToken = process.env.CLOUDFLARE_TOKEN
|
|
39
40
|
|
|
40
41
|
if (config.enabled === false) {
|
|
41
42
|
console.log('Config is disabled and would not be applied:', config.domains)
|
|
@@ -50,9 +51,14 @@ async function applyCloudflareSettings (config) {
|
|
|
50
51
|
throw new Error('Cloudflare zone ID is not defined')
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
let options
|
|
55
|
+
if (site.token) {
|
|
56
|
+
options = { token: site.token }
|
|
57
|
+
} else if (accountToken) {
|
|
58
|
+
options = { token: accountToken }
|
|
59
|
+
} else {
|
|
60
|
+
options = { email: accountEmail, apiKey: accountKey }
|
|
61
|
+
}
|
|
56
62
|
|
|
57
63
|
const cloudFlare = new CloudFlare(zoneId, site.domain, options)
|
|
58
64
|
const domainSettings = substituteDomainName(settings, site.domain)
|