cloudflare_client_rb 4.2.7 → 5.0.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
- SHA1:
3
- metadata.gz: 781fa68d768317105d936c42203e717c9fa760f2
4
- data.tar.gz: 4b04969de67f023b90a7054c6638e5f1bd3801f7
2
+ SHA256:
3
+ metadata.gz: 867624e2f37d6cf2f1709c151e9bd51cba5526863486debbaa7dfc99430950e1
4
+ data.tar.gz: 40ee55b856e35a064872391bbe4ec105b5cc149546ca6d9592e5ef0c67820c90
5
5
  SHA512:
6
- metadata.gz: a5adf49cd33d6fc7a8370a7627ffd9f9e9d9d972dd5f5e736c7e9de507b9ff39b6de88adfade73a4f7fd6ab1ab92861676d4d9447bed2d28e953cc23f6c13e59
7
- data.tar.gz: c6ff857e320a7708eebdc9b15e7bfa9f0fa261d1ffa51311eed8adb7a2d31220ea15f9199b6e9d2a77472ec1fb01c4fc246aaa4fc301949b23cc3cb48aa9a2bf
6
+ metadata.gz: 715cdb2ae1c2c8a4f37ae47665ffd1d146e1e31147984e57431aae7bc2afab9da6f1e155229db3aacba9ad45ae245dbfe46d6464d7ada0d72208dfc8c6adcdfb
7
+ data.tar.gz: 7ad6cf31ed7bfd150c99392d9213a50bf6a3fe1b949db77f3470a60b014c604b30ac99451ac35173d522582cc9834ae9de099b6c987bcfced9bbff275c5fabae
@@ -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(**args)
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(**args)
10
+ end
11
+
12
+ end
@@ -8,7 +8,7 @@ class CloudflareClient::Organization < CloudflareClient
8
8
  def initialize(args)
9
9
  @org_id = args.delete(:org_id)
10
10
  id_check(:org_id, org_id)
11
- super
11
+ super(**args)
12
12
  end
13
13
 
14
14
  ##
@@ -1,9 +1,4 @@
1
1
  class CloudflareClient::Railgun < CloudflareClient
2
- ##
3
- # Railgun methods
4
- def initialize(*args)
5
- super
6
- end
7
2
 
8
3
  ##
9
4
  # create(name: 'name of railgun')
@@ -1,3 +1,3 @@
1
1
  class CloudflareClient
2
- VERSION = "4.2.7"
2
+ VERSION = "5.0.0"
3
3
  end
@@ -7,7 +7,7 @@ class CloudflareClient::VirtualDnsCluster::Analytic < CloudflareClient::VirtualD
7
7
  def initialize(args)
8
8
  @virtual_dns_id = args.delete(:virtual_dns_id)
9
9
  id_check(:virtual_dns_id, virtual_dns_id)
10
- super
10
+ super(**args)
11
11
  end
12
12
 
13
13
  def report(dimensions:, metrics:, since_ts:, until_ts:, filters: nil, sort: nil, limit: nil)
@@ -22,7 +22,7 @@ class CloudflareClient::VirtualDnsCluster < CloudflareClient
22
22
  @uri_prefix = "/organizations/#{org_id}"
23
23
  end
24
24
 
25
- super
25
+ super(**args)
26
26
  end
27
27
 
28
28
  ##
@@ -4,6 +4,6 @@ class CloudflareClient::Zone::Base < CloudflareClient::Zone
4
4
  def initialize(args)
5
5
  @zone_id = args.delete(:zone_id)
6
6
  id_check('zone_id', zone_id)
7
- super
7
+ super(**args)
8
8
  end
9
9
  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}/custom_certficates", params: params)
29
+ cf_get(path: "/zones/#{zone_id}/custom_certificates", params: params)
30
30
  end
31
31
 
32
32
  ##
@@ -4,6 +4,6 @@ class CloudflareClient::Zone::Firewall::WAFPackage::Base < CloudflareClient::Zon
4
4
  def initialize(args)
5
5
  @package_id = args.delete(:package_id)
6
6
  id_check('package_id', package_id)
7
- super
7
+ super(**args)
8
8
  end
9
9
  end
@@ -10,10 +10,10 @@ class CloudflareClient::Zone::Log < CloudflareClient::Zone::Base
10
10
  timestamp_check(:end_time, end_time) unless end_time.nil?
11
11
 
12
12
  params = Hash.new
13
-
13
+ minute = 60
14
14
 
15
15
  if start_time.nil?
16
- params[:start] = (Time.now - 20.minute).to_i
16
+ params[:start] = (Time.now - (20 * minute)).to_i
17
17
  else
18
18
  timestamp_check(:start_time, start_time)
19
19
  params[:start] = start_time
@@ -21,7 +21,7 @@ class CloudflareClient::Zone::Log < CloudflareClient::Zone::Base
21
21
 
22
22
 
23
23
  if end_time.nil?
24
- params[:end] = (Time.now - 5.minute).to_i
24
+ params[:end] = (Time.now - (5 * minute)).to_i
25
25
  else
26
26
  timestamp_check(:end_time, end_time)
27
27
  params[:end] = end_time
@@ -5,12 +5,6 @@ class CloudflareClient
5
5
 
6
6
  VALID_ZONE_STATUSES = %w[active pending initializing moved deleted deactivated].freeze
7
7
 
8
- ##
9
- # Zone based operations
10
- def initialize(*args)
11
- super
12
- end
13
-
14
8
  ##
15
9
  # list_zones will either list all zones or search for zones based on params
16
10
  # results are paginated!
@@ -51,10 +51,10 @@ class CloudflareClient
51
51
  websockets
52
52
  ].freeze
53
53
 
54
- def initialize(auth_key: nil, email: nil, &block)
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, &block)
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
@@ -133,14 +133,20 @@ class CloudflareClient
133
133
  def build_client(params)
134
134
  # we need multipart form encoding for some of these operations
135
135
  client = Faraday.new(url: API_BASE) do |conn|
136
- conn.request :multipart
136
+ # conn.request :multipart
137
137
  conn.request :url_encoded
138
138
  conn.use Middleware::Response::RaiseError
139
139
  end
140
- client.headers['X-Auth-Key'] = params[:auth_key]
141
- client.headers['X-Auth-User-Service-Key '] = params[:auth_key] #FIXME, is this always the same?
142
- client.headers['X-Auth-Email'] = params[:email]
140
+
143
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
+
144
150
  yield client if block_given?
145
151
  client.adapter :net_http
146
152
  client
@@ -174,16 +180,21 @@ class CloudflareClient
174
180
  JSON.parse(result.body, symbolize_names: true)
175
181
  end
176
182
 
177
- def cf_put(path: nil, data: nil)
183
+ def cf_put(path: nil, data: nil, params: nil)
178
184
  result = @cf_client.put do |request|
179
185
  request.url(API_BASE + path) unless path.nil?
180
- request.body = data.to_json unless data.nil?
186
+ unless data.nil?
187
+ request.body = data.kind_of?(String) ? data : data.to_json
188
+ end
189
+ unless params.nil?
190
+ request.params = params if params.values.any? { |i| !i.nil? }
191
+ end
181
192
  end
182
193
  JSON.parse(result.body, symbolize_names: true)
183
194
  end
184
195
 
185
196
  def cf_patch(path: nil, data: {})
186
- result = @cf_client.patch do |request|
197
+ result = @cf_client.patch do |request|
187
198
  request.url(API_BASE + path) unless path.nil?
188
199
  request.body = data.to_json unless data.empty?
189
200
  end
@@ -203,4 +214,4 @@ class CloudflareClient
203
214
  return false unless POSSIBLE_API_SETTINGS.include?(name)
204
215
  true
205
216
  end
206
- end
217
+ 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.2.7
4
+ version: 5.0.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: 2019-07-16 00:00:00.000000000 Z
11
+ date: 2022-08-03 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 License Version 2.0
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
@@ -62,16 +65,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
65
  requirements:
63
66
  - - ">="
64
67
  - !ruby/object:Gem::Version
65
- version: 2.3.0
68
+ version: 3.1.0
66
69
  required_rubygems_version: !ruby/object:Gem::Requirement
67
70
  requirements:
68
71
  - - ">="
69
72
  - !ruby/object:Gem::Version
70
73
  version: '0'
71
74
  requirements: []
72
- rubyforge_project:
73
- rubygems_version: 2.6.11
74
- signing_key:
75
+ rubygems_version: 3.3.7
76
+ signing_key:
75
77
  specification_version: 4
76
78
  summary: lightweight cloudflare api client
77
79
  test_files: []