zonesync 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 799ab804db56a8f9b6882b1dd64ebdcad5f88310bb25ca6261ab997ecb9934d9
4
- data.tar.gz: 3410be337d22be94eaae226aadf34d064f9f66289306023dce0d4d26ecaa31b2
3
+ metadata.gz: de0f19d0c0fc5e8ce4abdbf8162e812bc8e9625949c569f8241f1dd3a26b1d59
4
+ data.tar.gz: ac995b1a37c31ebfcc942d1b7bdf8af61d3ea542b928181d98a5339ae3ed873f
5
5
  SHA512:
6
- metadata.gz: 06c7e0f79883aaa040aa9d98b61793495adcc48ce565f1072d14cf22c98e81aea2877d4e4917371f72d26d6b952a1f8daed443e71c51d32003464b9b850a61e2
7
- data.tar.gz: 1112ee6ef2d185e6d21cea7284035960e71d9dc6b23dc21a8768c08da4b831c1780452fbb1d93e2436ded427c4559b70643a3c7eeca3050a0ee10741090a0fa6
6
+ metadata.gz: 2ae81d95b270a1832003e80fa9b9a239fa84550baef01b2e965ea98c4d9088386cf7bda17c25dc62d91b1bb1d24fb6e743957246b38f927219844185d8eefc89
7
+ data.tar.gz: a21efe23b40750c68ab57597fca878771fdf1e5738b847d818b56fb4331af83094fb78d5d340f006815c264cd80217239c2a0be59e77295ad22c797838af3657
@@ -36,7 +36,7 @@ module Zonesync
36
36
  response = http.get(nil)
37
37
  response["result"].reduce({}) do |map, attrs|
38
38
  map.merge attrs["id"] => Record.new(
39
- attrs["name"],
39
+ attrs["name"] + ".", # normalize to trailing period
40
40
  attrs["type"],
41
41
  attrs["ttl"].to_i,
42
42
  attrs["content"],
@@ -9,25 +9,10 @@ module Zonesync
9
9
 
10
10
  def diffable_records
11
11
  DNS::Zonefile.load(read).records.map do |record|
12
- rdata = case record
13
- when DNS::Zonefile::A, DNS::Zonefile::AAAA
14
- record.address
15
- when DNS::Zonefile::CNAME
16
- record.domainname
17
- when DNS::Zonefile::MX
18
- record.domainname
19
- when DNS::Zonefile::TXT
20
- record.data
21
- else
22
- next
23
- end
24
- Record.new(
25
- record.host,
26
- record.class.name.split("::").last,
27
- record.ttl,
28
- rdata,
29
- )
30
- end.compact
12
+ Record.from_dns_zonefile_record(record)
13
+ end.select do |record|
14
+ %w[A AAAA CNAME MX TXT SPF NAPTR PTR].include?(record.type)
15
+ end.sort
31
16
  end
32
17
 
33
18
  def read record
@@ -1,5 +1,42 @@
1
1
  module Zonesync
2
2
  class Record < Struct.new(:name, :type, :ttl, :rdata)
3
+ def self.from_dns_zonefile_record record
4
+ type = record.class.name.split("::").last
5
+ rdata = case type
6
+ when "SOA"
7
+ def record.host = origin
8
+ "" # it just gets ignored anyways
9
+ when "A", "AAAA"
10
+ record.address
11
+ when "CNAME", "NS", "PTR"
12
+ record.domainname
13
+ when "MX"
14
+ "#{record.priority} #{record.domainname}"
15
+ when "TXT", "SPF", "NAPTR"
16
+ record.data
17
+ else
18
+ raise NotImplementedError.new(record.class).to_s
19
+ end
20
+
21
+ new(
22
+ record.host,
23
+ type,
24
+ record.ttl,
25
+ rdata,
26
+ )
27
+ end
28
+
29
+ def <=> other
30
+ to_sortable <=> other.to_sortable
31
+ end
32
+
33
+ def to_sortable
34
+ [type, name, rdata, ttl]
35
+ end
36
+
37
+ def to_s
38
+ values.join(" ")
39
+ end
3
40
  end
4
41
  end
5
42
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zonesync
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/zonesync.rb CHANGED
@@ -11,7 +11,10 @@ module Zonesync
11
11
  local = Provider.from({ provider: "Filesystem", path: zonefile })
12
12
  remote = Provider.from(credentials)
13
13
  operations = Diff.call(from: remote, to: local)
14
- operations.each { |method, args| puts [method, *args].inspect }
14
+ operations.each do |method, args|
15
+ puts [method, args].inspect
16
+ remote.send(method, args)
17
+ end
15
18
  end
16
19
  end
17
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zonesync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel