cloudflare 4.1.1 → 4.3.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: 79a8768ecb786ce6c1c3af592c2adbc33156f2cd9148273ce3774e3d5ed74392
4
- data.tar.gz: 19c2bb97be2cb08fb36b538501d816ad968af53a7552564fc9f1a669baddab9a
3
+ metadata.gz: 7df158b1fb45428a5bd2f3a2147700e691ed6a4bdadbc26f7a6cf0229d77ff98
4
+ data.tar.gz: 909cd8848e8368d670592c2108ffe1231147226d56d98e23e499807f48d80e8c
5
5
  SHA512:
6
- metadata.gz: d2f3272dd96f2c821877ca85dc38e4d692e95bcfe1c54a6141dd72bce16aa6225a06fabf371496724bdda4136271c0c6c3ef5a313713a50189b75ffa6666cbd2
7
- data.tar.gz: 290ebb0294ec423404726303811a44c9c98dcc727716bdf29a2868b0c2938a771a4c6f15a3ed36ef96df54ed3d71c0374f3d87f2694ebc35a6c1cf2a20ad7031
6
+ metadata.gz: df08439266659d4232501e8cd22dc1013b5d7d764c9c0d09c3a2768704cb460031ef69139c72de03b5c84b3e8618e1714c1b00624652e3dd557e9206a0fedd3b
7
+ data.tar.gz: 7c006538e659c65ff3059f6bbbac4feaeed6ac36763f683498be20b2cc8b0ff7d42e0bc43faeda1a8786967a829b152d7575f52c8904502302c7a2a0aa818b95
data/lib/cloudflare.rb CHANGED
@@ -25,13 +25,13 @@ require 'async'
25
25
  require_relative 'cloudflare/connection'
26
26
 
27
27
  module Cloudflare
28
- DEFAULT_URL = 'https://api.cloudflare.com/client/v4'
28
+ DEFAULT_ENDPOINT = Async::HTTP::Endpoint.parse('https://api.cloudflare.com/client/v4')
29
29
 
30
- def self.connect(key: nil, email: nil)
31
- representation = Connection.for(DEFAULT_URL)
30
+ def self.connect(endpoint = DEFAULT_ENDPOINT, **auth_info)
31
+ representation = Connection.for(endpoint)
32
32
 
33
- if key
34
- representation = representation.authenticated(key, email)
33
+ if !auth_info.empty?
34
+ representation = representation.authenticated(**auth_info)
35
35
  end
36
36
 
37
37
  return representation unless block_given?
@@ -33,7 +33,7 @@ module Cloudflare
33
33
  end
34
34
 
35
35
  def kv_namespaces
36
- KV::Namespaces.new(@resource.with(path: 'storage/kv/namespaces'))
36
+ self.with(KV::Namespaces, path: 'storage/kv/namespaces')
37
37
  end
38
38
  end
39
39
 
@@ -28,29 +28,33 @@ require_relative 'user'
28
28
 
29
29
  module Cloudflare
30
30
  class Connection < Representation
31
- def authenticated(key, email = nil)
31
+ def authenticated(token: nil, key: nil, email: nil)
32
32
  headers = {}
33
33
 
34
- if email.nil?
35
- headers['X-Auth-User-Service-Key'] = key
36
- else
37
- headers['X-Auth-Key'] = key
38
- headers['X-Auth-Email'] = email
34
+ if token
35
+ headers['Authorization'] = "Bearer #{token}"
36
+ elsif key
37
+ if email
38
+ headers['X-Auth-Key'] = key
39
+ headers['X-Auth-Email'] = email
40
+ else
41
+ headers['X-Auth-User-Service-Key'] = key
42
+ end
39
43
  end
40
44
 
41
- self.class.new(@resource.with(headers: headers))
45
+ self.with(headers: headers)
42
46
  end
43
47
 
44
48
  def zones
45
- Zones.new(@resource.with(path: 'zones'))
49
+ self.with(Zones, path: 'zones')
46
50
  end
47
51
 
48
52
  def accounts
49
- Accounts.new(@resource.with(path: 'accounts'))
53
+ self.with(Accounts, path: 'accounts')
50
54
  end
51
55
 
52
56
  def user
53
- User.new(@resource.with(path: 'user'))
57
+ self.with(User, path: 'user')
54
58
  end
55
59
  end
56
60
  end
@@ -34,11 +34,12 @@ module Cloudflare
34
34
  @record = record || get.result
35
35
  end
36
36
 
37
- def update_content(content)
37
+ def update_content(content, **options)
38
38
  response = put(
39
39
  type: @record[:type],
40
40
  name: @record[:name],
41
- content: content
41
+ content: content,
42
+ **options
42
43
  )
43
44
 
44
45
  @value = response.result
@@ -56,6 +57,10 @@ module Cloudflare
56
57
  value[:content]
57
58
  end
58
59
 
60
+ def proxied
61
+ value[:proxied]
62
+ end
63
+
59
64
  def to_s
60
65
  "#{@record[:name]} #{@record[:type]} #{@record[:content]}"
61
66
  end
@@ -5,6 +5,7 @@
5
5
 
6
6
  require_relative '../paginate'
7
7
  require_relative '../representation'
8
+ require_relative 'rest_wrapper'
8
9
 
9
10
  module Cloudflare
10
11
  module KV
@@ -32,7 +33,7 @@ module Cloudflare
32
33
  end
33
34
 
34
35
  def keys
35
- Keys.new(@resource.with(path: 'keys'))
36
+ self.with(Keys, path: 'keys')
36
37
  end
37
38
 
38
39
  def read_value(name)
@@ -55,7 +56,8 @@ module Cloudflare
55
56
  private
56
57
 
57
58
  def value_representation(name)
58
- Representation.new(@resource.with(path: "values/#{name}"))
59
+ @representation_class ||= Representation[RESTWrapper]
60
+ self.with(@representation_class, path: "values/#{name}")
59
61
  end
60
62
  end
61
63
 
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Cloudflare
6
+ module KV
7
+ class RESTWrapper < Async::REST::Wrapper::Generic
8
+ APPLICATION_OCTET_STREAM = 'application/octet-stream'
9
+ APPLICATION_JSON = 'application/json'
10
+ ACCEPT_HEADER = "#{APPLICATION_JSON}, #{APPLICATION_OCTET_STREAM}"
11
+
12
+ def prepare_request(payload, headers)
13
+ headers['accept'] ||= ACCEPT_HEADER
14
+
15
+ if payload
16
+ headers['content-type'] = APPLICATION_OCTET_STREAM
17
+ ::Protocol::HTTP::Body::Buffered.new([payload.to_s])
18
+ end
19
+ end
20
+
21
+ def parser_for(response)
22
+ if response.headers['content-type'].start_with?(APPLICATION_OCTET_STREAM)
23
+ OctetParser
24
+ elsif response.headers['content-type'].start_with?(APPLICATION_JSON)
25
+ JsonParser
26
+ else
27
+ Async::REST::Wrapper::Generic::Unsupported
28
+ end
29
+ end
30
+
31
+ class OctetParser < ::Protocol::HTTP::Body::Wrapper
32
+ def join
33
+ super
34
+ end
35
+ end
36
+
37
+ class JsonParser < ::Protocol::HTTP::Body::Wrapper
38
+ def join
39
+ JSON.parse(super, symbolize_names: true)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -37,7 +37,7 @@ module Cloudflare
37
37
  page += 1
38
38
 
39
39
  # Was this the last page?
40
- break if zones.value.count < per_page
40
+ break if zones.value.size < per_page
41
41
  end
42
42
  end
43
43
 
@@ -21,13 +21,15 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  require 'async/rspec'
24
+ require 'async/http/proxy'
25
+
24
26
  require_relative '../../cloudflare'
25
27
 
26
28
  module Cloudflare
27
29
  module RSpec
28
30
  module Connection
29
31
  end
30
-
32
+
31
33
  RSpec.shared_context Connection do
32
34
  include_context Async::RSpec::Reactor
33
35
 
@@ -35,10 +37,20 @@ module Cloudflare
35
37
  let(:email) {ENV['CLOUDFLARE_EMAIL']}
36
38
  let(:key) {ENV['CLOUDFLARE_KEY']}
37
39
 
38
- let(:connection) {@connection = Cloudflare.connect(key: key, email: email)}
40
+ let(:connection) do
41
+ if proxy_url = ENV['CLOUDFLARE_PROXY']
42
+ proxy_endpoint = Async::HTTP::Endpoint.parse(proxy_url)
43
+ @client = Async::HTTP::Client.new(proxy_endpoint)
44
+ @connection = Cloudflare.connect(@client.proxied_endpoint(DEFAULT_ENDPOINT), key: key, email: email)
45
+ else
46
+ @client = nil
47
+ @connection = Cloudflare.connect(key: key, email: email)
48
+ end
49
+ end
39
50
 
40
51
  after do
41
52
  @connection&.close
53
+ @client&.close
42
54
  end
43
55
  end
44
56
  end
@@ -22,5 +22,5 @@
22
22
  # THE SOFTWARE.
23
23
 
24
24
  module Cloudflare
25
- VERSION = '4.1.1'
25
+ VERSION = '4.3.0'
26
26
  end
@@ -33,19 +33,19 @@ require_relative 'logs'
33
33
  module Cloudflare
34
34
  class Zone < Representation
35
35
  def custom_hostnames
36
- CustomHostnames.new(@resource.with(path: 'custom_hostnames'))
36
+ self.with(CustomHostnames, path: 'custom_hostnames')
37
37
  end
38
38
 
39
39
  def dns_records
40
- DNS::Records.new(@resource.with(path: 'dns_records'))
40
+ self.with(DNS::Records, path: 'dns_records')
41
41
  end
42
42
 
43
43
  def firewall_rules
44
- Firewall::Rules.new(@resource.with(path: 'firewall/access_rules/rules'))
44
+ self.with(Firewall::Rules, path: 'firewall/access_rules/rules')
45
45
  end
46
46
 
47
47
  def logs
48
- Logs::Received.new(@resource.with(path: 'logs/received'))
48
+ self.with(Logs::Received, path: 'logs/received')
49
49
  end
50
50
 
51
51
  DEFAULT_PURGE_CACHE_PARAMS = {
@@ -53,7 +53,7 @@ module Cloudflare
53
53
  }.freeze
54
54
 
55
55
  def purge_cache(parameters = DEFAULT_PURGE_CACHE_PARAMS)
56
- Zone.new(@resource.with(path: 'purge_cache')).post(parameters)
56
+ self.with(Zone, path: 'purge_cache').post(parameters)
57
57
 
58
58
  return self
59
59
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflare
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.1
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Prokop
8
8
  - Samuel Williams
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-06-21 00:00:00.000000000 Z
12
+ date: 2021-06-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: async-rest
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 0.8.0
20
+ version: 0.12.3
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 0.8.0
27
+ version: 0.12.3
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: async-rspec
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -39,20 +39,6 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
- - !ruby/object:Gem::Dependency
43
- name: covered
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '0'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
42
  - !ruby/object:Gem::Dependency
57
43
  name: bundler
58
44
  requirement: !ruby/object:Gem::Requirement
@@ -68,7 +54,7 @@ dependencies:
68
54
  - !ruby/object:Gem::Version
69
55
  version: '0'
70
56
  - !ruby/object:Gem::Dependency
71
- name: rake
57
+ name: covered
72
58
  requirement: !ruby/object:Gem::Requirement
73
59
  requirements:
74
60
  - - ">="
@@ -95,21 +81,12 @@ dependencies:
95
81
  - - "~>"
96
82
  - !ruby/object:Gem::Version
97
83
  version: '3.6'
98
- description:
84
+ description:
99
85
  email:
100
- - marcin@prokop.co
101
- - samuel.williams@oriontransfer.co.nz
102
86
  executables: []
103
87
  extensions: []
104
88
  extra_rdoc_files: []
105
89
  files:
106
- - ".gitignore"
107
- - ".rspec"
108
- - ".travis.yml"
109
- - Gemfile
110
- - README.md
111
- - Rakefile
112
- - cloudflare.gemspec
113
90
  - lib/cloudflare.rb
114
91
  - lib/cloudflare/accounts.rb
115
92
  - lib/cloudflare/connection.rb
@@ -119,6 +96,7 @@ files:
119
96
  - lib/cloudflare/dns.rb
120
97
  - lib/cloudflare/firewall.rb
121
98
  - lib/cloudflare/kv/namespaces.rb
99
+ - lib/cloudflare/kv/rest_wrapper.rb
122
100
  - lib/cloudflare/logs.rb
123
101
  - lib/cloudflare/paginate.rb
124
102
  - lib/cloudflare/representation.rb
@@ -126,20 +104,11 @@ files:
126
104
  - lib/cloudflare/user.rb
127
105
  - lib/cloudflare/version.rb
128
106
  - lib/cloudflare/zones.rb
129
- - spec/cloudflare/accounts_spec.rb
130
- - spec/cloudflare/custom_hostname/ssl_attribute/settings_spec.rb
131
- - spec/cloudflare/custom_hostname/ssl_attribute_spec.rb
132
- - spec/cloudflare/custom_hostnames_spec.rb
133
- - spec/cloudflare/dns_spec.rb
134
- - spec/cloudflare/firewall_spec.rb
135
- - spec/cloudflare/kv/namespaces_spec.rb
136
- - spec/cloudflare/zone_spec.rb
137
- - spec/spec_helper.rb
138
- homepage: https://github.com/b4k3r/cloudflare
107
+ homepage: https://github.com/socketry/cloudflare
139
108
  licenses:
140
109
  - MIT
141
110
  metadata: {}
142
- post_install_message:
111
+ post_install_message:
143
112
  rdoc_options: []
144
113
  require_paths:
145
114
  - lib
@@ -147,24 +116,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
116
  requirements:
148
117
  - - ">="
149
118
  - !ruby/object:Gem::Version
150
- version: 2.0.0
119
+ version: '2.5'
151
120
  required_rubygems_version: !ruby/object:Gem::Requirement
152
121
  requirements:
153
122
  - - ">="
154
123
  - !ruby/object:Gem::Version
155
124
  version: '0'
156
125
  requirements: []
157
- rubygems_version: 3.0.2
158
- signing_key:
126
+ rubygems_version: 3.1.6
127
+ signing_key:
159
128
  specification_version: 4
160
129
  summary: A Ruby wrapper for the Cloudflare API.
161
- test_files:
162
- - spec/cloudflare/accounts_spec.rb
163
- - spec/cloudflare/custom_hostname/ssl_attribute/settings_spec.rb
164
- - spec/cloudflare/custom_hostname/ssl_attribute_spec.rb
165
- - spec/cloudflare/custom_hostnames_spec.rb
166
- - spec/cloudflare/dns_spec.rb
167
- - spec/cloudflare/firewall_spec.rb
168
- - spec/cloudflare/kv/namespaces_spec.rb
169
- - spec/cloudflare/zone_spec.rb
170
- - spec/spec_helper.rb
130
+ test_files: []
data/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
-
11
- # rspec failure tracking
12
- .rspec_status
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --format documentation
2
- --backtrace
3
- --warnings
4
- --require spec_helper
data/.travis.yml DELETED
@@ -1,25 +0,0 @@
1
- language: ruby
2
- dist: xenial
3
- cache: bundler
4
-
5
- matrix:
6
- include:
7
- - rvm: 2.3
8
- - rvm: 2.4
9
- - rvm: 2.5
10
- - rvm: 2.6
11
- - rvm: 2.6
12
- env: COVERAGE=BriefSummary,Coveralls
13
- - rvm: jruby-head
14
- env: JRUBY_OPTS="--debug -X+O"
15
- - rvm: truffleruby
16
- - rvm: ruby-head
17
- allow_failures:
18
- - rvm: ruby-head
19
- - rvm: jruby-head
20
- - rvm: truffleruby
21
-
22
- env:
23
- global:
24
- - CLOUDFLARE_TEST_ZONE_MANAGEMENT=true
25
- - secure: c5yG7N1r9nYuw47Y90jGeoHNvkL59AAC55dtPAhKP+gjXWW8hKbntj3oj+lVkxEqzRpzEQgYZzUElrP+6mJnb20ldclZg03L56243tMtVEcpGOx/MFhnIBkx3kKu1H6ydKKMxieHxjsLQ3vnpcIZ3p0skTQjYbjdu607tjbyg7s=
data/Gemfile DELETED
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Specify your gem's dependencies in cloudflare.gemspec
6
- gemspec
7
-
8
- group :development do
9
- gem 'pry'
10
- gem 'pry-coolline'
11
- end
12
-
13
- group :test do
14
- gem 'coveralls', require: false
15
- gem 'simplecov'
16
- gem 'sinatra'
17
- gem 'webmock'
18
- end
data/README.md DELETED
@@ -1,106 +0,0 @@
1
- # Cloudflare
2
-
3
- It is a Ruby wrapper for the Cloudflare V4 API. It provides a light weight wrapper using `RestClient::Resource`. The wrapper functionality is limited to zones and DNS records at this time, *PRs welcome*.
4
-
5
- [![Build Status](https://secure.travis-ci.org/socketry/cloudflare.svg)](http://travis-ci.org/socketry/cloudflare)
6
- [![Coverage Status](https://coveralls.io/repos/socketry/cloudflare/badge.svg)](https://coveralls.io/r/socketry/cloudflare)
7
-
8
- ## Installation
9
-
10
- Add this line to your application's Gemfile:
11
-
12
- ```ruby
13
- gem 'cloudflare'
14
- ```
15
-
16
- And then execute:
17
-
18
- ```
19
- $ bundle
20
- ```
21
-
22
- Or install it yourself as:
23
-
24
- ```
25
- $ gem install cloudflare
26
- ```
27
-
28
- ## Usage
29
-
30
- Here are some basic examples. For more details, refer to the code and specs.
31
-
32
- ```ruby
33
- require 'cloudflare'
34
-
35
- # Grab some details from somewhere:
36
- email = ENV['CLOUDFLARE_EMAIL']
37
- key = ENV['CLOUDFLARE_KEY']
38
-
39
- Cloudflare.connect(key: key, email: email) do |connection|
40
- # Get all available zones:
41
- zones = connection.zones
42
-
43
- # Get a specific zone:
44
- zone = connection.zones.find_by_id("...")
45
- zone = connection.zones.find_by_name("example.com")
46
-
47
- # Get DNS records for a given zone:
48
- dns_records = zone.dns_records
49
-
50
- # Show some details of the DNS record:
51
- dns_record = dns_records.first
52
- puts dns_record.name
53
-
54
- # Add a DNS record. Here we add an A record for `batman.example.com`:
55
- zone = zones.find_by_name("example.com")
56
- zone.dns_records.create('A', 'batman', '1.2.3.4', proxied: false)
57
-
58
- # Get firewall rules:
59
- all_rules = zone.firewall_rules
60
-
61
- # Block an ip:
62
- rule = zone.firewall_rules.set('block', '1.2.3.4', notes: "ssh dictionary attack")
63
- end
64
- ```
65
-
66
- ## Contributing
67
-
68
- 1. Fork it
69
- 2. Create your feature branch (`git checkout -b my-new-feature`)
70
- 3. Commit your changes (`git commit -am 'Add some feature'`)
71
- 4. Push to the branch (`git push origin my-new-feature`)
72
- 5. Create new Pull Request
73
-
74
- ## See Also
75
-
76
- - [Cloudflare::DNS::Update](https://github.com/ioquatix/cloudflare-dns-update) - A dynamic DNS updater based on this gem.
77
- - [Rubyflare](https://github.com/trev/rubyflare) - Another implementation.
78
-
79
- ## License
80
-
81
- Released under the MIT license.
82
-
83
- Copyright, 2018, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
84
- Copyright, 2017, by [David Rosenbloom](http://artifactory.com).
85
- Copyright, 2012, 2014, by [Marcin Prokop](https://github.com/b4k3r).
86
-
87
- Permission is hereby granted, free of charge, to any person obtaining a copy
88
- of this software and associated documentation files (the "Software"), to deal
89
- in the Software without restriction, including without limitation the rights
90
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
91
- copies of the Software, and to permit persons to whom the Software is
92
- furnished to do so, subject to the following conditions:
93
-
94
- The above copyright notice and this permission notice shall be included in
95
- all copies or substantial portions of the Software.
96
-
97
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
98
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
99
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
100
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
101
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
102
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
103
- THE SOFTWARE.
104
-
105
-
106
-
data/Rakefile DELETED
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:test)
7
-
8
- task default: :test
9
-
10
- task :coverage do
11
- ENV['COVERAGE'] = 'y'
12
- end
13
-
14
- task :console do
15
- require_relative 'lib/cloudflare'
16
- require 'pry'
17
-
18
- email = ENV.fetch('CLOUDFLARE_EMAIL')
19
- key = ENV.fetch('CLOUDFLARE_KEY')
20
-
21
- Async.run do
22
- connection = Cloudflare.connect(key: key, email: email)
23
-
24
- binding.pry
25
- end
26
- end
data/cloudflare.gemspec DELETED
@@ -1,32 +0,0 @@
1
-
2
- # frozen_string_literal: true
3
-
4
- require_relative 'lib/cloudflare/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'cloudflare'
8
- spec.version = Cloudflare::VERSION
9
- spec.platform = Gem::Platform::RUBY
10
-
11
- spec.summary = 'A Ruby wrapper for the Cloudflare API.'
12
- spec.authors = ['Marcin Prokop', 'Samuel Williams']
13
- spec.email = ['marcin@prokop.co', 'samuel.williams@oriontransfer.co.nz']
14
- spec.homepage = 'https://github.com/b4k3r/cloudflare'
15
- spec.licenses = ['MIT']
16
-
17
- spec.files = `git ls-files`.split("\n")
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ['lib']
21
-
22
- spec.required_ruby_version = '>= 2.0.0'
23
-
24
- spec.add_dependency 'async-rest', '~> 0.8.0'
25
-
26
- spec.add_development_dependency 'async-rspec'
27
-
28
- spec.add_development_dependency 'covered'
29
- spec.add_development_dependency 'bundler'
30
- spec.add_development_dependency 'rake'
31
- spec.add_development_dependency 'rspec', '~> 3.6'
32
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Cloudflare::Accounts, order: :defined, timeout: 30 do
4
- include_context Cloudflare::Account
5
-
6
- before do
7
- account.id # Force a fetch if it hasn't happened yet
8
- end
9
-
10
- it 'can list existing accounts' do
11
- accounts = connection.accounts.to_a
12
- expect(accounts.any? {|a| a.id == account.id }).to be true
13
- end
14
-
15
- it 'can get a specific account' do
16
- expect(connection.accounts.find_by_id(account.id).id).to eq account.id
17
- end
18
-
19
- it 'can generate a representation for the KV namespace endpoint' do
20
- ns = connection.accounts.find_by_id(account.id).kv_namespaces
21
- expect(ns).to be_kind_of(Cloudflare::KV::Namespaces)
22
- expect(ns.resource.reference.path).to end_with("/#{account.id}/storage/kv/namespaces")
23
- end
24
- end
@@ -1,54 +0,0 @@
1
- RSpec.describe Cloudflare::CustomHostname::SSLAttribute::Settings do
2
-
3
- subject { described_class.new({}) }
4
-
5
- it 'has an accessor for ciphers' do
6
- ciphers = double
7
- expect(subject.ciphers).to be_nil
8
- subject.ciphers = ciphers
9
- expect(subject.ciphers).to be ciphers
10
- end
11
-
12
- it 'has a boolean accessor for http2' do
13
- expect(subject.http2).to be_nil
14
- expect(subject.http2?).to be false
15
- subject.http2 = true
16
- expect(subject.http2).to eq 'on'
17
- expect(subject.http2?).to be true
18
- subject.http2 = false
19
- expect(subject.http2).to eq 'off'
20
- expect(subject.http2?).to be false
21
- subject.http2 = 'on'
22
- expect(subject.http2).to eq 'on'
23
- expect(subject.http2?).to be true
24
- subject.http2 = 'off'
25
- expect(subject.http2).to eq 'off'
26
- expect(subject.http2?).to be false
27
- end
28
-
29
- it 'has an accessor for min_tls_version' do
30
- tls_version = double
31
- expect(subject.min_tls_version).to be_nil
32
- subject.min_tls_version = tls_version
33
- expect(subject.min_tls_version).to be tls_version
34
- end
35
-
36
- it 'has a boolean accessor for tls_1_3' do
37
- expect(subject.tls_1_3).to be_nil
38
- expect(subject.tls_1_3?).to be false
39
- subject.tls_1_3 = true
40
- expect(subject.tls_1_3).to eq 'on'
41
- expect(subject.tls_1_3?).to be true
42
- subject.tls_1_3 = false
43
- expect(subject.tls_1_3).to eq 'off'
44
- expect(subject.tls_1_3?).to be false
45
- subject.tls_1_3 = 'on'
46
- expect(subject.tls_1_3).to eq 'on'
47
- expect(subject.tls_1_3?).to be true
48
- subject.tls_1_3 = 'off'
49
- expect(subject.tls_1_3).to eq 'off'
50
- expect(subject.tls_1_3?).to be false
51
- end
52
-
53
-
54
- end
@@ -1,73 +0,0 @@
1
- RSpec.describe Cloudflare::CustomHostname::SSLAttribute do
2
-
3
- accessors = [:cname, :cname_target, :http_body, :http_url, :method, :status, :type, :validation_errors]
4
-
5
- let(:original_hash) { {} }
6
-
7
- subject { described_class.new(original_hash) }
8
-
9
- accessors.each do |key|
10
-
11
- it "has an accessor for the #{key} value" do
12
- test_value = double
13
- expect(subject.send(key)).to be_nil
14
- original_hash[key] = test_value
15
- expect(subject.send(key)).to be test_value
16
- end
17
-
18
- end
19
-
20
- it '#active? returns true when the status is "active" and false otherwise' do
21
- expect(subject.active?).to be false
22
- original_hash[:status] = 'initializing'
23
- expect(subject.active?).to be false
24
- original_hash[:status] = 'pending_validation'
25
- expect(subject.active?).to be false
26
- original_hash[:status] = 'pending_deployment'
27
- expect(subject.active?).to be false
28
- original_hash[:status] = 'active'
29
- expect(subject.active?).to be true
30
- end
31
-
32
- it '#pending_validation? returns true when the status is "pending_validation" and false otherwise' do
33
- expect(subject.pending_validation?).to be false
34
- original_hash[:status] = 'initializing'
35
- expect(subject.pending_validation?).to be false
36
- original_hash[:status] = 'active'
37
- expect(subject.pending_validation?).to be false
38
- original_hash[:status] = 'pending_deployment'
39
- expect(subject.pending_validation?).to be false
40
- original_hash[:status] = 'pending_validation'
41
- expect(subject.pending_validation?).to be true
42
- end
43
-
44
- describe '#settings' do
45
-
46
- it 'should return a Settings object' do
47
- expect(subject.settings).to be_kind_of Cloudflare::CustomHostname::SSLAttribute::Settings
48
- end
49
-
50
- it 'initailizes the settings object with the value from the settings key' do
51
- settings = { min_tls_version: double }
52
- original_hash[:settings] = settings
53
- expect(subject.settings.min_tls_version).to be settings[:min_tls_version]
54
- end
55
-
56
- it 'initializes the settings object with a new hash if the settings key does not exist' do
57
- expected_value = double
58
- expect(original_hash[:settings]).to be_nil
59
- expect(subject.settings.min_tls_version).to be_nil
60
- expect(original_hash[:settings]).not_to be_nil
61
- original_hash[:settings][:min_tls_version] = expected_value
62
- expect(subject.settings.min_tls_version).to be expected_value
63
- end
64
-
65
- it 'updates the stored hash with values set on the settings object' do
66
- expected_value = double
67
- expect(subject.settings.min_tls_version).to be_nil
68
- subject.settings.min_tls_version = expected_value
69
- expect(original_hash[:settings][:min_tls_version]).to be expected_value
70
- end
71
- end
72
-
73
- end
@@ -1,213 +0,0 @@
1
-
2
- RSpec.describe Cloudflare::CustomHostnames, order: :defined, timeout: 30 do
3
- include_context Cloudflare::Zone
4
-
5
- let(:domain) { "www#{ENV['TRAVIS_JOB_ID'] || rand(1..5)}.ourtest.com" }
6
-
7
- let(:record) { @record = zone.custom_hostnames.create(domain) }
8
-
9
- let(:custom_origin) do
10
- id = rand(1...100)
11
- id += (job_id * 100) if job_id.positive?
12
- subdomain = "origin-#{id}"
13
- @dns_record = zone.dns_records.create("A", subdomain, "1.2.3.4") # This needs to exist or the calls will fail
14
- "#{subdomain}.#{zone.name}"
15
- end
16
-
17
- after do
18
- if defined? @record
19
- expect(@record.delete).to be_success
20
- end
21
-
22
- if defined? @dns_record
23
- expect(@dns_record.delete).to be_success
24
- end
25
- end
26
-
27
- it 'can create a custom hostname record' do
28
- expect(record).to be_kind_of Cloudflare::CustomHostname
29
- expect(record.custom_metadata).to be_nil
30
- expect(record.hostname).to eq domain
31
- expect(record.custom_origin).to be_nil
32
- expect(record.ssl.method).to eq 'http'
33
- expect(record.ssl.type).to eq 'dv'
34
- end
35
-
36
- it 'can create a custom hostname record with a custom origin' do
37
- begin
38
- @record = zone.custom_hostnames.create(domain, origin: custom_origin)
39
-
40
- expect(@record).to be_kind_of Cloudflare::CustomHostname
41
- expect(@record.custom_metadata).to be_nil
42
- expect(@record.hostname).to eq domain
43
- expect(@record.custom_origin).to eq custom_origin
44
- expect(@record.ssl.method).to eq 'http'
45
- expect(@record.ssl.type).to eq 'dv'
46
- rescue Cloudflare::RequestError => e
47
- if e.message.include?('custom origin server has not been granted')
48
- skip(e.message) # This currently doesn't work but might start eventually: https://github.com/socketry/async-rspec/issues/7
49
- else
50
- raise
51
- end
52
- end
53
- end
54
-
55
- it 'can create a custom hostname record with different ssl options' do
56
- @record = zone.custom_hostnames.create(domain, ssl: { method: 'cname' })
57
-
58
- expect(@record).to be_kind_of Cloudflare::CustomHostname
59
- expect(@record.custom_metadata).to be_nil
60
- expect(@record.hostname).to eq domain
61
- expect(@record.custom_origin).to be_nil
62
- expect(@record.ssl.method).to eq 'cname'
63
- expect(@record.ssl.type).to eq 'dv'
64
- end
65
-
66
- it 'can create a custom hostname record with additional metadata' do
67
- metadata = { a: rand(1..10) }
68
-
69
- begin
70
- @record = zone.custom_hostnames.create(domain, metadata: metadata)
71
-
72
- expect(@record).to be_kind_of Cloudflare::CustomHostname
73
- expect(@record.custom_metadata).to eq metadata
74
- expect(@record.hostname).to eq domain
75
- expect(@record.custom_origin).to be_nil
76
- expect(@record.ssl.method).to eq 'http'
77
- expect(@record.ssl.type).to eq 'dv'
78
- rescue Cloudflare::RequestError => e
79
- if e.message.include?('No custom metadata access has been allocated for this zone')
80
- skip(e.message) # This currently doesn't work but might start eventually: https://github.com/socketry/async-rspec/issues/7
81
- else
82
- raise
83
- end
84
- end
85
- end
86
-
87
- it 'can look up an existing custom hostname by the hostname or id' do
88
- expect(zone.custom_hostnames.find_by_hostname(record.hostname).id).to eq record.id
89
- expect(zone.custom_hostnames.find_by_id(record.id).id).to eq record.id
90
- end
91
-
92
- context 'with existing record' do
93
-
94
- it 'returns the hostname when calling #to_s' do
95
- expect(record.to_s).to eq domain
96
- end
97
-
98
- it 'can update metadata' do
99
- metadata = { c: rand(1..10) }
100
-
101
- expect(record.custom_metadata).to be_nil
102
-
103
- begin
104
- record.update_settings(metadata: metadata)
105
-
106
- # Make sure the existing object is updated
107
- expect(record.custom_metadata).to eq metadata
108
-
109
- # Verify that the server has the changes
110
- found_record = zone.custom_hostnames.find_by_id(record.id)
111
-
112
- expect(found_record.custom_metadata).to eq metadata
113
- expect(found_record.hostname).to eq domain
114
- expect(found_record.custom_origin).to be_nil
115
- rescue Cloudflare::RequestError => e
116
- if e.message.include?('No custom metadata access has been allocated for this zone')
117
- skip(e.message) # This currently doesn't work but might start eventually: https://github.com/socketry/async-rspec/issues/7
118
- else
119
- raise
120
- end
121
- end
122
- end
123
-
124
- it 'can update the custom origin' do
125
- expect(record.custom_origin).to be_nil
126
-
127
- begin
128
- record.update_settings(origin: custom_origin)
129
-
130
- # Make sure the existing object is updated
131
- expect(record.custom_origin).to eq custom_origin
132
-
133
- # Verify that the server has the changes
134
- found_record = zone.custom_hostnames.find_by_id(record.id)
135
-
136
- expect(found_record.custom_metadata).to be_nil
137
- expect(found_record.hostname).to eq domain
138
- expect(found_record.custom_origin).to eq custom_origin
139
- rescue Cloudflare::RequestError => e
140
- if e.message.include?('custom origin server has not been granted')
141
- skip(e.message) # This currently doesn't work but might start eventually: https://github.com/socketry/async-rspec/issues/7
142
- else
143
- raise
144
- end
145
- end
146
- end
147
-
148
- it 'can update ssl information' do
149
- expect(record.ssl.method).to eq 'http'
150
-
151
- record.update_settings(ssl: { method: 'cname', type: 'dv' })
152
-
153
- # Make sure the existing object is updated
154
- expect(record.ssl.method).to eq 'cname'
155
-
156
- # Verify that the server has the changes
157
- found_record = zone.custom_hostnames.find_by_id(record.id)
158
-
159
- expect(found_record.custom_metadata).to be_nil
160
- expect(found_record.hostname).to eq domain
161
- expect(found_record.custom_origin).to be_nil
162
- expect(found_record.ssl.method).to eq 'cname'
163
- end
164
-
165
- context 'has an ssl section' do
166
-
167
- it 'wraps it in an SSLAttributes object' do
168
- expect(record.ssl).to be_kind_of Cloudflare::CustomHostname::SSLAttribute
169
- end
170
-
171
- it 'has some helpers for commonly used keys' do
172
- # Make sure our values exist before we check to make sure that they are returned correctly
173
- expect(record.value[:ssl].values_at(:method, :http_body, :http_url).compact).not_to be_empty
174
- expect(record.ssl.method).to be record.value[:ssl][:method]
175
- expect(record.ssl.http_body).to be record.value[:ssl][:http_body]
176
- expect(record.ssl.http_url).to be record.value[:ssl][:http_url]
177
- end
178
-
179
- end
180
-
181
- describe '#ssl_active?' do
182
-
183
- it 'returns the result of calling ssl.active?' do
184
- expected_value = double
185
- expect(record.ssl).to receive(:active?).and_return(expected_value)
186
- expect(record).not_to receive(:send_patch)
187
- expect(record.ssl_active?).to be expected_value
188
- end
189
-
190
- it 'returns the result of calling ssl.active? without triggering an update if force_update is true and the ssl is not in the pending_validation state' do
191
- expected_value = double
192
- expect(record.ssl).to receive(:active?).and_return(expected_value)
193
- expect(record.ssl.method).not_to be_nil
194
- expect(record.ssl.type).not_to be_nil
195
- expect(record.ssl.pending_validation?).to be false
196
- expect(record).not_to receive(:send_patch).with(ssl: { method: record.ssl.method, type: record.ssl.type })
197
- expect(record.ssl_active?(true)).to be expected_value
198
- end
199
-
200
- it 'returns the result of calling ssl.active? after triggering an update if force_update is true and the ssl is in the pending_validation state' do
201
- expected_value = double
202
- expect(record.ssl).to receive(:active?).and_return(expected_value)
203
- expect(record.ssl.method).not_to be_nil
204
- expect(record.ssl.type).not_to be_nil
205
- record.value[:ssl][:status] = 'pending_validation'
206
- expect(record).to receive(:send_patch).with(ssl: { method: record.ssl.method, type: record.ssl.type })
207
- expect(record.ssl_active?(true)).to be expected_value
208
- end
209
-
210
- end
211
-
212
- end
213
- end
@@ -1,32 +0,0 @@
1
-
2
- require 'cloudflare/rspec/connection'
3
-
4
- RSpec.describe Cloudflare::DNS, order: :defined, timeout: 30 do
5
- include_context Cloudflare::Zone
6
-
7
- let(:subdomain) {"www#{ENV['TRAVIS_JOB_ID']}"}
8
-
9
- let(:record) {@record = zone.dns_records.create("A", subdomain, "1.2.3.4")}
10
-
11
- after do
12
- if defined? @record
13
- expect(@record.delete).to be_success
14
- end
15
- end
16
-
17
- it "can create dns record" do
18
- expect(record.type).to be == "A"
19
- expect(record.name).to be_start_with subdomain
20
- expect(record.content).to be == "1.2.3.4"
21
- end
22
-
23
- context "with existing record" do
24
- it "can update dns content" do
25
- record.update_content("4.3.2.1")
26
- expect(record.content).to be == "4.3.2.1"
27
-
28
- fetched_record = zone.dns_records.find_by_name(record.name)
29
- expect(fetched_record.content).to be == record.content
30
- end
31
- end
32
- end
@@ -1,48 +0,0 @@
1
-
2
- require 'cloudflare/rspec/connection'
3
-
4
- RSpec.describe Cloudflare::Firewall, order: :defined, timeout: 30 do
5
- include_context Cloudflare::Zone
6
-
7
- let(:notes) {'gemtest'}
8
-
9
- context "with several rules" do
10
- let(:allow_ip) {'123.123.123.123'}
11
- let(:block_ip) {'123.123.123.124'}
12
-
13
- before do
14
- zone.firewall_rules.each do |rule|
15
- rule.delete
16
- end
17
-
18
- zone.firewall_rules.set('whitelist', allow_ip)
19
- zone.firewall_rules.set('block', block_ip)
20
- end
21
-
22
- it 'should get all rules' do
23
- rules = zone.firewall_rules.to_a
24
-
25
- expect(rules.size).to be >= 2
26
- end
27
-
28
- it 'should get rules with specific value' do
29
- rules = zone.firewall_rules.each_by_value(allow_ip).to_a
30
-
31
- expect(rules.size).to be == 1
32
- end
33
- end
34
-
35
- %w[block challenge whitelist].each_with_index do |mode, index|
36
- it "should create a #{mode} rule" do
37
- value = "123.123.123.#{index}"
38
- rule = zone.firewall_rules.set(mode, value, notes: notes)
39
-
40
- expect(rule.mode).to be == mode
41
- expect(rule.configuration[:value]).to be == value
42
- expect(rule.configuration[:target]).to be == 'ip'
43
- expect(rule.notes).to be == notes
44
-
45
- rule.delete
46
- end
47
- end
48
- end
@@ -1,71 +0,0 @@
1
-
2
- RSpec.describe Cloudflare::KV::Namespaces, kv_spec: true, order: :defined, timeout: 30 do
3
- include_context Cloudflare::Account
4
-
5
- let(:namespace) { @namespace = account.kv_namespaces.create(namespace_title) }
6
- let(:namespace_title) { "Test NS ##{rand(1..100)}" }
7
-
8
- after do
9
- if defined? @namespace
10
- expect(@namespace.delete).to be_success
11
- end
12
- end
13
-
14
- it 'can create a namespace' do
15
- expect(namespace).to be_kind_of Cloudflare::KV::Namespace
16
- expect(namespace.id).not_to be_nil
17
- expect(namespace.title).to eq namespace_title
18
- end
19
-
20
- it 'can find a namespace by title' do
21
- namespace # Call this so that the namespace gets created
22
- expect(account.kv_namespaces.find_by_title(namespace_title).id).to eq namespace.id
23
- end
24
-
25
- it 'can rename the namespace' do
26
- new_title = "#{namespace_title}-#{rand(1..100)}"
27
- namespace.rename(new_title)
28
- expect(namespace.title).to eq new_title
29
- expect(account.kv_namespaces.find_by_title(new_title).id).to eq namespace.id
30
- expect(account.kv_namespaces.find_by_title(namespace_title)).to be_nil
31
- end
32
-
33
- it 'can store a key/value, read it back' do
34
- key = "key-#{rand(1..100)}"
35
- value = rand(100..999)
36
- namespace.write_value(key, value)
37
- expect(account.kv_namespaces.find_by_id(namespace.id).read_value(key)).to eq value.to_s
38
- end
39
-
40
- it 'can read a previously stored key' do
41
- key = "key-#{rand(1..100)}"
42
- value = rand(100..999)
43
- expect(account.kv_namespaces.find_by_id(namespace.id).write_value(key, value)).to be true
44
- expect(namespace.read_value(key)).to eq value.to_s
45
- end
46
-
47
- it 'can delete keys' do
48
- key = "key-#{rand(1..100)}"
49
- value = rand(100..999)
50
- expect(namespace.write_value(key, value)).to be true
51
- expect(namespace.read_value(key)).to eq value.to_s
52
- expect(namespace.delete_value(key)).to be true
53
- expect do
54
- account.kv_namespaces.find_by_id(namespace.id).read_value(key)
55
- end.to raise_error(Cloudflare::RequestError)
56
- end
57
-
58
- it 'can get the keys that exist in the namespace' do
59
- counter = 0
60
- keys = Array.new(rand(1..9)) { "key-#{counter += 1}" } # Keep this single digits so ordering works
61
- keys.each_with_index do |key, i|
62
- namespace.write_value(key, i)
63
- end
64
-
65
- saved_keys = account.kv_namespaces.find_by_id(namespace.id).keys.to_a
66
- expect(saved_keys.length).to eq keys.length
67
- saved_keys.each_with_index do |key, i|
68
- expect(key.name).to eq keys[i]
69
- end
70
- end
71
- end
@@ -1,27 +0,0 @@
1
-
2
- RSpec.describe Cloudflare::Zones, order: :defined, timeout: 30 do
3
- include_context Cloudflare::Zone
4
-
5
- if ENV['CLOUDFLARE_TEST_ZONE_MANAGEMENT'] == 'true'
6
- it "can delete existing domain if exists" do
7
- if zone = zones.find_by_name(name)
8
- expect(zone.delete).to be_success
9
- end
10
- end
11
-
12
- it "can create a zone" do
13
- zone = zones.create(name, account)
14
- expect(zone.value).to include(:id)
15
- end
16
- end
17
-
18
- it "can list zones" do
19
- matching_zones = zones.select{|zone| zone.name == name}
20
- expect(matching_zones).to_not be_empty
21
- end
22
-
23
- it "can get zone by name" do
24
- found_zone = zones.find_by_name(name)
25
- expect(found_zone.name).to be == name
26
- end
27
- end
data/spec/spec_helper.rb DELETED
@@ -1,85 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- AUTH_EMAIL = ENV['CLOUDFLARE_EMAIL']
4
- AUTH_KEY = ENV['CLOUDFLARE_KEY']
5
-
6
- if AUTH_EMAIL.nil? || AUTH_EMAIL.empty? || AUTH_KEY.nil? || AUTH_KEY.empty?
7
- puts 'Please make sure you have defined CLOUDFLARE_EMAIL and CLOUDFLARE_KEY in your environment'
8
- puts 'You can also specify CLOUDFLARE_ZONE_NAME to test with your own zone and'
9
- puts 'CLOUDFLARE_ACCOUNT_ID to use a specific account'
10
- exit(1)
11
- end
12
-
13
- ACCOUNT_ID = ENV['CLOUDFLARE_ACCOUNT_ID']
14
- NAMES = ['testing', 'horse', 'cat', 'dog', 'fish', 'dolphin', 'lion', 'tiger'].freeze
15
- JOB_ID = ENV.fetch('TRAVIS_JOB_ID', 0).to_i
16
- ZONE_NAME = ENV['CLOUDFLARE_ZONE_NAME'] || "#{NAMES[JOB_ID % NAMES.size]}.com"
17
-
18
- require 'covered/rspec'
19
- require 'async/rspec'
20
-
21
- require 'cloudflare/rspec/connection'
22
- require 'cloudflare/zones'
23
-
24
- RSpec.shared_context Cloudflare::Account do
25
- include_context Cloudflare::RSpec::Connection
26
-
27
- let(:account) do
28
- if ACCOUNT_ID
29
- connection.accounts.find_by_id(ACCOUNT_ID)
30
- else
31
- connection.accounts.first
32
- end
33
- end
34
-
35
- end
36
-
37
- RSpec.shared_context Cloudflare::Zone do
38
- include_context Cloudflare::Account
39
-
40
- let(:job_id) { JOB_ID }
41
- let(:names) { NAMES.dup }
42
- let(:name) { ZONE_NAME.dup }
43
-
44
- let(:zones) {connection.zones}
45
-
46
- let(:zone) {@zone = zones.find_by_name(name) || zones.create(name, account)}
47
-
48
- # after do
49
- # if defined? @zone
50
- # @zone.delete
51
- # end
52
- # end
53
- end
54
-
55
- RSpec.configure do |config|
56
- # Enable flags like --only-failures and --next-failure
57
- config.example_status_persistence_file_path = '.rspec_status'
58
-
59
- config.expect_with :rspec do |c|
60
- c.syntax = :expect
61
- end
62
-
63
- disabled_specs = {}
64
-
65
- # Check for features the current account has enabled
66
- Cloudflare.connect(key: AUTH_KEY, email: AUTH_EMAIL) do |conn|
67
- begin
68
- account = if ACCOUNT_ID
69
- conn.accounts.find_by_id(ACCOUNT_ID)
70
- else
71
- conn.accounts.first
72
- end
73
- account.kv_namespaces.to_a
74
- rescue Cloudflare::RequestError => e
75
- if e.message.include?('your account is not permitted')
76
- puts 'Disabling KV specs due to no access'
77
- disabled_specs[:kv_spec] = true
78
- else
79
- raise
80
- end
81
- end
82
- end
83
-
84
- config.filter_run_excluding disabled_specs unless disabled_specs.empty?
85
- end