glare 0.9.0 → 1.0.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: 9c9e2e4e31435dfca712365a0fcd6a23719ffcb95ce32c7b9a6c828dbc5bb8fd
4
- data.tar.gz: 1ae706b32bc0cd374c20ccb4bf00eab6744e6ba2e3951079f3303ca583977c35
3
+ metadata.gz: 2600364f5b04c36ab6d05324f6876f4a36ea654c0dd85a6f77be1c21a65f141e
4
+ data.tar.gz: 5aa32304bb23e6cca6ab6c25343d346b7a3800cb02a14ba39db48c4d16765dc3
5
5
  SHA512:
6
- metadata.gz: 34fcb6cbb9193e558e989d99f6d887da5159b7fef3e2910fa00f14459ea009a91073df7f3673a20caeaa668290b797bc9ab5ab13bd54d6b84fd17a88e80e8c28
7
- data.tar.gz: 6201d4bcbfe6c8c22c71e7b78333e53f52900a76cb80f6295e6de4f471e2c4c8da68b53adaa789e0ee35206e83720d371adf09509dd190a4eda68e50f61b9ef2
6
+ metadata.gz: 4c75b4376b091ddbfd72eb3d43284be26c6d1ec4a999f06d138b40c0a686211f6a6e4efb97047a90851d211442dc14f93a01ce0431d2ab1c1d2c8b90b2aefa10
7
+ data.tar.gz: 0351277a39c10948b2b52210f7a221509d286c07b5c4176acf6be29e2249f9f439efbacd1a2e3a44b1663890b627448bc9f675b3a1dc1355f2ac1e19b06ab25e
data/README.md CHANGED
@@ -46,6 +46,8 @@ Additionally, you can set other environment variables:
46
46
  require 'glare'
47
47
 
48
48
  Glare.register('example.domain.com', 'destination.com' ,'CNAME')
49
+ Glare.register('example.domain.com', 'destination.com' ,'CNAME', proxied: true)
50
+ Glare.register('example.domain.com', 'destination.com' ,'CNAME', ttl: 300)
49
51
  ```
50
52
 
51
53
  Where:
data/lib/glare.rb CHANGED
@@ -10,9 +10,9 @@ require 'glare/errors'
10
10
 
11
11
  module Glare
12
12
  class << self
13
- def register(fqdn, destination, type, proxied = false)
13
+ def register(fqdn, destination, type, proxied: false, ttl: 1)
14
14
  client = build_client
15
- Domain.new(client).register(fqdn, destination, type, proxied)
15
+ Domain.new(client).register(fqdn, destination, type, proxied: proxied, ttl: ttl)
16
16
  end
17
17
 
18
18
  def resolve(fqdn, type)
@@ -30,6 +30,11 @@ module Glare
30
30
  Domain.new(client).proxied?(fqdn, type)
31
31
  end
32
32
 
33
+ def records(fqdn, type)
34
+ client = build_client
35
+ Domain.new(client).records(fqdn, type)
36
+ end
37
+
33
38
  private
34
39
 
35
40
  CF_EMAIL = 'CF_EMAIL'.freeze
@@ -1,18 +1,20 @@
1
1
  module Glare
2
2
  class CfDnsRecord
3
- def initialize(id:, name:, type:, content:, proxied: false)
3
+ def initialize(id:, name:, type:, content:, proxied: false, ttl:)
4
4
  @id = id
5
5
  @name = name
6
6
  @type = type
7
7
  @content = content
8
8
  @proxied = proxied
9
+ @ttl = ttl
9
10
  end
10
11
 
11
12
  def ==(cf_dns_record)
12
13
  @type == cf_dns_record.type &&
13
14
  @name == cf_dns_record.name &&
14
15
  @content == cf_dns_record.content &&
15
- @proxied == cf_dns_record.proxied
16
+ @proxied == cf_dns_record.proxied &&
17
+ @ttl == cf_dns_record.ttl
16
18
  end
17
19
 
18
20
  def to_h
@@ -20,11 +22,12 @@ module Glare
20
22
  type: @type,
21
23
  name: @name,
22
24
  content: @content,
23
- proxied: @proxied
25
+ proxied: @proxied,
26
+ ttl: @ttl
24
27
  }
25
28
  end
26
29
 
27
30
  attr_reader :id, :name, :type
28
- attr_accessor :content, :proxied
31
+ attr_accessor :content, :proxied, :ttl
29
32
  end
30
33
  end
@@ -13,7 +13,8 @@ module Glare
13
13
  name: item['name'],
14
14
  type: item['type'],
15
15
  content: item['content'],
16
- proxied: item['proxied']
16
+ proxied: item['proxied'],
17
+ ttl: item['ttl']
17
18
  )
18
19
  end
19
20
 
@@ -45,6 +46,10 @@ module Glare
45
46
  @records.all? { |r| r.proxied == true }
46
47
  end
47
48
 
49
+ def all?
50
+ @records.all? { |record| yield(record) }
51
+ end
52
+
48
53
  def each
49
54
  @records.each { |record| yield(record) }
50
55
  end
@@ -80,6 +80,7 @@ module Glare
80
80
  final_record = record.dup
81
81
  final_record.content = new_record.content
82
82
  final_record.proxied = new_record.proxied
83
+ final_record.ttl = new_record.ttl
83
84
  operations << Operation.new(final_record, :update)
84
85
  true
85
86
  else
@@ -1,10 +1,11 @@
1
1
  module Glare
2
2
  class DnsRecord
3
- def initialize(name:, type:, content:, proxied: false)
3
+ def initialize(name:, type:, content:, proxied:, ttl: )
4
4
  @name = name
5
5
  @type = type
6
6
  @content = content
7
7
  @proxied = proxied
8
+ @ttl = ttl
8
9
  end
9
10
 
10
11
  def to_h
@@ -12,7 +13,8 @@ module Glare
12
13
  type: @type,
13
14
  name: @name,
14
15
  content: @content,
15
- proxied: @proxied
16
+ proxied: @proxied,
17
+ ttl: @ttl
16
18
  }
17
19
  end
18
20
 
@@ -20,9 +22,10 @@ module Glare
20
22
  @type == dns_record.type &&
21
23
  @name == dns_record.name &&
22
24
  @content == dns_record.content &&
23
- @proxied == dns_record.proxied
25
+ @proxied == dns_record.proxied &&
26
+ @ttl == dns_record.ttl
24
27
  end
25
28
 
26
- attr_reader :content, :type, :name, :proxied
29
+ attr_reader :content, :type, :name, :proxied, :ttl
27
30
  end
28
31
  end
data/lib/glare/domain.rb CHANGED
@@ -7,9 +7,9 @@ module Glare
7
7
  @client = client
8
8
  end
9
9
 
10
- def register(fqdn, destinations, type, proxied=false)
10
+ def register(fqdn, destinations, type, proxied:, ttl:)
11
11
  dns_records = Array(destinations).map do |destination|
12
- DnsRecord.new(type: type, name: fqdn, content: destination, proxied: proxied)
12
+ DnsRecord.new(type: type, name: fqdn, content: destination, proxied: proxied, ttl: ttl)
13
13
  end
14
14
 
15
15
  zone = Zone.new(@client, fqdn)
@@ -33,5 +33,10 @@ module Glare
33
33
  records = zone.records(type)
34
34
  records.all_proxied?
35
35
  end
36
+
37
+ def records(fqdn, type)
38
+ zone = Zone.new(@client, fqdn)
39
+ zone.records(type)
40
+ end
36
41
  end
37
42
  end
data/lib/glare/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Glare
2
- VERSION = '0.9.0'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
data/spec/proxied_spec.rb CHANGED
@@ -18,7 +18,7 @@ RSpec.describe 'retrieves proxied values', integration: true do
18
18
  end
19
19
 
20
20
  def register_domain(domain, destination)
21
- Glare.register(domain, destination, type, true)
21
+ Glare.register(domain, destination, type, proxied: true)
22
22
  end
23
23
 
24
24
  def proxied?(domain)
data/spec/ttl_spec.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'glare'
2
+
3
+ RSpec.describe 'retrieves proxied values', integration: true do
4
+ context 'when a domain contains more than one destination' do
5
+ let(:domain) { 'a.flywire.com.cn' }
6
+ let(:type) { 'A' }
7
+ before do
8
+ register_domain(domain, destination)
9
+ end
10
+
11
+ context 'two new records' do
12
+ let(:destination) { ['1.2.3.4', '5.6.7.8'] }
13
+
14
+ it 'sets custom ttl' do
15
+ records_with_correct_ttl = records(domain).all? { |r| r.ttl == 300 }
16
+ expect(records_with_correct_ttl).to eq(true)
17
+ end
18
+ end
19
+ end
20
+
21
+ def register_domain(domain, destination)
22
+ Glare.register(domain, destination, type, ttl: 300)
23
+ end
24
+
25
+ def records(domain)
26
+ Glare.records(domain, type)
27
+ end
28
+ end
@@ -2,11 +2,21 @@ require 'glare'
2
2
 
3
3
  RSpec.describe Glare do
4
4
  before do
5
- allow(ENV).to receive(:fetch).with('CF_EMAIL').and_return('an_email')
6
- allow(ENV).to receive(:fetch).with('CF_AUTH_KEY').and_return('an_auth_key')
7
-
8
5
  allow(Glare::Client).to receive(:new).and_return(client)
9
6
  end
7
+
8
+ around do |example|
9
+ previous_cf_email = ENV['CF_EMAIL']
10
+ previous_cf_auth_key = ENV['CF_AUTH_KEY']
11
+ ENV['CF_EMAIL'] = 'an_email'
12
+ ENV['CF_AUTH_KEY'] = 'an_auth_key'
13
+
14
+ example.run
15
+
16
+ ENV['CF_EMAIL'] = previous_cf_email
17
+ ENV['CF_AUTH_KEY'] = previous_cf_auth_key
18
+ end
19
+
10
20
  let(:client) { spy(Glare::Client) }
11
21
  let(:zone_list) { Glare::ApiResponse.new(load_fixture('list_zone')) }
12
22
  let(:empty_result) { Glare::ApiResponse.new(load_fixture('empty_result')) }
@@ -92,7 +102,7 @@ RSpec.describe Glare do
92
102
 
93
103
  expect(client).to have_received(:post).with(
94
104
  '/zones/9de4eb694c380d79845d35cd939cc7a7/dns_records',
95
- type: 'CNAME', name: 'not-exist.example.com', content: 'a_destination', proxied: false
105
+ type: 'CNAME', name: 'not-exist.example.com', content: 'a_destination', proxied: false, ttl: 1
96
106
  )
97
107
  end
98
108
 
@@ -102,19 +112,19 @@ RSpec.describe Glare do
102
112
  name: 'not-exist.example.com', type: 'CNAME'
103
113
  ).and_return(empty_result)
104
114
 
105
- Glare.register('not-exist.example.com', ['a_destination', 'another_destination'].shuffle, 'CNAME', true)
115
+ Glare.register('not-exist.example.com', ['a_destination', 'another_destination'].shuffle, 'CNAME', proxied: true, ttl: 1)
106
116
 
107
117
  expect(client).not_to have_received(:put).
108
118
  with('/zones/9de4eb694c380d79845d35cd939cc7a7/dns_records', any_args)
109
119
 
110
120
  expect(client).to have_received(:post).with(
111
121
  '/zones/9de4eb694c380d79845d35cd939cc7a7/dns_records',
112
- type: 'CNAME', name: 'not-exist.example.com', content: 'a_destination', proxied: true
122
+ type: 'CNAME', name: 'not-exist.example.com', content: 'a_destination', proxied: true, ttl: 1
113
123
  )
114
124
 
115
125
  expect(client).to have_received(:post).with(
116
126
  '/zones/9de4eb694c380d79845d35cd939cc7a7/dns_records',
117
- type: 'CNAME', name: 'not-exist.example.com', content: 'another_destination', proxied: true
127
+ type: 'CNAME', name: 'not-exist.example.com', content: 'another_destination', proxied: true, ttl: 1
118
128
  )
119
129
  end
120
130
 
@@ -155,7 +165,7 @@ RSpec.describe Glare do
155
165
 
156
166
  expect(client).to have_received(:put).with(
157
167
  '/zones/9de4eb694c380d79845d35cd939cc7a7/dns_records/a1f984afe5544840505494298f54c33e',
158
- type: 'CNAME', name: 'wadus.example.com', content: 'a_destination.com', proxied: false
168
+ type: 'CNAME', name: 'wadus.example.com', content: 'a_destination.com', proxied: false, ttl: 1
159
169
  )
160
170
 
161
171
  expect(client).not_to have_received(:put).with(
@@ -168,19 +178,39 @@ RSpec.describe Glare do
168
178
  context 'all records proxied attributes are different' do
169
179
  it 'sends registration data to update endpoint' do
170
180
  destinations = ['destination.com', 'another_destination.com'].shuffle
171
- Glare.register('wadus.example.com', destinations, 'CNAME', true)
181
+ Glare.register('wadus.example.com', destinations, 'CNAME', proxied: true)
182
+
183
+ expect(client).not_to have_received(:post).
184
+ with('/zones/9de4eb694c380d79845d35cd939cc7a7/dns_records', any_args)
185
+
186
+ expect(client).to have_received(:put).with(
187
+ any_args,
188
+ type: 'CNAME', name: 'wadus.example.com', content: 'destination.com', proxied: true, ttl: 1
189
+ )
190
+
191
+ expect(client).to have_received(:put).with(
192
+ any_args,
193
+ type: 'CNAME', name: 'wadus.example.com', content: 'another_destination.com', proxied: true, ttl: 1
194
+ )
195
+ end
196
+ end
197
+
198
+ context 'all records ttl attributes are different' do
199
+ it 'sends registration data to update endpoint' do
200
+ destinations = ['destination.com', 'another_destination.com'].shuffle
201
+ Glare.register('wadus.example.com', destinations, 'CNAME', proxied: false, ttl: 300)
172
202
 
173
203
  expect(client).not_to have_received(:post).
174
204
  with('/zones/9de4eb694c380d79845d35cd939cc7a7/dns_records', any_args)
175
205
 
176
206
  expect(client).to have_received(:put).with(
177
207
  any_args,
178
- type: 'CNAME', name: 'wadus.example.com', content: 'destination.com', proxied: true
208
+ type: 'CNAME', name: 'wadus.example.com', content: 'destination.com', proxied: false, ttl: 300
179
209
  )
180
210
 
181
211
  expect(client).to have_received(:put).with(
182
212
  any_args,
183
- type: 'CNAME', name: 'wadus.example.com', content: 'another_destination.com', proxied: true
213
+ type: 'CNAME', name: 'wadus.example.com', content: 'another_destination.com', proxied: false, ttl: 300
184
214
  )
185
215
  end
186
216
  end
@@ -194,7 +224,7 @@ RSpec.describe Glare do
194
224
 
195
225
  expect(client).to have_received(:put).with(
196
226
  any_args,
197
- type: 'CNAME', name: 'wadus.example.com', content: 'a_destination.com', proxied: false
227
+ type: 'CNAME', name: 'wadus.example.com', content: 'a_destination.com', proxied: false, ttl: 1
198
228
  )
199
229
 
200
230
  expect(client).to have_received(:delete).once
@@ -216,7 +246,7 @@ RSpec.describe Glare do
216
246
 
217
247
  expect(client).to have_received(:post).with(
218
248
  '/zones/9de4eb694c380d79845d35cd939cc7a7/dns_records',
219
- type: 'CNAME', name: 'wadus.example.com', content: 'a_third_destination.com', proxied: false
249
+ type: 'CNAME', name: 'wadus.example.com', content: 'a_third_destination.com', proxied: false, ttl: 1
220
250
  )
221
251
  end
222
252
  end
@@ -103,11 +103,11 @@ RSpec.describe Glare::CfDnsRecords::Updater do
103
103
  expect(operations.count).to be_zero
104
104
  end
105
105
 
106
- def existing_record(id: 1_234, name: 'name', type: 'A', content:)
107
- Glare::CfDnsRecord.new(id: id, name: name, type: type, content: content)
106
+ def existing_record(id: 1_234, name: 'name', type: 'A', content:, ttl: 1)
107
+ Glare::CfDnsRecord.new(id: id, name: name, type: type, content: content, ttl: ttl)
108
108
  end
109
109
 
110
- def dns_record(name: 'name', type: 'A', content:, proxied: false)
111
- Glare::DnsRecord.new(name: name, type: type, content: content, proxied: proxied)
110
+ def dns_record(name: 'name', type: 'A', content:, proxied: false, ttl: 1)
111
+ Glare::DnsRecord.new(name: name, type: type, content: content, proxied: proxied, ttl: ttl)
112
112
  end
113
113
  end
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.9.0
4
+ version: 1.0.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-31 00:00:00.000000000 Z
12
+ date: 2020-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -130,6 +130,7 @@ files:
130
130
  - spec/proxied_spec.rb
131
131
  - spec/resolve_domain_spec.rb
132
132
  - spec/spec_helper.rb
133
+ - spec/ttl_spec.rb
133
134
  - spec/units/api_response_spec.rb
134
135
  - spec/units/glare_spec.rb
135
136
  - spec/units/operations_spec.rb
@@ -152,13 +153,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
153
  - !ruby/object:Gem::Version
153
154
  version: '0'
154
155
  requirements: []
155
- rubygems_version: 3.0.1
156
+ rubygems_version: 3.0.3
156
157
  signing_key:
157
158
  specification_version: 4
158
159
  summary: API client for CloudFlare v4 API
159
160
  test_files:
160
161
  - spec/delete_domain_spec.rb
161
162
  - spec/spec_helper.rb
163
+ - spec/ttl_spec.rb
162
164
  - spec/proxied_spec.rb
163
165
  - spec/resolve_domain_spec.rb
164
166
  - spec/units/glare_spec.rb