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 +4 -4
- data/lib/glare.rb +7 -2
- data/lib/glare/cf_dns_records.rb +4 -0
- data/lib/glare/cf_dns_records/updater.rb +2 -1
- data/lib/glare/domain.rb +7 -1
- data/lib/glare/domain/record.rb +1 -1
- data/lib/glare/version.rb +1 -1
- data/spec/proxied_spec.rb +27 -0
- data/spec/units/glare_spec.rb +13 -12
- data/spec/units/operations_spec.rb +11 -8
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bc9315cdcc4aa4a6c2b3b293763b09829a6f3c187f2c4f060facca091005a1b
|
4
|
+
data.tar.gz: d6e79343737a20fa16545c082b52766a6cdee2196a75a53e605e72a77210c35d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e389dad3306135b05f2209cfbb73f0c3f816aee3f1a09d7b08be08aac60e11fc8e4f1602ff746f3c9ff2e5e88a3cd7b041fda683445236eaa1c5879ff848798f
|
7
|
+
data.tar.gz: e430a12761d7ec021098f6d2eac4ee421b9c994ffb3a2c86fc8adeddd10a6edac930224771560396ba237e8ae0d20c525a347348c9ae7e854b942e1cefdfe723
|
data/lib/glare.rb
CHANGED
@@ -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
|
39
|
-
auth_key = ENV
|
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
|
|
data/lib/glare/cf_dns_records.rb
CHANGED
@@ -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
|
data/lib/glare/domain.rb
CHANGED
@@ -7,7 +7,7 @@ module Glare
|
|
7
7
|
@client = client
|
8
8
|
end
|
9
9
|
|
10
|
-
def register(fqdn, destinations, type, proxied
|
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
|
data/lib/glare/domain/record.rb
CHANGED
data/lib/glare/version.rb
CHANGED
@@ -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
|
data/spec/units/glare_spec.rb
CHANGED
@@ -2,8 +2,8 @@ require 'glare'
|
|
2
2
|
|
3
3
|
RSpec.describe Glare do
|
4
4
|
before do
|
5
|
-
allow(ENV).to receive(:
|
6
|
-
allow(ENV).to receive(:
|
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:
|
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:
|
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
|
168
|
+
context 'all records proxied attributes are different' do
|
169
169
|
it 'sends registration data to update endpoint' do
|
170
|
-
|
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: '
|
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: '
|
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
|
-
|
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
|
-
|
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
|
-
|
80
|
-
|
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
|
84
|
-
expect(operations.deletions).to
|
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
|
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.
|
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-
|
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
|