cloudflare 4.1.3 → 4.2.0

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: 626ea2f798763660de19bc89189844304761b3db0c7db35f7bf8db5910844df6
4
- data.tar.gz: 206a3f3f19a7b0db41371f63a151b3e626fd2686f02b9f4bd7118d612bc48c06
3
+ metadata.gz: 9da58bc3e8cf7394296aafbe26d50731d145f1587df2ecd940057c01de31585c
4
+ data.tar.gz: 0b8523d30369c61c1fa5aaf1d749daa9a05c03f36c1a9aa898bb5782e662fa6c
5
5
  SHA512:
6
- metadata.gz: 67914afda228ba0a5a1d3ce5e51ef38e7c7ccf38a69015d8b82408f620f48a32874ba008f5172915300826c2c461c115d029bf8ac8862547c486952d623f918e
7
- data.tar.gz: 8ec079ac0dd5de6bfa9d74db9a0ff987579bb37b2a93b52ef2ba3265dfa543b1898c1b898045065ab561645082f360f6d5471d38f81707d51f8c465f5cde3370
6
+ metadata.gz: 8079f41055721191fd999e1b4e948d0061bf5e710503940c07d4125a315c812cda8e5603cc891e50671f5992dbc75ab1e65d6a297c9f6656db0317e85784cc35
7
+ data.tar.gz: 9f6ac470ada76aea32143026ac1b7923b76b0b50775a362759817dd7fc3118b792d6ad36f4dcd2829e3b3faba097f3c1072e01db3d1a9d21ab5c653285421683
@@ -21,6 +21,9 @@ matrix:
21
21
  - rvm: 2.6
22
22
  env: CLOUDFLARE_PROXY=http://localhost:3128
23
23
  before_script: sudo service squid start
24
+ - rvm: jruby-head
25
+ env: JRUBY_OPTS="--debug -X+O" CLOUDFLARE_PROXY=http://localhost:3128
26
+ before_script: sudo service squid start
24
27
  allow_failures:
25
28
  - rvm: ruby-head
26
29
  - rvm: jruby-head
data/README.md CHANGED
@@ -63,6 +63,20 @@ Cloudflare.connect(key: key, email: email) do |connection|
63
63
  end
64
64
  ```
65
65
 
66
+ ### Using a Bearer Token
67
+
68
+ You can read more about [bearer tokens here](https://blog.cloudflare.com/api-tokens-general-availability/). This allows you to limit priviledges.
69
+
70
+ ```ruby
71
+ require 'cloudflare'
72
+
73
+ token = 'a_generated_api_token'
74
+
75
+ Cloudflare.connect(token: token) do |connection|
76
+ # ...
77
+ end
78
+ ```
79
+
66
80
  ## Contributing
67
81
 
68
82
  1. Fork it
@@ -101,6 +115,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
101
115
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
102
116
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
103
117
  THE SOFTWARE.
104
-
105
-
106
-
@@ -27,11 +27,11 @@ require_relative 'cloudflare/connection'
27
27
  module Cloudflare
28
28
  DEFAULT_ENDPOINT = Async::HTTP::Endpoint.parse('https://api.cloudflare.com/client/v4')
29
29
 
30
- def self.connect(endpoint = DEFAULT_ENDPOINT, key: nil, email: nil)
30
+ def self.connect(endpoint = DEFAULT_ENDPOINT, **auth_info)
31
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?
@@ -28,14 +28,18 @@ 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
45
  self.with(headers: headers)
@@ -39,7 +39,7 @@ module Cloudflare
39
39
  type: @record[:type],
40
40
  name: @record[:name],
41
41
  content: content,
42
- **options
42
+ **options
43
43
  )
44
44
 
45
45
  @value = response.result
@@ -22,5 +22,5 @@
22
22
  # THE SOFTWARE.
23
23
 
24
24
  module Cloudflare
25
- VERSION = '4.1.3'
25
+ VERSION = '4.2.0'
26
26
  end
@@ -25,7 +25,7 @@ RSpec.xdescribe Cloudflare::CustomHostnames, order: :defined, timeout: 30 do
25
25
  end
26
26
 
27
27
  it 'can create a custom hostname record' do
28
- expect(record).to be_kind_of Cloudflare::CustomHostname
28
+ expect(record).to be_kind_of Cloudflare::CustomHostname
29
29
  expect(record.custom_metadata).to be_nil
30
30
  expect(record.hostname).to eq domain
31
31
  expect(record.custom_origin).to be_nil
@@ -19,7 +19,7 @@ RSpec.describe Cloudflare::DNS, order: :defined, timeout: 30 do
19
19
  expect(@record.name).to be_start_with subdomain
20
20
  expect(@record.content).to be == "1.2.3.4"
21
21
  end
22
-
22
+
23
23
  it "can create dns record with proxied option" do
24
24
  @record = zone.dns_records.create("A", subdomain, "1.2.3.4", proxied: true)
25
25
  expect(@record.type).to be == "A"
@@ -38,7 +38,7 @@ RSpec.describe Cloudflare::DNS, order: :defined, timeout: 30 do
38
38
  fetched_record = zone.dns_records.find_by_name(record.name)
39
39
  expect(fetched_record.content).to be == record.content
40
40
  end
41
-
41
+
42
42
  it "can update dns content with proxied option" do
43
43
  record.update_content("4.3.2.1", proxied: true)
44
44
  expect(record.proxied).to be_truthy
@@ -12,7 +12,7 @@ RSpec.describe Cloudflare::KV::Namespaces, kv_spec: true, order: :defined, timeo
12
12
  end
13
13
 
14
14
  it 'can create a namespace' do
15
- expect(namespace).to be_kind_of Cloudflare::KV::Namespace
15
+ expect(namespace).to be_kind_of Cloudflare::KV::Namespace
16
16
  expect(namespace.id).not_to be_nil
17
17
  expect(namespace.title).to eq namespace_title
18
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflare
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.3
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Prokop
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-08-14 00:00:00.000000000 Z
12
+ date: 2019-11-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: async-rest
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  requirements: []
157
- rubygems_version: 3.0.3
157
+ rubygems_version: 3.0.6
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: A Ruby wrapper for the Cloudflare API.