cloudflare 4.3.0 → 4.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7df158b1fb45428a5bd2f3a2147700e691ed6a4bdadbc26f7a6cf0229d77ff98
4
- data.tar.gz: 909cd8848e8368d670592c2108ffe1231147226d56d98e23e499807f48d80e8c
3
+ metadata.gz: 2ba2d239f123bdb4e182b88d91784524799c70c90bd5c807667f95901892263f
4
+ data.tar.gz: bf5e63e363ec5da14af177bb87849c9e00b883c964c18b7ebcb227cae994758a
5
5
  SHA512:
6
- metadata.gz: df08439266659d4232501e8cd22dc1013b5d7d764c9c0d09c3a2768704cb460031ef69139c72de03b5c84b3e8618e1714c1b00624652e3dd557e9206a0fedd3b
7
- data.tar.gz: 7c006538e659c65ff3059f6bbbac4feaeed6ac36763f683498be20b2cc8b0ff7d42e0bc43faeda1a8786967a829b152d7575f52c8904502302c7a2a0aa818b95
6
+ metadata.gz: ad9c07a221587403f1d997273b05c121c9fe658113cd3d460f8b1394c17285518cdbbf98cc31865315189bb9402901a23d775003b75760d0c5e7f13b1342d5e5
7
+ data.tar.gz: 4f72ebb38c78fd734b235be37a5088c1f632877f592370924dfb89461bd3f4a4f0fe5f8ac85d071c9395467f928b62a530f165cded2718b7c50eb339b5065025
checksums.yaml.gz.sig ADDED
Binary file
@@ -1,39 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2012, by Marcin Prokop.
4
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
5
- # Copyright, 2017, by David Rosenbloom. <http://artifactory.com>
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 'representation'
26
- require_relative 'paginate'
27
- require_relative 'kv/namespaces'
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
- value[:id]
14
+ result[:id]
33
15
  end
34
16
 
35
17
  def kv_namespaces
36
- self.with(KV::Namespaces, path: 'storage/kv/namespaces')
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
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
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, 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
- require_relative 'representation'
13
+ require "async/rest/resource"
24
14
 
25
- require_relative 'zones'
26
- require_relative 'accounts'
27
- require_relative 'user'
15
+ require_relative "zones"
16
+ require_relative "accounts"
17
+ require_relative "user"
28
18
 
29
19
  module Cloudflare
30
- class Connection < Representation
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['Authorization'] = "Bearer #{token}"
27
+ headers["authorization"] = "bearer #{token}"
36
28
  elsif key
37
29
  if email
38
- headers['X-Auth-Key'] = key
39
- headers['X-Auth-Email'] = email
30
+ headers["x-auth-key"] = key
31
+ headers["x-auth-email"] = email
40
32
  else
41
- headers['X-Auth-User-Service-Key'] = key
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(Zones, path: 'zones')
41
+ Zones.new(self.with(path: "zones/"))
50
42
  end
51
43
 
52
44
  def accounts
53
- self.with(Accounts, path: 'accounts')
45
+ Accounts.new(self.with(path: "accounts"))
54
46
  end
55
47
 
56
48
  def user
57
- self.with(User, path: 'user')
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 == 'on'
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 == 'on'
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 == 'off' ? 'off' : 'on'
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
- require_relative './ssl_attribute/settings'
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 == 'active'
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 == 'pending_validation'
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
- # This implements the Custom Hostname API
4
- # https://api.cloudflare.com/#custom-hostname-for-a-zone-properties
3
+ # Released under the MIT License.
4
+ # Copyright, 2019, by Rob Widmer.
5
+ # Copyright, 2019-2024, by Samuel Williams.
5
6
 
6
- require_relative 'custom_hostname/ssl_attribute'
7
- require_relative 'paginate'
8
- require_relative 'representation'
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
- value[:custom_origin_server]
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
- value[:custom_metadata]
22
+ result[:custom_metadata]
20
23
  end
21
-
24
+
22
25
  def hostname
23
- value[:hostname]
26
+ result[:hostname]
24
27
  end
25
-
28
+
26
29
  def id
27
- value[:id]
30
+ result[:id]
28
31
  end
29
-
32
+
30
33
  def ssl
31
- @ssl ||= SSLAttribute.new(value[:ssl])
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
- send_patch(ssl: { method: ssl.method, type: ssl.type }) if force_update && ssl.pending_validation?
38
- ssl.active?
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
- attrs = {}
43
- attrs[:custom_metadata] = metadata if metadata
44
- attrs[:custom_origin_server] = origin if origin
45
- attrs[:ssl] = ssl if ssl
46
-
47
- send_patch(attrs)
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 send_patch(data)
55
- response = patch(data)
56
-
57
- @ssl = nil # Kill off our cached version of the ssl object so it will be regenerated from the response
58
- @value = response.result
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
- # initializes a custom hostname object and yields it for customization before saving
70
- def create(hostname, metadata: nil, origin: nil, ssl: {}, &block)
71
- attrs = { hostname: hostname, ssl: { method: 'http', type: 'dv' }.merge(ssl) }
72
- attrs[:custom_metadata] = metadata if metadata
73
- attrs[:custom_origin_server] = origin if origin
74
-
75
- represent_message(self.post(attrs))
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)
@@ -1,86 +1,84 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2012, by Marcin Prokop.
4
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
5
- # Copyright, 2017, by David Rosenbloom. <http://artifactory.com>
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 'representation'
26
- require_relative 'paginate'
8
+ require_relative "representation"
9
+ require_relative "paginate"
27
10
 
28
11
  module Cloudflare
29
12
  module DNS
30
13
  class Record < Representation
31
- def initialize(url, record = nil, **options)
32
- super(url, **options)
33
-
34
- @record = record || get.result
35
- end
36
-
14
+ include Async::REST::Representation::Mutable
15
+
37
16
  def update_content(content, **options)
38
- response = put(
39
- type: @record[:type],
40
- name: @record[:name],
17
+ self.class.put(@resource, {
18
+ type: self.type,
19
+ name: self.name,
41
20
  content: content,
42
21
  **options
43
- )
44
-
45
- @value = response.result
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
- value[:type]
35
+ result[:type]
50
36
  end
51
-
37
+
52
38
  def name
53
- value[:name]
39
+ result[:name]
54
40
  end
55
-
41
+
56
42
  def content
57
- value[:content]
43
+ result[:content]
58
44
  end
59
-
60
- def proxied
61
- value[:proxied]
45
+
46
+ def proxied?
47
+ result[:proxied]
62
48
  end
63
-
49
+
50
+ alias proxied proxied?
51
+
64
52
  def to_s
65
- "#{@record[:name]} #{@record[:type]} #{@record[:content]}"
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
- represent_message(self.post(type: type, name: name, content: content, **options))
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).first
81
+ each(name: name).find{|record| record.name == name}
84
82
  end
85
83
  end
86
84
  end
@@ -1,43 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
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 'representation'
24
- require_relative 'paginate'
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
- value[:mode]
16
+ result[:mode]
31
17
  end
32
-
18
+
33
19
  def notes
34
- value[:notes]
20
+ result[:notes]
35
21
  end
36
-
22
+
37
23
  def configuration
38
- value[:configuration]
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: 'ip')
38
+
39
+ def set(mode, value, notes: nil, target: "ip")
54
40
  notes ||= "cloudflare gem [#{mode}] #{Time.now.strftime('%m/%d/%y')}"
55
-
56
- message = self.post({
57
- mode: mode.to_s,
58
- notes: notes,
59
- configuration: {
60
- target: target,
61
- value: value.to_s,
62
- }
63
- })
64
-
65
- represent_message(message)
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