glare 0.6.0 → 0.7.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: 27e49ade7bb6778f14de878da4ad2bbc90fdf192542682086c22888805d957fe
4
- data.tar.gz: d2f684300c0acb3652dccbf0956b28a49a82b016f8cbb0864c48dbc33a2fcba4
3
+ metadata.gz: 3bc9315cdcc4aa4a6c2b3b293763b09829a6f3c187f2c4f060facca091005a1b
4
+ data.tar.gz: d6e79343737a20fa16545c082b52766a6cdee2196a75a53e605e72a77210c35d
5
5
  SHA512:
6
- metadata.gz: b0b1b129746cdedf5bd3ac073345396a746e162103802231f3363bcecc39da13ab249abaccae66037bc5607f30570b5538e87760020b0b7f739654a111d75d32
7
- data.tar.gz: be5bd9e5ebf93bc27ce1e9966ec95f9fd766eae8c9620ec12f0e16f1ed1935342cccd3f49ccc3a11368e78dd49323fc692b654756bc0b69fac2c12f9d56f45d3
6
+ metadata.gz: e389dad3306135b05f2209cfbb73f0c3f816aee3f1a09d7b08be08aac60e11fc8e4f1602ff746f3c9ff2e5e88a3cd7b041fda683445236eaa1c5879ff848798f
7
+ data.tar.gz: e430a12761d7ec021098f6d2eac4ee421b9c994ffb3a2c86fc8adeddd10a6edac930224771560396ba237e8ae0d20c525a347348c9ae7e854b942e1cefdfe723
@@ -25,6 +25,11 @@ module Glare
25
25
  Domain.new(client).deregister(fqdn, type)
26
26
  end
27
27
 
28
+ def proxied?(fqdn, type)
29
+ client = build_client
30
+ Domain.new(client).proxied?(fqdn, type)
31
+ end
32
+
28
33
  private
29
34
 
30
35
  CF_EMAIL = 'CF_EMAIL'.freeze
@@ -35,8 +40,8 @@ module Glare
35
40
  end
36
41
 
37
42
  def default_credentials
38
- email = ENV[CF_EMAIL]
39
- auth_key = ENV[CF_AUTH_KEY]
43
+ email = ENV.fetch(CF_EMAIL)
44
+ auth_key = ENV.fetch(CF_AUTH_KEY)
40
45
  Credentials.new(email, auth_key)
41
46
  end
42
47
 
@@ -41,6 +41,10 @@ module Glare
41
41
  @records.map(&:content)
42
42
  end
43
43
 
44
+ def all_proxied?
45
+ @records.all? { |r| r.proxied == true }
46
+ end
47
+
44
48
  def each
45
49
  @records.each { |record| yield(record) }
46
50
  end
@@ -76,9 +76,10 @@ module Glare
76
76
  operations = []
77
77
 
78
78
  @current_records.delete_if do |record|
79
- if new_record = @new_contents.shift
79
+ if (new_record = @new_contents.shift)
80
80
  final_record = record.dup
81
81
  final_record.content = new_record.content
82
+ final_record.proxied = new_record.proxied
82
83
  operations << Operation.new(final_record, :update)
83
84
  true
84
85
  else
@@ -7,7 +7,7 @@ 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=false)
11
11
  dns_records = Array(destinations).map do |destination|
12
12
  DnsRecord.new(type: type, name: fqdn, content: destination, proxied: proxied)
13
13
  end
@@ -27,5 +27,11 @@ module Glare
27
27
  dns_records = zone.records(type)
28
28
  Record.deregister(@client, zone, dns_records)
29
29
  end
30
+
31
+ def proxied?(fqdn, type)
32
+ zone = Zone.new(@client, fqdn)
33
+ records = zone.records(type)
34
+ records.all_proxied?
35
+ end
30
36
  end
31
37
  end
@@ -2,7 +2,7 @@ module Glare
2
2
  class Domain
3
3
  class Record
4
4
  class << self
5
- def register(client, zone, dns_records, proxied = false)
5
+ def register(client, zone, dns_records)
6
6
  @client = client
7
7
  existing_records = zone.records(dns_records.first.type)
8
8
  zone_id = zone.id
@@ -1,3 +1,3 @@
1
1
  module Glare
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.7.0'.freeze
3
3
  end
@@ -0,0 +1,27 @@
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 'resolves to right destination' do
15
+ expect(proxied?(domain)).to eq(true)
16
+ end
17
+ end
18
+ end
19
+
20
+ def register_domain(domain, destination)
21
+ Glare.register(domain, destination, type, true)
22
+ end
23
+
24
+ def proxied?(domain)
25
+ Glare.proxied?(domain, type)
26
+ end
27
+ end
@@ -2,8 +2,8 @@ require 'glare'
2
2
 
3
3
  RSpec.describe Glare do
4
4
  before do
5
- allow(ENV).to receive(:[]).with('CF_EMAIL').and_return('an_email')
6
- allow(ENV).to receive(:[]).with('CF_AUTH_KEY').and_return('an_auth_key')
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
7
 
8
8
  allow(Glare::Client).to receive(:new).and_return(client)
9
9
  end
@@ -102,19 +102,19 @@ RSpec.describe Glare do
102
102
  name: 'not-exist.example.com', type: 'CNAME'
103
103
  ).and_return(empty_result)
104
104
 
105
- Glare.register('not-exist.example.com', ['a_destination', 'another_destination'].shuffle, 'CNAME')
105
+ Glare.register('not-exist.example.com', ['a_destination', 'another_destination'].shuffle, 'CNAME', true)
106
106
 
107
107
  expect(client).not_to have_received(:put).
108
108
  with('/zones/9de4eb694c380d79845d35cd939cc7a7/dns_records', any_args)
109
109
 
110
110
  expect(client).to have_received(:post).with(
111
111
  '/zones/9de4eb694c380d79845d35cd939cc7a7/dns_records',
112
- type: 'CNAME', name: 'not-exist.example.com', content: 'a_destination', proxied: false
112
+ type: 'CNAME', name: 'not-exist.example.com', content: 'a_destination', proxied: true
113
113
  )
114
114
 
115
115
  expect(client).to have_received(:post).with(
116
116
  '/zones/9de4eb694c380d79845d35cd939cc7a7/dns_records',
117
- type: 'CNAME', name: 'not-exist.example.com', content: 'another_destination', proxied: false
117
+ type: 'CNAME', name: 'not-exist.example.com', content: 'another_destination', proxied: true
118
118
  )
119
119
  end
120
120
 
@@ -165,25 +165,25 @@ RSpec.describe Glare do
165
165
  end
166
166
  end
167
167
 
168
- context 'all records contents are different' do
168
+ context 'all records proxied attributes are different' do
169
169
  it 'sends registration data to update endpoint' do
170
- Glare.register('wadus.example.com', ['a_destination.com', 'yet_another_destination.com'].shuffle, 'CNAME')
170
+ destinations = ['destination.com', 'another_destination.com'].shuffle
171
+ Glare.register('wadus.example.com', destinations, 'CNAME', true)
171
172
 
172
173
  expect(client).not_to have_received(:post).
173
174
  with('/zones/9de4eb694c380d79845d35cd939cc7a7/dns_records', any_args)
174
175
 
175
176
  expect(client).to have_received(:put).with(
176
177
  any_args,
177
- type: 'CNAME', name: 'wadus.example.com', content: 'a_destination.com', proxied: false
178
+ type: 'CNAME', name: 'wadus.example.com', content: 'destination.com', proxied: true
178
179
  )
179
180
 
180
181
  expect(client).to have_received(:put).with(
181
182
  any_args,
182
- type: 'CNAME', name: 'wadus.example.com', content: 'yet_another_destination.com', proxied: false
183
+ type: 'CNAME', name: 'wadus.example.com', content: 'another_destination.com', proxied: true
183
184
  )
184
185
  end
185
186
  end
186
-
187
187
  end
188
188
 
189
189
  it 'updates different records and deletes extra ones' do
@@ -194,14 +194,15 @@ RSpec.describe Glare do
194
194
 
195
195
  expect(client).to have_received(:put).with(
196
196
  any_args,
197
- { type: 'CNAME', name: 'wadus.example.com', content: 'a_destination.com', proxied: false }
197
+ type: 'CNAME', name: 'wadus.example.com', content: 'a_destination.com', proxied: false
198
198
  )
199
199
 
200
200
  expect(client).to have_received(:delete).once
201
201
  end
202
202
 
203
203
  it 'updates different records and creates new ones' do
204
- Glare.register('wadus.example.com', ['destination.com', 'another_destination.com', 'a_third_destination.com'].shuffle, 'CNAME')
204
+ destinations = ['destination.com', 'another_destination.com', 'a_third_destination.com'].shuffle
205
+ Glare.register('wadus.example.com', destinations, 'CNAME')
205
206
 
206
207
  expect(client).not_to have_received(:put).with(
207
208
  '/zones/9de4eb694c380d79845d35cd939cc7a7/dns_records/a1f984afe5544840505494298f54c33e',
@@ -71,20 +71,23 @@ RSpec.describe Glare::CfDnsRecords::Updater do
71
71
  current_records = Glare::CfDnsRecords.new([current_record2, current_record, current_record3])
72
72
 
73
73
  new_record = dns_record(content: '1.2.3.8')
74
- update_record = dns_record(content: '1.2.3.4')
74
+ update_record = dns_record(content: '1.2.3.4', proxied: true)
75
75
  new_records = [new_record, update_record].shuffle
76
76
 
77
77
  operations = Glare::CfDnsRecords::Updater.new(current_records, new_records).calculate
78
78
 
79
- current_record2.content = '1.2.3.8'
80
- update_operation = Glare::CfDnsRecords::Updater::Operation.new(current_record2, :update)
79
+ updated_record = current_record.dup.tap { |r| r.proxied = true }
80
+ updated_record2 = current_record2.dup.tap { |r| r.content = '1.2.3.8' }
81
+
82
+ update_operation = Glare::CfDnsRecords::Updater::Operation.new(updated_record2, :update)
83
+ update_operation2 = Glare::CfDnsRecords::Updater::Operation.new(updated_record, :update)
81
84
  delete_operation = Glare::CfDnsRecords::Updater::Operation.new(current_record3, :delete)
82
85
 
83
- expect(operations.updates).to eq([update_operation])
84
- expect(operations.deletions).to eq([delete_operation])
86
+ expect(operations.updates).to match_array([update_operation, update_operation2])
87
+ expect(operations.deletions).to match_array([delete_operation])
85
88
  end
86
89
 
87
- it 'can detects new records to delete and update' do
90
+ it 'can detect new records to delete and update' do
88
91
  current_record = existing_record(content: '1.2.3.4')
89
92
  current_record2 = existing_record(content: '1.2.3.6')
90
93
  current_record3 = existing_record(content: '1.2.3.5')
@@ -104,7 +107,7 @@ RSpec.describe Glare::CfDnsRecords::Updater do
104
107
  Glare::CfDnsRecord.new(id: id, name: name, type: type, content: content)
105
108
  end
106
109
 
107
- def dns_record(name: 'name', type: 'A', content:)
108
- Glare::DnsRecord.new(name: name, type: type, content: content)
110
+ def dns_record(name: 'name', type: 'A', content:, proxied: false)
111
+ Glare::DnsRecord.new(name: name, type: type, content: content, proxied: proxied)
109
112
  end
110
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.6.0
4
+ version: 0.7.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-08-27 00:00:00.000000000 Z
12
+ date: 2019-08-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -127,6 +127,7 @@ files:
127
127
  - spec/fixtures/list_zone.json
128
128
  - spec/fixtures/wadus_records.json
129
129
  - spec/fixtures/wadus_records_reverse_order.json
130
+ - spec/proxied_spec.rb
130
131
  - spec/resolve_domain_spec.rb
131
132
  - spec/spec_helper.rb
132
133
  - spec/units/api_response_spec.rb
@@ -162,6 +163,7 @@ test_files:
162
163
  - spec/units/glare_spec.rb
163
164
  - spec/resolve_domain_spec.rb
164
165
  - spec/spec_helper.rb
166
+ - spec/proxied_spec.rb
165
167
  - spec/delete_domain_spec.rb
166
168
  - spec/fixtures/wadus_records_reverse_order.json
167
169
  - spec/fixtures/wadus_records.json