cloudflare_client_rb 4.2.5 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cloudflare_client/middleware/response/raise_error.rb +1 -1
- data/lib/cloudflare_client/namespace/value.rb +26 -0
- data/lib/cloudflare_client/namespace.rb +12 -0
- data/lib/cloudflare_client/version.rb +1 -1
- data/lib/cloudflare_client/zone/custom_hostname_v2.rb +24 -0
- data/lib/cloudflare_client/zone/custom_ssl.rb +1 -1
- data/lib/cloudflare_client.rb +20 -12
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b750c4cf1d2406e217504fe9cbf195faf7dbc87
|
4
|
+
data.tar.gz: 97a75d61e8d7f758425e3fb0c01d00bcf978f372
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b10b81567bd45527a8826e441cfb429158eaca341532d3cff5d1d02c895dea0334ea3e91c7040707cd714cedccc9b71fdae3236f8fefffedf618c538b5966e8b
|
7
|
+
data.tar.gz: 05c0e5b3880770e0291107b7608a4d9bdb18be396404cdd5f720c9ea06fa1c6d94a0b16c9b2ba95dd70271d64fcec649de91c5ce38de09cfef97f248ac5b64cf
|
@@ -4,7 +4,7 @@ class CloudflareClient
|
|
4
4
|
attr_reader :response, :method, :uri, :url
|
5
5
|
|
6
6
|
def initialize(message = nil, response = nil, method = nil, uri = nil, url = nil)
|
7
|
-
super("#{message}, #{method
|
7
|
+
super("#{message}, #{method&.upcase} #{url} #{response&.body}")
|
8
8
|
@response = response
|
9
9
|
@method = method
|
10
10
|
@uri = uri
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class CloudflareClient::Value < CloudflareClient::Namespace
|
2
|
+
attr_reader :namespace_id
|
3
|
+
|
4
|
+
def initialize(args)
|
5
|
+
@namespace_id = args.delete(:namespace_id)
|
6
|
+
id_check(:namespace_id, namespace_id)
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def write(key:, value:, expiration_ttl: nil, metadata: nil)
|
11
|
+
if expiration_ttl
|
12
|
+
raise RuntimeError, 'expiration_ttl must be an integer' unless expiration_ttl.kind_of?(Integer)
|
13
|
+
end
|
14
|
+
|
15
|
+
data = metadata ? { value: value, metadata: metadata} : value
|
16
|
+
cf_put(path: "/accounts/#{account_id}/storage/kv/namespaces/#{namespace_id}/values/#{key}", data: data, params: {expiration_ttl: expiration_ttl})
|
17
|
+
end
|
18
|
+
|
19
|
+
def read(key:)
|
20
|
+
cf_get(path: "/accounts/#{account_id}/storage/kv/namespaces/#{namespace_id}/values/#{key}", raw: true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(key:)
|
24
|
+
cf_delete(path: "/accounts/#{account_id}/storage/kv/namespaces/#{namespace_id}/values/#{key}")
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CloudflareClient::Namespace < CloudflareClient
|
2
|
+
Dir[File.expand_path('../namespace/*.rb', __FILE__)].each {|f| require f}
|
3
|
+
|
4
|
+
attr_reader :account_id
|
5
|
+
|
6
|
+
def initialize(args)
|
7
|
+
@account_id = args.delete(:account_id)
|
8
|
+
id_check(:account_id, account_id)
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'custom_hostname'
|
2
|
+
# https://api.cloudflare.com/#custom-hostname-for-a-zone-list-custom-hostnames
|
3
|
+
class CloudflareClient::Zone::CustomHostnameV2 < CloudflareClient::Zone::CustomHostname
|
4
|
+
|
5
|
+
def create(hostname:, ssl: DEFAULT_SSL_PROPERTIES, custom_metadata: {}, custom_origin_server: nil)
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def list(hostname: nil, id: nil, page: 1, per_page: 50, order: 'ssl', direction: 'desc', ssl: 0)
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def show(id:)
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def update(id:, ssl: {}, custom_metadata: nil, custom_origin_server: nil)
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete(id:)
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
@@ -26,7 +26,7 @@ class CloudflareClient::Zone::CustomSSL < CloudflareClient::Zone::Base
|
|
26
26
|
params = {page: page, per_page: per_page}
|
27
27
|
params[:match] = match
|
28
28
|
params[:direction] = direction
|
29
|
-
cf_get(path: "/zones/#{zone_id}/
|
29
|
+
cf_get(path: "/zones/#{zone_id}/custom_certificates", params: params)
|
30
30
|
end
|
31
31
|
|
32
32
|
##
|
data/lib/cloudflare_client.rb
CHANGED
@@ -51,10 +51,10 @@ class CloudflareClient
|
|
51
51
|
websockets
|
52
52
|
].freeze
|
53
53
|
|
54
|
-
def initialize(auth_key: nil, email: nil)
|
55
|
-
raise('Missing auth_key') if auth_key.nil?
|
56
|
-
raise('missing email') if email.nil?
|
57
|
-
@cf_client ||= build_client(auth_key: auth_key, email: email)
|
54
|
+
def initialize(auth_key: nil, email: nil, auth_token: nil, &block)
|
55
|
+
raise('Missing auth_key or auth_token') if auth_key.nil? && auth_token.nil?
|
56
|
+
raise('missing email') if email.nil? && !auth_key.nil?
|
57
|
+
@cf_client ||= build_client(auth_key: auth_key, email: email, auth_token: auth_token, &block)
|
58
58
|
end
|
59
59
|
|
60
60
|
#TODO: add the time based stuff
|
@@ -131,19 +131,24 @@ class CloudflareClient
|
|
131
131
|
end
|
132
132
|
|
133
133
|
def build_client(params)
|
134
|
-
raise('Missing auth_key') if params[:auth_key].nil?
|
135
|
-
raise('Missing auth email') if params[:email].nil?
|
136
134
|
# we need multipart form encoding for some of these operations
|
137
135
|
client = Faraday.new(url: API_BASE) do |conn|
|
138
136
|
conn.request :multipart
|
139
137
|
conn.request :url_encoded
|
140
138
|
conn.use Middleware::Response::RaiseError
|
141
|
-
conn.adapter :net_http
|
142
139
|
end
|
143
|
-
|
144
|
-
client.headers['X-Auth-User-Service-Key '] = params[:auth_key] #FIXME, is this always the same?
|
145
|
-
client.headers['X-Auth-Email'] = params[:email]
|
140
|
+
|
146
141
|
client.headers['Content-Type'] = 'application/json'
|
142
|
+
if params[:auth_token]
|
143
|
+
client.headers['Authorization'] = "Bearer #{params[:auth_token]}"
|
144
|
+
else
|
145
|
+
client.headers['X-Auth-Key'] = params[:auth_key]
|
146
|
+
client.headers['X-Auth-User-Service-Key '] = params[:auth_key] #FIXME, is this always the same?
|
147
|
+
client.headers['X-Auth-Email'] = params[:email]
|
148
|
+
end
|
149
|
+
|
150
|
+
yield client if block_given?
|
151
|
+
client.adapter :net_http
|
147
152
|
client
|
148
153
|
end
|
149
154
|
|
@@ -175,10 +180,13 @@ class CloudflareClient
|
|
175
180
|
JSON.parse(result.body, symbolize_names: true)
|
176
181
|
end
|
177
182
|
|
178
|
-
def cf_put(path: nil, data: nil)
|
183
|
+
def cf_put(path: nil, data: nil, params: nil)
|
179
184
|
result = @cf_client.put do |request|
|
180
185
|
request.url(API_BASE + path) unless path.nil?
|
181
186
|
request.body = data.to_json unless data.nil?
|
187
|
+
unless params.nil?
|
188
|
+
request.params = params if params.values.any? { |i| !i.nil? }
|
189
|
+
end
|
182
190
|
end
|
183
191
|
JSON.parse(result.body, symbolize_names: true)
|
184
192
|
end
|
@@ -204,4 +212,4 @@ class CloudflareClient
|
|
204
212
|
return false unless POSSIBLE_API_SETTINGS.include?(name)
|
205
213
|
true
|
206
214
|
end
|
207
|
-
end
|
215
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudflare_client_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ian waters
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description:
|
14
14
|
email: iwaters@zendesk.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
@@ -19,6 +19,8 @@ files:
|
|
19
19
|
- lib/cloudflare_client.rb
|
20
20
|
- lib/cloudflare_client/certificate.rb
|
21
21
|
- lib/cloudflare_client/middleware/response/raise_error.rb
|
22
|
+
- lib/cloudflare_client/namespace.rb
|
23
|
+
- lib/cloudflare_client/namespace/value.rb
|
22
24
|
- lib/cloudflare_client/organization.rb
|
23
25
|
- lib/cloudflare_client/organization/access_rule.rb
|
24
26
|
- lib/cloudflare_client/organization/invite.rb
|
@@ -33,6 +35,7 @@ files:
|
|
33
35
|
- lib/cloudflare_client/zone/analytics.rb
|
34
36
|
- lib/cloudflare_client/zone/base.rb
|
35
37
|
- lib/cloudflare_client/zone/custom_hostname.rb
|
38
|
+
- lib/cloudflare_client/zone/custom_hostname_v2.rb
|
36
39
|
- lib/cloudflare_client/zone/custom_page.rb
|
37
40
|
- lib/cloudflare_client/zone/custom_ssl.rb
|
38
41
|
- lib/cloudflare_client/zone/dns.rb
|
@@ -52,9 +55,9 @@ files:
|
|
52
55
|
- lib/cloudflare_client/zone/subscription.rb
|
53
56
|
homepage: https://github.com/zendesk/cloudflare_client_rb
|
54
57
|
licenses:
|
55
|
-
- Apache
|
58
|
+
- Apache-2.0
|
56
59
|
metadata: {}
|
57
|
-
post_install_message:
|
60
|
+
post_install_message:
|
58
61
|
rdoc_options: []
|
59
62
|
require_paths:
|
60
63
|
- lib
|
@@ -69,9 +72,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
72
|
- !ruby/object:Gem::Version
|
70
73
|
version: '0'
|
71
74
|
requirements: []
|
72
|
-
rubyforge_project:
|
75
|
+
rubyforge_project:
|
73
76
|
rubygems_version: 2.6.11
|
74
|
-
signing_key:
|
77
|
+
signing_key:
|
75
78
|
specification_version: 4
|
76
79
|
summary: lightweight cloudflare api client
|
77
80
|
test_files: []
|