cloudflare 4.3.0 → 4.5.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/cloudflare/accounts.rb +11 -29
- data/lib/cloudflare/certificates.rb +29 -0
- data/lib/cloudflare/connection.rb +33 -31
- data/lib/cloudflare/custom_hostname/ssl_attribute/settings.rb +22 -16
- data/lib/cloudflare/custom_hostname/ssl_attribute.rb +20 -15
- data/lib/cloudflare/custom_hostnames.rb +66 -43
- data/lib/cloudflare/dns.rb +51 -53
- data/lib/cloudflare/firewall.rb +32 -43
- data/lib/cloudflare/ips.rb +15 -0
- data/lib/cloudflare/kv/namespaces.rb +66 -32
- data/lib/cloudflare/kv/wrapper.rb +38 -0
- data/lib/cloudflare/logs.rb +8 -24
- data/lib/cloudflare/paginate.rb +21 -33
- data/lib/cloudflare/representation.rb +49 -87
- data/lib/cloudflare/request_error.rb +28 -0
- data/lib/cloudflare/user.rb +6 -23
- data/lib/cloudflare/version.rb +7 -21
- data/lib/cloudflare/zones.rb +53 -42
- data/lib/cloudflare.rb +18 -34
- data/license.md +42 -0
- data/readme.md +108 -0
- data.tar.gz.sig +0 -0
- metadata +65 -72
- metadata.gz.sig +2 -0
- data/lib/cloudflare/kv/rest_wrapper.rb +0 -44
- 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: 410e2e2d3f001bb5cb9a42cfd6ad2ae32245fa1cd887cb872dae9473275b3e8b
|
|
4
|
+
data.tar.gz: 5c7b45600a2588bb90f9af55f69c90d61179e9e90ad5481ec97957758ccd1c19
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 87fcb82185237fd6debabe4adc3b6bc74dc9de74f892c9cfb9103b932df01b6830ec2fb32972c2ebca054505577bbd1643351e64f47f7ae2ff794e57da92c70a
|
|
7
|
+
data.tar.gz: 24959d33b3017e6154cdbef2126eded40c427caa9a4cd3a4335ceabfc53182e7f1515f9a562f0c6f3ab0a9e47052bb4e27d76177b46e2b426ee27b9d8d71f4c9
|
checksums.yaml.gz.sig
ADDED
|
Binary file
|
data/lib/cloudflare/accounts.rb
CHANGED
|
@@ -1,45 +1,27 @@
|
|
|
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
|
+
|
|
40
22
|
class Accounts < Representation
|
|
41
23
|
include Paginate
|
|
42
|
-
|
|
24
|
+
|
|
43
25
|
def representation
|
|
44
26
|
Account
|
|
45
27
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "representation"
|
|
4
|
+
require_relative "paginate"
|
|
5
|
+
|
|
6
|
+
module Cloudflare
|
|
7
|
+
class Certificate < Representation
|
|
8
|
+
def certificate
|
|
9
|
+
result[:certificate]
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Certificates < Representation
|
|
14
|
+
include Paginate
|
|
15
|
+
|
|
16
|
+
def representation
|
|
17
|
+
Certificate
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create(csr_pem, hostnames, request_type = "origin-rsa", requested_validity = 5475)
|
|
21
|
+
represent_message(self.post({
|
|
22
|
+
csr: csr_pem,
|
|
23
|
+
request_type: request_type,
|
|
24
|
+
hostnames: hostnames,
|
|
25
|
+
requested_validity: requested_validity
|
|
26
|
+
}))
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -1,60 +1,62 @@
|
|
|
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 "ips"
|
|
16
|
+
require_relative "zones"
|
|
17
|
+
require_relative "accounts"
|
|
18
|
+
require_relative "user"
|
|
19
|
+
require_relative "certificates"
|
|
28
20
|
|
|
29
21
|
module Cloudflare
|
|
30
|
-
class Connection <
|
|
22
|
+
class Connection < Async::REST::Resource
|
|
23
|
+
ENDPOINT = Async::HTTP::Endpoint.parse("https://api.cloudflare.com/client/v4/")
|
|
24
|
+
|
|
31
25
|
def authenticated(token: nil, key: nil, email: nil)
|
|
32
26
|
headers = {}
|
|
33
27
|
|
|
34
28
|
if token
|
|
35
|
-
headers[
|
|
29
|
+
headers["authorization"] = "bearer #{token}"
|
|
36
30
|
elsif key
|
|
37
31
|
if email
|
|
38
|
-
headers[
|
|
39
|
-
headers[
|
|
32
|
+
headers["x-auth-key"] = key
|
|
33
|
+
headers["x-auth-email"] = email
|
|
40
34
|
else
|
|
41
|
-
headers[
|
|
35
|
+
headers["x-auth-user-service-key"] = key
|
|
42
36
|
end
|
|
43
37
|
end
|
|
44
38
|
|
|
45
39
|
self.with(headers: headers)
|
|
46
40
|
end
|
|
47
41
|
|
|
42
|
+
def cidrs(ipv: nil)
|
|
43
|
+
IPs.new(self.with(path: "ips")).cidrs(ipv: ipv)
|
|
44
|
+
end
|
|
45
|
+
|
|
48
46
|
def zones
|
|
49
|
-
self.with(
|
|
47
|
+
Zones.new(self.with(path: "zones/"))
|
|
50
48
|
end
|
|
51
49
|
|
|
52
50
|
def accounts
|
|
53
|
-
self.with(
|
|
51
|
+
Accounts.new(self.with(path: "accounts"))
|
|
54
52
|
end
|
|
55
53
|
|
|
56
54
|
def user
|
|
57
|
-
self.with(
|
|
55
|
+
User.new(self.with(path: "user"))
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def certificates
|
|
59
|
+
Certificates.new(self.with(path: "certificates"))
|
|
58
60
|
end
|
|
59
61
|
end
|
|
60
62
|
end
|
|
@@ -1,68 +1,74 @@
|
|
|
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
|
+
|
|
11
17
|
def ciphers
|
|
12
18
|
@settings[:ciphers]
|
|
13
19
|
end
|
|
14
|
-
|
|
20
|
+
|
|
15
21
|
def ciphers=(value)
|
|
16
22
|
@settings[:ciphers] = value
|
|
17
23
|
end
|
|
18
|
-
|
|
24
|
+
|
|
19
25
|
# This will return the raw value, it is needed because
|
|
20
26
|
# if a value is nil we can't assume that it means it is off
|
|
21
27
|
def http2
|
|
22
28
|
@settings[:http2]
|
|
23
29
|
end
|
|
24
|
-
|
|
30
|
+
|
|
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)
|
|
32
38
|
process_boolean(:http2, value)
|
|
33
39
|
end
|
|
34
|
-
|
|
40
|
+
|
|
35
41
|
def min_tls_version
|
|
36
42
|
@settings[:min_tls_version]
|
|
37
43
|
end
|
|
38
|
-
|
|
44
|
+
|
|
39
45
|
def min_tls_version=(value)
|
|
40
46
|
@settings[:min_tls_version] = value
|
|
41
47
|
end
|
|
42
|
-
|
|
48
|
+
|
|
43
49
|
# This will return the raw value, it is needed because
|
|
44
50
|
# if a value is nil we can't assume that it means it is off
|
|
45
51
|
def tls_1_3
|
|
46
52
|
@settings[:tls_1_3]
|
|
47
53
|
end
|
|
48
|
-
|
|
54
|
+
|
|
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)
|
|
56
62
|
process_boolean(:tls_1_3, value)
|
|
57
63
|
end
|
|
58
|
-
|
|
64
|
+
|
|
59
65
|
private
|
|
60
|
-
|
|
66
|
+
|
|
61
67
|
def process_boolean(key, value)
|
|
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
|
|
@@ -8,52 +13,52 @@ module Cloudflare
|
|
|
8
13
|
def initialize(params)
|
|
9
14
|
@params = params
|
|
10
15
|
end
|
|
11
|
-
|
|
16
|
+
|
|
12
17
|
def active?
|
|
13
|
-
status ==
|
|
18
|
+
status == "active"
|
|
14
19
|
end
|
|
15
|
-
|
|
20
|
+
|
|
16
21
|
def cname
|
|
17
22
|
@params[:cname]
|
|
18
23
|
end
|
|
19
|
-
|
|
24
|
+
|
|
20
25
|
def cname_target
|
|
21
26
|
@params[:cname_target]
|
|
22
27
|
end
|
|
23
|
-
|
|
28
|
+
|
|
24
29
|
def http_body
|
|
25
30
|
@params[:http_body]
|
|
26
31
|
end
|
|
27
|
-
|
|
32
|
+
|
|
28
33
|
def http_url
|
|
29
34
|
@params[:http_url]
|
|
30
35
|
end
|
|
31
|
-
|
|
36
|
+
|
|
32
37
|
def method
|
|
33
38
|
@params[:method]
|
|
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
|
|
41
46
|
def settings
|
|
42
47
|
@settings ||= Settings.new(@params[:settings] ||= {})
|
|
43
48
|
end
|
|
44
|
-
|
|
49
|
+
|
|
45
50
|
def status
|
|
46
51
|
@params[:status]
|
|
47
52
|
end
|
|
48
|
-
|
|
53
|
+
|
|
49
54
|
def to_h
|
|
50
55
|
@params
|
|
51
56
|
end
|
|
52
|
-
|
|
57
|
+
|
|
53
58
|
def type
|
|
54
59
|
@params[:type]
|
|
55
60
|
end
|
|
56
|
-
|
|
61
|
+
|
|
57
62
|
def validation_errors
|
|
58
63
|
@params[:validation_errors]
|
|
59
64
|
end
|
|
@@ -1,80 +1,103 @@
|
|
|
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[:success]
|
|
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)
|
|
79
102
|
each(hostname: hostname).first
|
|
80
103
|
end
|
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
|