cloudflare 4.1.0 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f5bd083595954567afddacb3dccb6ad1dbe614d3d654d6ec5edfb7967d99e19
4
- data.tar.gz: f1ac3f29decb6108455805f5a24d68cda0ab7a142cd781b0df991ed11014835f
3
+ metadata.gz: 9dcc42587b1325b8ec2935b4b2bc93024dbf217928050c0ff84ce7623f805722
4
+ data.tar.gz: e2c287268b345cd3f2e9edbd116180117b5ea7ea7d7156e7b53ac4f6c5f95e09
5
5
  SHA512:
6
- metadata.gz: 6113d2ffeb66def38c41b35ed739a24f2d8b568596e0fc5623e55c8b49dd17954235e37c0288ccef0aaf0a370c54c8bec5a4321cb5b2bfdc5f461a438184300d
7
- data.tar.gz: bc5c727f94c5078d0a506d9cf6006b7d46582802d24a3089dbc3a8000be48e28a14d072f7a7a6125f835a14d567cd51f1424f2142dea44e992dafcfaff7d0d29
6
+ metadata.gz: 9a82ec080141604eafce382d2bf3f7986974e4c80ba108c0aa900ffafbb79b90b32e604ae497baa842e667878e3bbcfbf452848f24d448ff1935eecdfccb59bc
7
+ data.tar.gz: e6137b9c6dbaf3dd81265a2e5b07c7e40b392a08abf49318ae4f3822c8edb14c71e1e7fa7650e24cd9b91009b27e9ded0fe53f4be235d26e4a57e5c64415cc84
@@ -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
@@ -32,7 +32,7 @@ module Cloudflare
32
32
  end
33
33
 
34
34
  def keys
35
- Keys.new(@resource.with(path: 'keys'))
35
+ self.with(Keys, path: 'keys')
36
36
  end
37
37
 
38
38
  def read_value(name)
@@ -55,7 +55,7 @@ module Cloudflare
55
55
  private
56
56
 
57
57
  def value_representation(name)
58
- Representation.new(@resource.with(path: "values/#{name}"))
58
+ self.with(Representation, path: "values/#{name}")
59
59
  end
60
60
  end
61
61
 
@@ -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.0'
25
+ VERSION = '4.2.1'
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,30 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflare
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.1
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-04-03 00:00:00.000000000 Z
12
+ date: 2020-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: async-rest
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: 0.10.0
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'
27
+ version: 0.10.0
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
@@ -126,20 +103,11 @@ files:
126
103
  - lib/cloudflare/user.rb
127
104
  - lib/cloudflare/version.rb
128
105
  - 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
106
+ homepage: https://github.com/socketry/cloudflare
139
107
  licenses:
140
108
  - MIT
141
109
  metadata: {}
142
- post_install_message:
110
+ post_install_message:
143
111
  rdoc_options: []
144
112
  require_paths:
145
113
  - lib
@@ -147,24 +115,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
115
  requirements:
148
116
  - - ">="
149
117
  - !ruby/object:Gem::Version
150
- version: 2.0.0
118
+ version: '2.5'
151
119
  required_rubygems_version: !ruby/object:Gem::Requirement
152
120
  requirements:
153
121
  - - ">="
154
122
  - !ruby/object:Gem::Version
155
123
  version: '0'
156
124
  requirements: []
157
- rubygems_version: 3.0.3
158
- signing_key:
125
+ rubygems_version: 3.1.2
126
+ signing_key:
159
127
  specification_version: 4
160
128
  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
129
+ test_files: []
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- t/
2
- Gemfile*
3
- *.gem
4
- tags
5
- .byebug_history
6
- .rspec_status
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --format documentation
2
- --backtrace
3
- --warnings
4
- --require spec_helper
@@ -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/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
@@ -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'
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
@@ -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