1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[google|dns] Add get method to RRSet

- Add "get" method and tests to Resource Record Sets
This commit is contained in:
Ferran Rodenas 2014-10-20 13:40:52 -07:00
parent 3ef4d66478
commit 3939b021a2
7 changed files with 69 additions and 9 deletions

View file

@ -21,6 +21,10 @@ def test
puts '------------------------------------'
zone.records
puts 'Get the Record...'
puts '-----------------'
record = connection.records(zone: zone).get(name: 'test.example.org.', type: 'A')
puts 'Modify the "A" Record...'
puts '------------------------'
record.modify(ttl: 2600)

View file

@ -51,6 +51,18 @@ module Fog
self
end
##
# Reloads a Resource Record Sets resource
#
# @return [Fog::DNS::Google::Record] Resource Record Sets resource
def reload
requires :name, :type
data = collection.get(self.name, self.type)
merge_attributes(data.attributes)
self
end
##
# Creates a new Resource Record Sets resource
#

View file

@ -22,6 +22,21 @@ module Fog
[]
end
##
# Fetches the representation of an existing Resource Record Set
#
# @param [String] name Resource Record Set name
# @param [String] type Resource Record Set type
# @return [Fog::DNS::Google::Record] Resource Record Set resource
def get(name, type)
requires :zone
records = service.list_resource_record_sets(zone.identity, { :name => name, :type => type }).body['rrsets'] || []
records.any? ? new(records.first) : nil
rescue Fog::Errors::NotFound
nil
end
##
# Creates a new instance of a Resource Record Set
#

View file

@ -6,19 +6,23 @@ module Fog
#
# @see https://developers.google.com/cloud-dns/api/v1beta1/resourceRecordSets/list
class Real
def list_resource_record_sets(zone_name_or_id)
def list_resource_record_sets(zone_name_or_id, options = {})
api_method = @dns.resource_record_sets.list
parameters = {
'project' => @project,
'managedZone' => zone_name_or_id,
}
[:name, :type].reject{ |o| options[o].nil? }.each do |key|
parameters[key] = options[key]
end
request(api_method, parameters)
end
end
class Mock
def list_resource_record_sets(zone_name_or_id)
def list_resource_record_sets(zone_name_or_id, options = {})
if self.data[:managed_zones].has_key?(zone_name_or_id)
zone = self.data[:managed_zones][zone_name_or_id]
else
@ -29,9 +33,14 @@ module Fog
raise Fog::Errors::NotFound, "The 'parameters.managedZone' resource named '#{zone_name_or_id}' does not exist."
end
rrsets = self.data[:resource_record_sets][zone['id']]
if options.has_key?(:name) && options.has_key?(:type)
rrsets.delete_if { |rrset| rrset['name'] != options[:name] || rrset['type'] != options[:type] }
end
body = {
'kind' => 'dns#resourceRecordSetsListResponse',
'rrsets' => self.data[:resource_record_sets][zone['id']],
'rrsets' => rrsets,
}
build_excon_response(body)
end

View file

@ -28,6 +28,10 @@ Shindo.tests('Fog::DNS[:google] | record model', ['google']) do
@record.modify({ :ttl => 2600 })
end
tests('#reload').succeeds do
@record.reload
end
tests('#destroy').succeeds do
@record.destroy
end

View file

@ -6,19 +6,31 @@ Shindo.tests('Fog::DNS[:google] | records model', ['google']) do
end
@dns = Fog::DNS[:google]
@zone = @dns.zones.create(
:name => Fog::Mock.random_letters(16),
:domain => ENV['FOG_TEST_GOOGLE_DNS_ZONE'] || generate_unique_domain,
:description => 'Fog test domain'
)
tests('success') do
@zone = @dns.zones.create(
:name => Fog::Mock.random_letters(16),
:domain => ENV['FOG_TEST_GOOGLE_DNS_ZONE'] || generate_unique_domain,
:description => 'Fog test domain'
)
tests('#all').succeeds do
@dns.records(:service => @dns, :zone => @zone).all
end
@zone.destroy
tests('#get').succeeds do
@dns.records(:service => @dns, :zone => @zone).get(@zone.domain, 'NS')
end
end
tests('failure') do
tests('#get').returns(nil) do
@dns.records(:service => @dns, :zone => @zone).get(@zone.domain, 'A')
end
end
@zone.destroy
end

View file

@ -31,6 +31,10 @@ Shindo.tests('Fog::DNS[:google] | record requests', ['google']) do
@dns.list_resource_record_sets(@zone.identity).body
end
tests('#list_resource_record_sets (with name and type)').formats(@list_resource_record_sets_format) do
@dns.list_resource_record_sets(@zone.identity, { :name => @zone.domain, :type => 'NS' }).body
end
@zone.destroy
end