glare 0.8.0 → 0.9.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: 7d1935ecba14315bdda101bdc310447d5860cdfab6a808333514e02dbc99435d
4
- data.tar.gz: ef6347b733cd15987ee81023ae537b1ce61f4855c0fb1cedae885cd5139d6447
3
+ metadata.gz: 9c9e2e4e31435dfca712365a0fcd6a23719ffcb95ce32c7b9a6c828dbc5bb8fd
4
+ data.tar.gz: 1ae706b32bc0cd374c20ccb4bf00eab6744e6ba2e3951079f3303ca583977c35
5
5
  SHA512:
6
- metadata.gz: 3509e8b7cbfffd83b2f2ea57514dd966dd932f559f8942c8b34fae5ecd50fe8224663698f695b0f9dbf70f43548281ea03eeb0aa998a7ddf84eb1230632cedb8
7
- data.tar.gz: 2ec69752f53b51528953293623cbdf91c91bae62fa2df2d0d638630e0c752e1b45f85758eb09f56b2edf0a82ca63f87d603f643994c90fd0b59cf5354bebfbba
6
+ metadata.gz: 34fcb6cbb9193e558e989d99f6d887da5159b7fef3e2910fa00f14459ea009a91073df7f3673a20caeaa668290b797bc9ab5ab13bd54d6b84fd17a88e80e8c28
7
+ data.tar.gz: 6201d4bcbfe6c8c22c71e7b78333e53f52900a76cb80f6295e6de4f471e2c4c8da68b53adaa789e0ee35206e83720d371adf09509dd190a4eda68e50f61b9ef2
data/README.md CHANGED
@@ -7,7 +7,7 @@ Ruby gem to interact with CloudFlare API v4
7
7
  [![Build Status](https://travis-ci.org/peertransfer/glare.svg?branch=master)](https://travis-ci.org/peertransfer/glare)
8
8
  [![Coverage Status](https://coveralls.io/repos/github/peertransfer/glare/badge.svg?branch=master)](https://coveralls.io/github/peertransfer/glare?branch=master)
9
9
  [![Code Climate](https://codeclimate.com/github/peertransfer/glare/badges/gpa.svg)](https://codeclimate.com/github/peertransfer/glare)
10
- [![Dependency Status](https://gemnasium.com/peertransfer/glare.svg)](https://gemnasium.com/peertransfer/glare)
10
+ [![Known Vulnerabilities](https://snyk.io/test/github/peertransfer/glare/badge.svg)](https://snyk.io/test/github/peertransfer/glare)
11
11
 
12
12
  ## Installation
13
13
 
@@ -27,7 +27,11 @@ Or install it yourself as:
27
27
 
28
28
  ## Usage
29
29
 
30
- In order to configure credentials used to interact with Cloudflare API you will need to setup the following environment variables:
30
+ In order to configure credentials used to interact with Cloudflare API you will need to setup the following environment variable:
31
+
32
+ - `CF_API_TOKEN`: Scoped API [token](https://support.cloudflare.com/hc/en-us/articles/200167836-Managing-API-Tokens-and-Keys) defined in a Cloudflare account
33
+
34
+ or both of the following variables:
31
35
 
32
36
  - `CF_EMAIL`: Email used to create a Cloudflare account
33
37
  - `CF_AUTH_KEY`: Auth key of the given user
data/lib/glare.rb CHANGED
@@ -34,10 +34,7 @@ module Glare
34
34
 
35
35
  CF_EMAIL = 'CF_EMAIL'.freeze
36
36
  CF_AUTH_KEY = 'CF_AUTH_KEY'.freeze
37
-
38
- def client(credentials)
39
- Glare::Client.new(credentials.email, credentials.auth_key)
40
- end
37
+ CF_API_TOKEN = 'CF_API_TOKEN'.freeze
41
38
 
42
39
  def default_credentials
43
40
  email = ENV.fetch(CF_EMAIL)
@@ -45,9 +42,20 @@ module Glare
45
42
  Credentials.new(email, auth_key)
46
43
  end
47
44
 
48
- def build_client
45
+ def client_with_api_key
49
46
  credentials = default_credentials
50
- client(credentials)
47
+ Glare::Client.new.from_global_api_key(credentials.email, credentials.auth_key)
48
+ end
49
+
50
+ def client_with_api_token
51
+ return nil unless ENV.key?(CF_API_TOKEN)
52
+
53
+ api_token = ENV.fetch(CF_API_TOKEN)
54
+ Glare::Client.new.from_scoped_api_token(api_token)
55
+ end
56
+
57
+ def build_client
58
+ client_with_api_token || client_with_api_key
51
59
  end
52
60
  end
53
61
  end
data/lib/glare/client.rb CHANGED
@@ -5,13 +5,24 @@ module Glare
5
5
  class Client
6
6
  BASE_URL = 'https://api.cloudflare.com/client/v4'.freeze
7
7
 
8
- def initialize(email, auth_key)
8
+ def initialize
9
+ @http = JSONClient.new
10
+ @http.debug_dev = STDERR if ENV['CF_DEBUG']
11
+ end
12
+
13
+ def from_global_api_key(email, auth_key)
9
14
  @headers = {
10
15
  'X-Auth-Email' => email,
11
16
  'X-Auth-Key' => auth_key
12
17
  }
13
- @http = JSONClient.new
14
- @http.debug_dev = STDERR if ENV['CF_DEBUG']
18
+ self
19
+ end
20
+
21
+ def from_scoped_api_token(api_token)
22
+ @headers = {
23
+ 'Authorization' => "Bearer #{api_token}"
24
+ }
25
+ self
15
26
  end
16
27
 
17
28
  def get(query, params)
data/lib/glare/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Glare
2
- VERSION = '0.8.0'.freeze
2
+ VERSION = '0.9.0'.freeze
3
3
  end
@@ -48,7 +48,7 @@ RSpec.describe Glare do
48
48
  it 'uses default credentials' do
49
49
  Glare.register('example.com', 'a_destination', 'CNAME')
50
50
 
51
- expect(Glare::Client).to have_received(:new).with('an_email', 'an_auth_key')
51
+ expect(client).to have_received(:from_global_api_key).with('an_email', 'an_auth_key')
52
52
  end
53
53
 
54
54
  it 'uses the registration endpoint' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glare
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Luis Salas
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-10-28 00:00:00.000000000 Z
12
+ date: 2019-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  requirements: []
155
- rubygems_version: 3.0.3
155
+ rubygems_version: 3.0.1
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: API client for CloudFlare v4 API