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 +4 -4
- data/README.md +6 -2
- data/lib/glare.rb +14 -6
- data/lib/glare/client.rb +14 -3
- data/lib/glare/version.rb +1 -1
- data/spec/units/glare_spec.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c9e2e4e31435dfca712365a0fcd6a23719ffcb95ce32c7b9a6c828dbc5bb8fd
|
4
|
+
data.tar.gz: 1ae706b32bc0cd374c20ccb4bf00eab6744e6ba2e3951079f3303ca583977c35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
[](https://travis-ci.org/peertransfer/glare)
|
8
8
|
[](https://coveralls.io/github/peertransfer/glare?branch=master)
|
9
9
|
[](https://codeclimate.com/github/peertransfer/glare)
|
10
|
-
[](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
|
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
|
45
|
+
def client_with_api_key
|
49
46
|
credentials = default_credentials
|
50
|
-
|
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
|
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
|
-
|
14
|
-
|
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
data/spec/units/glare_spec.rb
CHANGED
@@ -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(
|
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.
|
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-
|
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.
|
155
|
+
rubygems_version: 3.0.1
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: API client for CloudFlare v4 API
|