Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update our provider to match dnsimple-ruby 4.5.0 #60

Merged
merged 9 commits into from Oct 19, 2018
Merged
25 changes: 14 additions & 11 deletions libraries/provider_dnsimple_record.rb
Expand Up @@ -31,7 +31,7 @@ def load_current_resource
@current_resource.domain(@new_resource.domain)
@current_resource.type(@new_resource.type)

records = dnsimple_client.zones.all_records(dnsimple_client_account_id,
records = dnsimple_client.zones.list_zone_records(dnsimple_client_account_id,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look at this. I tried the patch and it does fix that error, but list_zone_records is paginated with 30 records per page so the logic below to detect if this in existing record often fails once someone has more than 30 records.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be all_zone_records instead

Copy link
Member

@weppos weppos Oct 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
records = dnsimple_client.zones.list_zone_records(dnsimple_client_account_id,
records = dnsimple_client.zones.all_zone_records(dnsimple_client_account_id,

The method was renamed from all_records to all_zone_records.

@new_resource.domain)
@existing_record = records.data.detect do |record|
(record.name == @new_resource.record_name) && (record.type == @new_resource.type)
Expand Down Expand Up @@ -68,9 +68,10 @@ def load_current_resource

def create_record
converge_by("create record #{new_resource.record_name} for domain #{new_resource.domain}") do
dnsimple_client.zones.create_record(
dnsimple_client_account_id, new_resource.domain, **record_options
)
dnsimple_client.zones.create_zone_record(dnsimple_client_account_id,
new_resource.domain,
**record_options
)
Chef::Log.info "DNSimple: created #{new_resource.type} record for #{new_resource.name}.#{new_resource.domain}"
end
rescue Dnsimple::RequestError => e
Expand All @@ -79,9 +80,10 @@ def create_record

def delete_record
converge_by("delete record #{@new_resource.record_name} from domain #{@new_resource.domain}") do
dnsimple_client.zones.delete_record(dnsimple_client_account_id,
@current_resource.domain,
existing_record_id)
dnsimple_client.zones.delete_zone_record(dnsimple_client_account_id,
@current_resource.domain,
existing_record_id
)
Chef::Log.info "DNSimple: destroyed #{@new_resource.type} record " \
"for #{@new_resource.name}.#{@new_resource.domain}"
end
Expand All @@ -92,10 +94,11 @@ def delete_record
def update_record
return unless changed_record?
converge_by("update record #{new_resource.record_name} for domain #{new_resource.domain}") do
dnsimple_client.zones.update_record(dnsimple_client_account_id,
new_resource.domain,
existing_record_id,
**record_options)
dnsimple_client.zones.update_zone_record(dnsimple_client_account_id,
new_resource.domain,
existing_record_id,
**record_options
)
Chef::Log.info "DNSimple: updated #{new_resource.type} record for #{new_resource.name}.#{new_resource.domain}"
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/libraries/provider_dnsimple_record_spec.rb
Expand Up @@ -29,7 +29,7 @@
let(:response) { instance_double(Dnsimple::Response, data: data) }
let(:data) { instance_double(Dnsimple::Struct::Whoami, account: account) }
let(:account) { instance_double(Dnsimple::Struct::Account, id: 1) }
let(:zones) { instance_double(Dnsimple::Client::ZonesService, all_records: zone_records, create_record: zone_record) }
let(:zones) { instance_double(Dnsimple::Client::ZonesService, list_zone_records: zone_records, create_zone_record: zone_record) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let(:zones) { instance_double(Dnsimple::Client::ZonesService, list_zone_records: zone_records, create_zone_record: zone_record) }
let(:zones) { instance_double(Dnsimple::Client::ZonesService, all_zone_records: zone_records, create_zone_record: zone_record) }

let(:zone_records) { instance_double(Dnsimple::CollectionResponse, data: [zone_record]) }
let(:zone_record) { instance_double(Dnsimple::Struct::ZoneRecord, name: 'example_record') }
let(:dns_record) do
Expand Down Expand Up @@ -60,7 +60,7 @@

context 'when it fails request validation' do
before do
allow(zones).to receive(:create_record)
allow(zones).to receive(:create_zone_record)
.and_raise(Dnsimple::RequestError, request_error)
end

Expand Down Expand Up @@ -90,15 +90,15 @@
@new_resource.ttl = dns_record[:ttl]
@new_resource.domain = dns_record_domain
@provider.current_resource = @new_resource
allow(zones).to receive(:delete_record)
allow(zones).to receive(:delete_zone_record)
end

let(:client) { instance_double(Dnsimple::Client, identity: identity, zones: zones) }
let(:identity) { instance_double(Dnsimple::Client::Identity, whoami: response) }
let(:response) { instance_double(Dnsimple::Response, data: data) }
let(:data) { instance_double(Dnsimple::Struct::Whoami, account: account) }
let(:account) { instance_double(Dnsimple::Struct::Account, id: 1) }
let(:zones) { instance_double(Dnsimple::Client::ZonesService, all_records: zone_records) }
let(:zones) { instance_double(Dnsimple::Client::ZonesService, list_zone_records: zone_records) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let(:zones) { instance_double(Dnsimple::Client::ZonesService, list_zone_records: zone_records) }
let(:zones) { instance_double(Dnsimple::Client::ZonesService, all_zone_records: zone_records) }

let(:zone_records) { instance_double(Dnsimple::CollectionResponse, data: [zone_record]) }
let(:zone_record) { instance_double(Dnsimple::Struct::ZoneRecord, **dns_record) }
let(:dns_record_domain) { 'example.com' }
Expand Down Expand Up @@ -132,7 +132,7 @@

context 'when it fails validation' do
before do
allow(zones).to receive(:delete_record)
allow(zones).to receive(:delete_zone_record)
.and_raise(Dnsimple::RequestError, request_error)
allow(@provider).to receive(:existing_record_id).and_return(0)
end
Expand Down Expand Up @@ -171,7 +171,7 @@
let(:response) { instance_double(Dnsimple::Response, data: data) }
let(:data) { instance_double(Dnsimple::Struct::Whoami, account: account) }
let(:account) { instance_double(Dnsimple::Struct::Account, id: 1) }
let(:zones) { instance_double(Dnsimple::Client::ZonesService, all_records: zone_records, update_record: zone_record) }
let(:zones) { instance_double(Dnsimple::Client::ZonesService, list_zone_records: zone_records, update_zone_record: zone_record) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let(:zones) { instance_double(Dnsimple::Client::ZonesService, list_zone_records: zone_records, update_zone_record: zone_record) }
let(:zones) { instance_double(Dnsimple::Client::ZonesService, all_zone_records: zone_records, update_zone_record: zone_record) }

let(:zone_records) { instance_double(Dnsimple::CollectionResponse, data: [zone_record]) }
let(:zone_record) { instance_double(Dnsimple::Struct::ZoneRecord, **dns_record) }
let(:dns_record_domain) { 'example.com' }
Expand Down
2 changes: 1 addition & 1 deletion test/integration/create_record/libraries/dnsimple_zone.rb
Expand Up @@ -40,7 +40,7 @@ def response

filter = {}
filter = { type: @type } if @type
client.zones.records(account_id, @zone, filter: filter).data.detect do |record|
client.zones.list_zone_records(account_id, @zone, filter: filter).data.detect do |record|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
client.zones.list_zone_records(account_id, @zone, filter: filter).data.detect do |record|
client.zones.all_zone_records(account_id, @zone, filter: filter).data.detect do |record|

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martinisoft there is this one missing

record.name == @name
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/integration/update_record/libraries/dnsimple_zone.rb
Expand Up @@ -40,7 +40,7 @@ def response

filter = {}
filter = { type: @type } if @type
client.zones.records(account_id, @zone, filter: filter).data.detect do |record|
client.zones.list_zone_records(account_id, @zone, filter: filter).data.detect do |record|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
client.zones.list_zone_records(account_id, @zone, filter: filter).data.detect do |record|
client.zones.all_zone_records(account_id, @zone, filter: filter).data.detect do |record|

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this one

record.name == @name
end
end
Expand Down