cloudflare 4.2.1 → 4.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/cloudflare/accounts.rb +8 -26
- data/lib/cloudflare/connection.rb +23 -31
- data/lib/cloudflare/custom_hostname/ssl_attribute/settings.rb +10 -4
- data/lib/cloudflare/custom_hostname/ssl_attribute.rb +8 -3
- data/lib/cloudflare/custom_hostnames.rb +64 -41
- data/lib/cloudflare/dns.rb +50 -52
- data/lib/cloudflare/firewall.rb +31 -42
- data/lib/cloudflare/kv/namespaces.rb +65 -29
- data/lib/cloudflare/kv/wrapper.rb +38 -0
- data/lib/cloudflare/logs.rb +7 -23
- data/lib/cloudflare/paginate.rb +21 -33
- data/lib/cloudflare/representation.rb +62 -86
- data/lib/cloudflare/user.rb +6 -23
- data/lib/cloudflare/version.rb +7 -21
- data/lib/cloudflare/zones.rb +46 -40
- data/lib/cloudflare.rb +18 -34
- data/license.md +41 -0
- data/readme.md +108 -0
- data.tar.gz.sig +0 -0
- metadata +61 -66
- metadata.gz.sig +2 -0
- data/lib/cloudflare/rspec/connection.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ba2d239f123bdb4e182b88d91784524799c70c90bd5c807667f95901892263f
|
4
|
+
data.tar.gz: bf5e63e363ec5da14af177bb87849c9e00b883c964c18b7ebcb227cae994758a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad9c07a221587403f1d997273b05c121c9fe658113cd3d460f8b1394c17285518cdbbf98cc31865315189bb9402901a23d775003b75760d0c5e7f13b1342d5e5
|
7
|
+
data.tar.gz: 4f72ebb38c78fd734b235be37a5088c1f632877f592370924dfb89461bd3f4a4f0fe5f8ac85d071c9395467f928b62a530f165cded2718b7c50eb339b5065025
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/lib/cloudflare/accounts.rb
CHANGED
@@ -1,39 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
# Copyright,
|
5
|
-
# Copyright,
|
6
|
-
#
|
7
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
-
# of this software and associated documentation files (the "Software"), to deal
|
9
|
-
# in the Software without restriction, including without limitation the rights
|
10
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
-
# copies of the Software, and to permit persons to whom the Software is
|
12
|
-
# furnished to do so, subject to the following conditions:
|
13
|
-
#
|
14
|
-
# The above copyright notice and this permission notice shall be included in
|
15
|
-
# all copies or substantial portions of the Software.
|
16
|
-
#
|
17
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
-
# THE SOFTWARE.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2018-2024, by Samuel Williams.
|
5
|
+
# Copyright, 2019, by Rob Widmer.
|
24
6
|
|
25
|
-
require_relative
|
26
|
-
require_relative
|
27
|
-
require_relative
|
7
|
+
require_relative "representation"
|
8
|
+
require_relative "paginate"
|
9
|
+
require_relative "kv/namespaces"
|
28
10
|
|
29
11
|
module Cloudflare
|
30
12
|
class Account < Representation
|
31
13
|
def id
|
32
|
-
|
14
|
+
result[:id]
|
33
15
|
end
|
34
16
|
|
35
17
|
def kv_namespaces
|
36
|
-
self.with(KV::Namespaces, path:
|
18
|
+
self.with(KV::Namespaces, path: "storage/kv/namespaces")
|
37
19
|
end
|
38
20
|
end
|
39
21
|
|
@@ -1,44 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2014-2016, by Marcin Prokop.
|
5
|
+
# Copyright, 2014-2024, by Samuel Williams.
|
6
|
+
# Copyright, 2015, by Kyle Corbitt.
|
7
|
+
# Copyright, 2015, by Guillaume Leseur.
|
8
|
+
# Copyright, 2018, by Leonhardt Wille.
|
9
|
+
# Copyright, 2018, by Michael Kalygin.
|
10
|
+
# Copyright, 2018, by Sherman Koa.
|
11
|
+
# Copyright, 2019, by Akinori Musha.
|
22
12
|
|
23
|
-
|
13
|
+
require "async/rest/resource"
|
24
14
|
|
25
|
-
require_relative
|
26
|
-
require_relative
|
27
|
-
require_relative
|
15
|
+
require_relative "zones"
|
16
|
+
require_relative "accounts"
|
17
|
+
require_relative "user"
|
28
18
|
|
29
19
|
module Cloudflare
|
30
|
-
class Connection <
|
20
|
+
class Connection < Async::REST::Resource
|
21
|
+
ENDPOINT = Async::HTTP::Endpoint.parse("https://api.cloudflare.com/client/v4/")
|
22
|
+
|
31
23
|
def authenticated(token: nil, key: nil, email: nil)
|
32
24
|
headers = {}
|
33
25
|
|
34
26
|
if token
|
35
|
-
headers[
|
27
|
+
headers["authorization"] = "bearer #{token}"
|
36
28
|
elsif key
|
37
29
|
if email
|
38
|
-
headers[
|
39
|
-
headers[
|
30
|
+
headers["x-auth-key"] = key
|
31
|
+
headers["x-auth-email"] = email
|
40
32
|
else
|
41
|
-
headers[
|
33
|
+
headers["x-auth-user-service-key"] = key
|
42
34
|
end
|
43
35
|
end
|
44
36
|
|
@@ -46,15 +38,15 @@ module Cloudflare
|
|
46
38
|
end
|
47
39
|
|
48
40
|
def zones
|
49
|
-
self.with(
|
41
|
+
Zones.new(self.with(path: "zones/"))
|
50
42
|
end
|
51
43
|
|
52
44
|
def accounts
|
53
|
-
self.with(
|
45
|
+
Accounts.new(self.with(path: "accounts"))
|
54
46
|
end
|
55
47
|
|
56
48
|
def user
|
57
|
-
self.with(
|
49
|
+
User.new(self.with(path: "user"))
|
58
50
|
end
|
59
51
|
end
|
60
52
|
end
|
@@ -1,10 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019, by Rob Widmer.
|
5
|
+
# Copyright, 2019-2024, by Samuel Williams.
|
6
|
+
|
7
|
+
require_relative "../../representation"
|
8
|
+
|
3
9
|
module Cloudflare
|
4
10
|
class CustomHostname < Representation
|
5
11
|
class SSLAttribute
|
6
12
|
class Settings
|
7
|
-
def initialize(settings)
|
13
|
+
def initialize(settings = {})
|
8
14
|
@settings = settings
|
9
15
|
end
|
10
16
|
|
@@ -25,7 +31,7 @@ module Cloudflare
|
|
25
31
|
# Always coerce into a boolean, if the key is not
|
26
32
|
# provided, this value may not be accurate
|
27
33
|
def http2?
|
28
|
-
http2 ==
|
34
|
+
http2 == "on"
|
29
35
|
end
|
30
36
|
|
31
37
|
def http2=(value)
|
@@ -49,7 +55,7 @@ module Cloudflare
|
|
49
55
|
# Always coerce into a boolean, if the key is not
|
50
56
|
# provided, this value may not be accurate
|
51
57
|
def tls_1_3?
|
52
|
-
tls_1_3 ==
|
58
|
+
tls_1_3 == "on"
|
53
59
|
end
|
54
60
|
|
55
61
|
def tls_1_3=(value)
|
@@ -62,7 +68,7 @@ module Cloudflare
|
|
62
68
|
if value.nil?
|
63
69
|
@settings.delete(key)
|
64
70
|
else
|
65
|
-
@settings[key] = !value || value ==
|
71
|
+
@settings[key] = !value || value == "off" ? "off" : "on"
|
66
72
|
end
|
67
73
|
end
|
68
74
|
end
|
@@ -1,6 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019, by Rob Widmer.
|
5
|
+
# Copyright, 2019-2024, by Samuel Williams.
|
6
|
+
|
7
|
+
require_relative "ssl_attribute/settings"
|
8
|
+
require_relative "../representation"
|
4
9
|
|
5
10
|
module Cloudflare
|
6
11
|
class CustomHostname < Representation
|
@@ -10,7 +15,7 @@ module Cloudflare
|
|
10
15
|
end
|
11
16
|
|
12
17
|
def active?
|
13
|
-
status ==
|
18
|
+
status == "active"
|
14
19
|
end
|
15
20
|
|
16
21
|
def cname
|
@@ -34,7 +39,7 @@ module Cloudflare
|
|
34
39
|
end
|
35
40
|
|
36
41
|
def pending_validation?
|
37
|
-
status ==
|
42
|
+
status == "pending_validation"
|
38
43
|
end
|
39
44
|
|
40
45
|
# Wraps the settings hash if it exists or initializes the settings hash and then wraps it
|
@@ -1,78 +1,101 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019, by Rob Widmer.
|
5
|
+
# Copyright, 2019-2024, by Samuel Williams.
|
5
6
|
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
7
|
+
require_relative "custom_hostname/ssl_attribute"
|
8
|
+
require_relative "paginate"
|
9
|
+
require_relative "representation"
|
9
10
|
|
10
11
|
module Cloudflare
|
11
12
|
class CustomHostname < Representation
|
13
|
+
include Async::REST::Representation::Mutable
|
14
|
+
|
12
15
|
# Only available if enabled for your zone
|
13
16
|
def custom_origin
|
14
|
-
|
17
|
+
result[:custom_origin_server]
|
15
18
|
end
|
16
|
-
|
19
|
+
|
17
20
|
# Only available if enabled for your zone
|
18
21
|
def custom_metadata
|
19
|
-
|
22
|
+
result[:custom_metadata]
|
20
23
|
end
|
21
|
-
|
24
|
+
|
22
25
|
def hostname
|
23
|
-
|
26
|
+
result[:hostname]
|
24
27
|
end
|
25
|
-
|
28
|
+
|
26
29
|
def id
|
27
|
-
|
30
|
+
result[:id]
|
28
31
|
end
|
29
|
-
|
32
|
+
|
30
33
|
def ssl
|
31
|
-
@ssl ||= SSLAttribute.new(
|
34
|
+
@ssl ||= SSLAttribute.new(result[:ssl])
|
32
35
|
end
|
33
|
-
|
36
|
+
|
34
37
|
# Check if the cert has been validated
|
35
38
|
# passing true will send a request to Cloudflare to try to validate the cert
|
36
39
|
def ssl_active?(force_update = false)
|
37
|
-
|
38
|
-
|
40
|
+
if force_update && ssl.pending_validation?
|
41
|
+
self.patch(ssl: {method: ssl.method, type: ssl.type})
|
42
|
+
end
|
43
|
+
|
44
|
+
return ssl.active?
|
39
45
|
end
|
40
|
-
|
46
|
+
|
41
47
|
def update_settings(metadata: nil, origin: nil, ssl: nil)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
+
payload = {}
|
49
|
+
|
50
|
+
payload[:custom_metadata] = metadata if metadata
|
51
|
+
payload[:custom_origin_server] = origin if origin
|
52
|
+
payload[:ssl] = ssl if ssl
|
53
|
+
|
54
|
+
self.patch(payload)
|
48
55
|
end
|
49
|
-
|
56
|
+
|
50
57
|
alias :to_s :hostname
|
51
|
-
|
58
|
+
|
52
59
|
private
|
53
|
-
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
60
|
+
|
61
|
+
def patch(payload)
|
62
|
+
self.class.patch(@resource, payload) do |resource, response|
|
63
|
+
value = response.read
|
64
|
+
|
65
|
+
if value[:sucess]
|
66
|
+
@ssl = nil
|
67
|
+
@value = value
|
68
|
+
else
|
69
|
+
raise RequestError.new(@resource, value)
|
70
|
+
end
|
71
|
+
end
|
59
72
|
end
|
60
73
|
end
|
61
74
|
|
62
75
|
class CustomHostnames < Representation
|
63
76
|
include Paginate
|
64
|
-
|
77
|
+
|
65
78
|
def representation
|
66
79
|
CustomHostname
|
67
80
|
end
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
81
|
+
|
82
|
+
def create(hostname, metadata: nil, origin: nil, ssl: {}, **options)
|
83
|
+
payload = {hostname: hostname, ssl: {method: "http", type: "dv"}.merge(ssl), **options}
|
84
|
+
|
85
|
+
payload[:custom_metadata] = metadata if metadata
|
86
|
+
payload[:custom_origin_server] = origin if origin
|
87
|
+
|
88
|
+
CustomHostname.post(@resource, payload) do |resource, response|
|
89
|
+
value = response.read
|
90
|
+
result = value[:result]
|
91
|
+
metadata = response.headers
|
92
|
+
|
93
|
+
if id = result[:id]
|
94
|
+
resource = resource.with(path: id)
|
95
|
+
end
|
96
|
+
|
97
|
+
CustomHostname.new(resource, value: value, metadata: metadata)
|
98
|
+
end
|
76
99
|
end
|
77
100
|
|
78
101
|
def find_by_hostname(hostname)
|
data/lib/cloudflare/dns.rb
CHANGED
@@ -1,86 +1,84 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
# Copyright,
|
5
|
-
# Copyright,
|
6
|
-
#
|
7
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
-
# of this software and associated documentation files (the "Software"), to deal
|
9
|
-
# in the Software without restriction, including without limitation the rights
|
10
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
-
# copies of the Software, and to permit persons to whom the Software is
|
12
|
-
# furnished to do so, subject to the following conditions:
|
13
|
-
#
|
14
|
-
# The above copyright notice and this permission notice shall be included in
|
15
|
-
# all copies or substantial portions of the Software.
|
16
|
-
#
|
17
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
-
# THE SOFTWARE.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2024, by Samuel Williams.
|
5
|
+
# Copyright, 2019, by Rob Widmer.
|
6
|
+
# Copyright, 2019, by David Wegman.
|
24
7
|
|
25
|
-
require_relative
|
26
|
-
require_relative
|
8
|
+
require_relative "representation"
|
9
|
+
require_relative "paginate"
|
27
10
|
|
28
11
|
module Cloudflare
|
29
12
|
module DNS
|
30
13
|
class Record < Representation
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
@record = record || get.result
|
35
|
-
end
|
36
|
-
|
14
|
+
include Async::REST::Representation::Mutable
|
15
|
+
|
37
16
|
def update_content(content, **options)
|
38
|
-
|
39
|
-
type:
|
40
|
-
name:
|
17
|
+
self.class.put(@resource, {
|
18
|
+
type: self.type,
|
19
|
+
name: self.name,
|
41
20
|
content: content,
|
42
21
|
**options
|
43
|
-
)
|
44
|
-
|
45
|
-
|
22
|
+
}) do |resource, response|
|
23
|
+
if response.success?
|
24
|
+
@value = response.read
|
25
|
+
@metadata = response.headers
|
26
|
+
else
|
27
|
+
raise RequestError.new(resource, response.read)
|
28
|
+
end
|
29
|
+
|
30
|
+
self
|
31
|
+
end
|
46
32
|
end
|
47
|
-
|
33
|
+
|
48
34
|
def type
|
49
|
-
|
35
|
+
result[:type]
|
50
36
|
end
|
51
|
-
|
37
|
+
|
52
38
|
def name
|
53
|
-
|
39
|
+
result[:name]
|
54
40
|
end
|
55
|
-
|
41
|
+
|
56
42
|
def content
|
57
|
-
|
43
|
+
result[:content]
|
58
44
|
end
|
59
|
-
|
60
|
-
def proxied
|
61
|
-
|
45
|
+
|
46
|
+
def proxied?
|
47
|
+
result[:proxied]
|
62
48
|
end
|
63
|
-
|
49
|
+
|
50
|
+
alias proxied proxied?
|
51
|
+
|
64
52
|
def to_s
|
65
|
-
"#{
|
53
|
+
"#{self.name} #{self.type} #{self.content}"
|
66
54
|
end
|
67
55
|
end
|
68
|
-
|
56
|
+
|
69
57
|
class Records < Representation
|
70
58
|
include Paginate
|
71
|
-
|
59
|
+
|
72
60
|
def representation
|
73
61
|
Record
|
74
62
|
end
|
75
|
-
|
76
|
-
TTL_AUTO = 1
|
77
63
|
|
78
64
|
def create(type, name, content, **options)
|
79
|
-
|
65
|
+
payload = {type: type, name: name, content: content, **options}
|
66
|
+
|
67
|
+
Record.post(@resource, payload) do |resource, response|
|
68
|
+
value = response.read
|
69
|
+
result = value[:result]
|
70
|
+
metadata = response.headers
|
71
|
+
|
72
|
+
if id = result[:id]
|
73
|
+
resource = resource.with(path: id)
|
74
|
+
end
|
75
|
+
|
76
|
+
Record.new(resource, value: value, metadata: metadata)
|
77
|
+
end
|
80
78
|
end
|
81
79
|
|
82
80
|
def find_by_name(name)
|
83
|
-
each(name: name).
|
81
|
+
each(name: name).find{|record| record.name == name}
|
84
82
|
end
|
85
83
|
end
|
86
84
|
end
|
data/lib/cloudflare/firewall.rb
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2024, by Samuel Williams.
|
5
|
+
# Copyright, 2019, by Rob Widmer.
|
22
6
|
|
23
|
-
require_relative
|
24
|
-
require_relative
|
7
|
+
require_relative "representation"
|
8
|
+
require_relative "paginate"
|
25
9
|
|
26
10
|
module Cloudflare
|
27
11
|
module Firewall
|
28
12
|
class Rule < Representation
|
13
|
+
include Async::REST::Representation::Mutable
|
14
|
+
|
29
15
|
def mode
|
30
|
-
|
16
|
+
result[:mode]
|
31
17
|
end
|
32
|
-
|
18
|
+
|
33
19
|
def notes
|
34
|
-
|
20
|
+
result[:notes]
|
35
21
|
end
|
36
|
-
|
22
|
+
|
37
23
|
def configuration
|
38
|
-
|
24
|
+
result[:configuration]
|
39
25
|
end
|
40
|
-
|
26
|
+
|
41
27
|
def to_s
|
42
28
|
"#{configuration[:value]} - #{mode} - #{notes}"
|
43
29
|
end
|
@@ -45,26 +31,29 @@ module Cloudflare
|
|
45
31
|
|
46
32
|
class Rules < Representation
|
47
33
|
include Paginate
|
48
|
-
|
34
|
+
|
49
35
|
def representation
|
50
36
|
Rule
|
51
37
|
end
|
52
|
-
|
53
|
-
def set(mode, value, notes: nil, target:
|
38
|
+
|
39
|
+
def set(mode, value, notes: nil, target: "ip")
|
54
40
|
notes ||= "cloudflare gem [#{mode}] #{Time.now.strftime('%m/%d/%y')}"
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
41
|
+
|
42
|
+
payload = {mode: mode.to_s, notes: notes, configuration: {target: target, value: value.to_s}}
|
43
|
+
|
44
|
+
Rule.post(@resource, payload) do |resource, response|
|
45
|
+
value = response.read
|
46
|
+
result = value[:result]
|
47
|
+
metadata = response.headers
|
48
|
+
|
49
|
+
if id = result[:id]
|
50
|
+
resource = resource.with(path: id)
|
51
|
+
end
|
52
|
+
|
53
|
+
Rule.new(resource, value: value, metadata: metadata)
|
54
|
+
end
|
66
55
|
end
|
67
|
-
|
56
|
+
|
68
57
|
def each_by_value(value, &block)
|
69
58
|
each(configuration_value: value, &block)
|
70
59
|
end
|