summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRodrigo Coutinho <rodrigo.coutinho@locaweb.com.br>2016-10-06 15:56:04 -0300
committerRodrigo Coutinho <rodrigo.coutinho@locaweb.com.br>2016-10-06 15:56:04 -0300
commita49a035a127325e412fbe6408d6ec73d925b1ea9 (patch)
tree8d064e42278ba7b8434f7977f1e336e75b66818f
parentDelete record symbolize keys (diff)
Format rrset to update resource record
-rw-r--r--lib/powerdnsex/managers/records_manager.ex6
-rw-r--r--lib/powerdnsex/models/resource_record_set.ex22
2 files changed, 17 insertions, 11 deletions
diff --git a/lib/powerdnsex/managers/records_manager.ex b/lib/powerdnsex/managers/records_manager.ex
index e59a153..37e6096 100644
--- a/lib/powerdnsex/managers/records_manager.ex
+++ b/lib/powerdnsex/managers/records_manager.ex
@@ -1,4 +1,5 @@
defmodule PowerDNSex.Managers.RecordsManager do
+ require Logger
alias PowerDNSex.HttpClient
alias PowerDNSex.Models.{Zone, Record, Error}
@@ -58,8 +59,11 @@ defmodule PowerDNSex.Managers.RecordsManager do
end
defp patch(%Zone{} = zone, %RRSet{} = rrset) do
+ rrset_body = RRSet.as_body(rrset)
+ Logger.info "Request to [#{zone.name}] with params [#{rrset_body}]"
+
zone.url
- |> HttpClient.patch!(RRSet.as_body(rrset))
+ |> HttpClient.patch!(rrset_body)
|> process_request_response
end
diff --git a/lib/powerdnsex/models/resource_record_set.ex b/lib/powerdnsex/models/resource_record_set.ex
index 52dbed2..d02d2c9 100644
--- a/lib/powerdnsex/models/resource_record_set.ex
+++ b/lib/powerdnsex/models/resource_record_set.ex
@@ -35,21 +35,23 @@ defmodule PowerDNSex.Models.ResourceRecordSet do
end
def update(%__MODULE__{} = rrset, %{} = new_attrs) do
- Enum.reduce(@permited_attrs, rrset, fn(attr_name, rrset)->
- case Map.fetch(new_attrs, attr_name) do
- {:ok, new_value} ->
- if attr_name == :records do
- new_value = Record.build(new_value)
- end
- %{rrset | attr_name => new_value}
- _ -> rrset
- end
- end)
+ format_attrs(new_attrs, rrset)
+ |> Enum.reduce(rrset, fn( {attr, value}, rrset) ->
+ %{rrset | attr => value}
+ end)
end
###
# Private
###
+ #
+ defp format_attrs(new_attrs, rrset) do
+ record = %Record{content: new_attrs.content, disabled: new_attrs.disabled }
+ %{
+ records: [record],
+ ttl: Map.get(new_attrs, :ttl, rrset.ttl)
+ }
+ end
defp set_attrs(rrset, attr_name, attrs) do
if Map.has_key?(attrs, attr_name) do