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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 27245dd948ed180b98c7c3f1546e3a4239d5ad79
4
- data.tar.gz: 165e52bfa90722ee772a86386b2983e3ff653fcc
2
+ SHA256:
3
+ metadata.gz: 4ba5f7252dbce98914e413a84e9721e5363e3c3b8dc217b95585f745ce7dd35e
4
+ data.tar.gz: adc0b38aab81daf21235845ccc0098d6ddb9e60fe372f4d12c0fc1a4386a815a
5
5
  SHA512:
6
- metadata.gz: fe8505dc8afae76e3b612cb43075848ffd607f6449fa8bbc1bd388285fe05ce365faa8a5a5705807578deada140b8a4e5a33081b9284e6c8f2a511a5b8b4015e
7
- data.tar.gz: 5e7f19e6b6200c547e0bf4d7d039d01397de0137793c5071dfc13c2cec0f019b385fa3e9a3fc86e7c2d1dc0b8eec71439614f7f6541f2b5fddd45bbb18b833cb
6
+ metadata.gz: 7c3db8aabdd6d5801da22bf28849422d9984b5976889fedaa61a72cf39fd72bf58aa6ed5878d9505debe4166680c4da2bb727904b558ead22e8b16357c935498
7
+ data.tar.gz: 66b0831ecf710fab181c15bcbdac141962e6132227b7dca25e61e63eec1926f729869aa82b0029e4b330b9f85b711d92207192aecb7f183b8d698ae2e0265486
@@ -1,5 +1,9 @@
1
1
  # ezdyn changelog
2
2
 
3
+ ## Version 0.3.1 - 2018-04-04
4
+
5
+ * Bugfix of typo in error message
6
+
3
7
  ## Version 0.3.0 - 2017-11-06
4
8
 
5
9
  * Added AllRecords support for fetching all records in a zone.
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)
@@ -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.author = "David Adams"
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"
@@ -67,9 +67,13 @@ module EZDyn
67
67
  # A pending record update.
68
68
  class UpdateChange < Change
69
69
  # @private
70
- def initialize(record:, new_record:)
71
- @record = record.sync!
72
- @new_record = new_record
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 @record.ttl == @new_record.ttl
81
- @record.ttl
84
+ if @records.map(&:ttl).min == @new_records.map(&:ttl).min
85
+ @records.map(&:ttl).min
82
86
  else
83
- "(( #{@record.ttl} -> #{@new_record.ttl} ))"
87
+ "(( #{@records.map(&:ttl).min} -> #{@new_records.map(&:ttl).min} ))"
84
88
  end
85
89
 
86
90
  value_string =
87
- if @record.value == @new_record.value
88
- @record.value
91
+ if @records.map(&:value).join(',') == @new_records.map(&:value).join(',')
92
+ @records.map(&:value).join(',')
89
93
  else
90
- "(( #{@record.value} -> #{@new_record.value} ))"
94
+ "(( #{@records.map(&:value).join(',')} -> #{@new_records.map(&:value).join(',')} ))"
91
95
  end
92
96
 
93
- "UPDATE #{@record.fqdn}. #{ttl_string} #{@record.type} #{value_string}"
97
+ "UPDATE #{@new_records.first.fqdn}. #{ttl_string} #{@new_records.first.type} #{value_string}"
94
98
  end
95
99
  end
96
100
 
@@ -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, Hash] Value to submit for the record data.
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
- response = self.call_api(
24
- method: "post",
25
- uri: self.build_uri(type: type, fqdn: fqdn),
26
- payload: { rdata: { RecordType.find(type).value_key => value }, ttl: ttl }
27
- )
28
-
29
- if not response.success?
30
- raise "Failed to create record: #{response.simple_message}"
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
- record = Record.new(client: self, raw: response.data)
34
- self.add_pending_change(CreateChange.new(record: record))
29
+ if not response.success?
30
+ raise "Failed to create record: #{response.simple_message}"
31
+ end
35
32
 
36
- return record
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, Hash] New value to submit for the record data (optional if updating TTL and record already exists).
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
- record =
64
- if records.count == 0
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 record.nil?
76
- if not fqdn.nil? and not type.nil? and not value.nil?
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: record.uri,
75
+ uri: self.build_uri(type: type, fqdn: fqdn),
87
76
  payload: {
88
- rdata: {
89
- record.type.value_key => ( value || record.value ),
90
- },
91
- ttl: ( ttl || record.ttl ),
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
- new_record = Record.new(client: self, raw: response.data)
100
- self.add_pending_change(UpdateChange.new(record: record, new_record: new_record))
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 new_record
92
+ return new_records
103
93
  end
104
94
 
105
95
  # Delete a record.
@@ -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"][@type.value_key]
132
+ @value = Array(@type.value_key).map { |k| raw["rdata"][k] }.join(' ')
133
133
  @in_sync = true
134
134
  @exists = true
135
135
  end
@@ -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: nil },
77
- { name: :ns, uri_name: "NSRecord", value_key: nil },
78
- { name: :text, uri_name: "TXTRecord", value_key: nil },
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)
@@ -1,4 +1,4 @@
1
1
  module EZDyn
2
2
  # The version number of the library.
3
- VERSION = "0.3.1"
3
+ VERSION = "0.4.0"
4
4
  end
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.3.1
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: 2018-04-05 00:00:00.000000000 Z
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
- rubyforge_project:
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