ezdyn 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +4 -0
- data/bin/ezdyn +2 -2
- data/ezdyn.gemspec +1 -1
- data/lib/ezdyn/changes.rb +14 -10
- data/lib/ezdyn/crud.rb +33 -43
- data/lib/ezdyn/record.rb +1 -1
- data/lib/ezdyn/record_type.rb +3 -3
- data/lib/ezdyn/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4ba5f7252dbce98914e413a84e9721e5363e3c3b8dc217b95585f745ce7dd35e
|
4
|
+
data.tar.gz: adc0b38aab81daf21235845ccc0098d6ddb9e60fe372f4d12c0fc1a4386a815a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c3db8aabdd6d5801da22bf28849422d9984b5976889fedaa61a72cf39fd72bf58aa6ed5878d9505debe4166680c4da2bb727904b558ead22e8b16357c935498
|
7
|
+
data.tar.gz: 66b0831ecf710fab181c15bcbdac141962e6132227b7dca25e61e63eec1926f729869aa82b0029e4b330b9f85b711d92207192aecb7f183b8d698ae2e0265486
|
data/CHANGELOG.md
CHANGED
data/bin/ezdyn
CHANGED
@@ -139,7 +139,7 @@ commands.each do |line|
|
|
139
139
|
next if $options[:check]
|
140
140
|
|
141
141
|
say "DynAPI: Creating #{fqdn} #{ttl||"(#{EZDyn::Record::DefaultTTL})"} #{type.upcase} #{value}"
|
142
|
-
$dyn.create(type: type, fqdn: fqdn, value: value, ttl: ttl)
|
142
|
+
$dyn.create(type: type, fqdn: fqdn, value: value.split(','), ttl: ttl)
|
143
143
|
|
144
144
|
when 'update','upsert'
|
145
145
|
type, fqdn, value, ttl = tokens.shift(4)
|
@@ -153,7 +153,7 @@ commands.each do |line|
|
|
153
153
|
next if $options[:check]
|
154
154
|
|
155
155
|
say "DynAPI: Upserting #{fqdn} #{ttl||"(#{EZDyn::Record::DefaultTTL})"} #{type.upcase} #{value}"
|
156
|
-
$dyn.update(type: type, fqdn: fqdn, value: value, ttl: ttl)
|
156
|
+
$dyn.update(type: type, fqdn: fqdn, value: value.split(','), ttl: ttl)
|
157
157
|
|
158
158
|
when 'delete'
|
159
159
|
type, fqdn = tokens.shift(2)
|
data/ezdyn.gemspec
CHANGED
@@ -3,7 +3,7 @@ require_relative 'lib/ezdyn/version'
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "ezdyn"
|
5
5
|
s.version = EZDyn::VERSION
|
6
|
-
s.
|
6
|
+
s.authors = ["David Adams","Dan Dorman","Eric Coan"]
|
7
7
|
s.email = "dadams@instructure.com"
|
8
8
|
s.date = Time.now.strftime("%Y-%m-%d")
|
9
9
|
s.license = "Nonstandard"
|
data/lib/ezdyn/changes.rb
CHANGED
@@ -67,9 +67,13 @@ module EZDyn
|
|
67
67
|
# A pending record update.
|
68
68
|
class UpdateChange < Change
|
69
69
|
# @private
|
70
|
-
def initialize(
|
71
|
-
@
|
72
|
-
@
|
70
|
+
def initialize(records:, new_records:)
|
71
|
+
@records = records.map(&:sync!)
|
72
|
+
@new_records = new_records
|
73
|
+
end
|
74
|
+
|
75
|
+
def zone
|
76
|
+
@new_records.first.zone
|
73
77
|
end
|
74
78
|
|
75
79
|
# Returns a string representation of the change.
|
@@ -77,20 +81,20 @@ module EZDyn
|
|
77
81
|
# @return [String] A string representation of this change.
|
78
82
|
def to_s
|
79
83
|
ttl_string =
|
80
|
-
if @
|
81
|
-
@
|
84
|
+
if @records.map(&:ttl).min == @new_records.map(&:ttl).min
|
85
|
+
@records.map(&:ttl).min
|
82
86
|
else
|
83
|
-
"(( #{@
|
87
|
+
"(( #{@records.map(&:ttl).min} -> #{@new_records.map(&:ttl).min} ))"
|
84
88
|
end
|
85
89
|
|
86
90
|
value_string =
|
87
|
-
if @
|
88
|
-
@
|
91
|
+
if @records.map(&:value).join(',') == @new_records.map(&:value).join(',')
|
92
|
+
@records.map(&:value).join(',')
|
89
93
|
else
|
90
|
-
"(( #{@
|
94
|
+
"(( #{@records.map(&:value).join(',')} -> #{@new_records.map(&:value).join(',')} ))"
|
91
95
|
end
|
92
96
|
|
93
|
-
"UPDATE #{@
|
97
|
+
"UPDATE #{@new_records.first.fqdn}. #{ttl_string} #{@new_records.first.type} #{value_string}"
|
94
98
|
end
|
95
99
|
end
|
96
100
|
|
data/lib/ezdyn/crud.rb
CHANGED
@@ -5,35 +5,35 @@ module EZDyn
|
|
5
5
|
# @note As a side effect upon success, this method creates a [CreateChange]
|
6
6
|
# object in the `pending_changes` array.
|
7
7
|
#
|
8
|
-
# @raise [RuntimeError] if such a record already exists.
|
9
8
|
# @raise [RuntimeError] if the record could not be created.
|
10
9
|
# @param type [RecordType, String, Symbol] Type of record to create.
|
11
10
|
# @param fqdn [String] FQDN of the record to create.
|
12
|
-
# @param value [String,
|
11
|
+
# @param value [String, Array] Value(s) to submit for the record data.
|
13
12
|
# @param ttl [String, Integer] TTL value (optional).
|
14
13
|
# @return [Record] A Record object filled with the values returned by the API.
|
15
14
|
def create(type:, fqdn:, value:, ttl: nil)
|
16
15
|
EZDyn.debug { "Client.create( type: #{type}, fqdn: #{fqdn}, value: #{value}, ttl: #{ttl} )" }
|
17
|
-
if self.exists?(type: type, fqdn: fqdn)
|
18
|
-
raise "EZDyn does not yet support multiple records of the same type on a single node."
|
19
|
-
end
|
20
16
|
|
21
17
|
ttl = ( ttl || Record::DefaultTTL ).to_i
|
18
|
+
values = Array(value)
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
20
|
+
return values.map do |val|
|
21
|
+
value_key = Array(RecordType.find(type).value_key)
|
22
|
+
split_val = val.split(' ', value_key.length)
|
23
|
+
response = self.call_api(
|
24
|
+
method: "post",
|
25
|
+
uri: self.build_uri(type: type, fqdn: fqdn),
|
26
|
+
payload: { rdata: value_key.zip(split_val).to_h, ttl: ttl }
|
27
|
+
)
|
32
28
|
|
33
|
-
|
34
|
-
|
29
|
+
if not response.success?
|
30
|
+
raise "Failed to create record: #{response.simple_message}"
|
31
|
+
end
|
35
32
|
|
36
|
-
|
33
|
+
record = Record.new(client: self, raw: response.data)
|
34
|
+
self.add_pending_change(CreateChange.new(record: record))
|
35
|
+
record
|
36
|
+
end
|
37
37
|
end
|
38
38
|
|
39
39
|
# Calls the Dyn API to update or create a record. Could also be called
|
@@ -42,53 +42,43 @@ module EZDyn
|
|
42
42
|
# @note As a side effect upon success, this method creates an [UpdateChange]
|
43
43
|
# or a [CreateChange] object in the `pending_changes` array.
|
44
44
|
#
|
45
|
-
# @raise [RuntimeError] if multiple records exist and no specific Record object was passed.
|
46
45
|
# @raise [RuntimeError] if the record could not be created or updated.
|
47
46
|
# @param record [Record] A Record object for the record to be updated.
|
48
47
|
# Either this parameter or the `type` and `fqdn` parameters are
|
49
48
|
# required.
|
50
49
|
# @param type [RecordType, String, Symbol] Type of record to update/create (not required if `record` is provided).
|
51
50
|
# @param fqdn [String] FQDN of the record to update/create (not requried if `record` is provided).
|
52
|
-
# @param value [String,
|
51
|
+
# @param value [String, Array] New value(s) to submit for the record data (optional if updating TTL and record already exists).
|
53
52
|
# @param ttl [String, Integer] New TTL value (optional).
|
54
53
|
# @return [Record] A Record object filled with the values returned by the API.
|
55
54
|
def update(record: nil, type: nil, fqdn: nil, value: nil, ttl: nil)
|
56
55
|
EZDyn.debug { "Client.update( record: #{record.nil? ? nil : "Record{#{record.record_id}}"}, type: #{type}, fqdn: #{fqdn}, value: #{value}, ttl: #{ttl} )" }
|
57
56
|
|
57
|
+
values = Array(value)
|
58
|
+
|
58
59
|
if record.nil?
|
59
60
|
if type.nil? or fqdn.nil?
|
60
61
|
raise "Cannot update a record without a Record object or both record type and FQDN"
|
61
62
|
end
|
62
63
|
records = self.records_for(type: type, fqdn: fqdn)
|
63
|
-
|
64
|
-
|
65
|
-
# do nothing, and let it be created
|
66
|
-
nil
|
67
|
-
elsif records.count == 1
|
68
|
-
records.first
|
69
|
-
else
|
70
|
-
raise "EZDyn does not (yet) support updating over multiple records"
|
71
|
-
end
|
64
|
+
else
|
65
|
+
records = [record]
|
72
66
|
end
|
73
67
|
|
74
68
|
response = nil
|
75
|
-
if
|
76
|
-
|
77
|
-
return self.create(type: type, fqdn: fqdn, value: value, ttl: ttl)
|
78
|
-
else
|
79
|
-
raise "Record doesn't exist, and insufficient information to create it was given"
|
80
|
-
end
|
69
|
+
if records.count.zero? && (fqdn.nil? || type.nil? || value.nil?)
|
70
|
+
raise "Record doesn't exist, and insufficient information to create it was given"
|
81
71
|
end
|
82
72
|
|
83
|
-
record.sync!
|
84
73
|
response = self.call_api(
|
85
74
|
method: "put",
|
86
|
-
uri:
|
75
|
+
uri: self.build_uri(type: type, fqdn: fqdn),
|
87
76
|
payload: {
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
77
|
+
"#{type}Records" => values.map do |val|
|
78
|
+
value_key = Array(RecordType.find(type).value_key)
|
79
|
+
split_val = val.split(' ', value_key.length)
|
80
|
+
{ rdata: value_key.zip(split_val).to_h, ttl: ttl || records.map(&:ttl).min }
|
81
|
+
end
|
92
82
|
}
|
93
83
|
)
|
94
84
|
|
@@ -96,10 +86,10 @@ module EZDyn
|
|
96
86
|
raise "Could not update: #{response.simple_message}"
|
97
87
|
end
|
98
88
|
|
99
|
-
|
100
|
-
self.add_pending_change(UpdateChange.new(
|
89
|
+
new_records = response.data.map { |res| Record.new(client: self, raw: res) }
|
90
|
+
self.add_pending_change(UpdateChange.new(records: records, new_records: new_records))
|
101
91
|
|
102
|
-
return
|
92
|
+
return new_records
|
103
93
|
end
|
104
94
|
|
105
95
|
# Delete a record.
|
data/lib/ezdyn/record.rb
CHANGED
@@ -129,7 +129,7 @@ module EZDyn
|
|
129
129
|
@fqdn = raw["fqdn"]
|
130
130
|
@type = RecordType.find(raw["record_type"])
|
131
131
|
@record_id = raw["record_id"].to_s
|
132
|
-
@value = raw["rdata"][
|
132
|
+
@value = Array(@type.value_key).map { |k| raw["rdata"][k] }.join(' ')
|
133
133
|
@in_sync = true
|
134
134
|
@exists = true
|
135
135
|
end
|
data/lib/ezdyn/record_type.rb
CHANGED
@@ -73,9 +73,9 @@ module EZDyn
|
|
73
73
|
{ name: :cname, uri_name: "CNAMERecord", value_key: "cname" },
|
74
74
|
{ name: :aaaa, uri_name: "AAAARecord", value_key: "address" },
|
75
75
|
{ name: :soa, uri_name: "SOARecord", value_key: nil },
|
76
|
-
{ name: :mx, uri_name: "MXRecord", value_key:
|
77
|
-
{ name: :ns, uri_name: "NSRecord", value_key:
|
78
|
-
{ name: :
|
76
|
+
{ name: :mx, uri_name: "MXRecord", value_key: ["exchange", "preference"] },
|
77
|
+
{ name: :ns, uri_name: "NSRecord", value_key: "nsdname" },
|
78
|
+
{ name: :txt, uri_name: "TXTRecord", value_key: "txtdata" },
|
79
79
|
{ name: :spf, uri_name: "SPFRecord", value_key: nil }
|
80
80
|
].each do |args|
|
81
81
|
@@types << EZDyn::RecordType.new(**args)
|
data/lib/ezdyn/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ezdyn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Adams
|
8
|
+
- Dan Dorman
|
9
|
+
- Eric Coan
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date:
|
13
|
+
date: 2019-12-11 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
16
|
name: yard
|
@@ -65,8 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
67
|
- !ruby/object:Gem::Version
|
66
68
|
version: '0'
|
67
69
|
requirements: []
|
68
|
-
|
69
|
-
rubygems_version: 2.6.13
|
70
|
+
rubygems_version: 3.0.6
|
70
71
|
signing_key:
|
71
72
|
specification_version: 4
|
72
73
|
summary: Simple library for Dyn Managed DNS
|