lib/fog/azurerm/requests/dns/check_for_zone.rb in fog-azure-rm-0.0.1 vs lib/fog/azurerm/requests/dns/check_for_zone.rb in fog-azure-rm-0.0.2

- old
+ new

@@ -1,38 +1,37 @@ module Fog module DNS class AzureRM + # Real class for DNS Request class Real def check_for_zone(resource_group, name) resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Network/dnsZones/#{name}?api-version=2015-05-04-preview" begin token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret) - dns_response = RestClient.get( - resource_url, - accept: 'application/json', - content_type: 'application/json', - authorization: token) - dns_hash = JSON.parse(dns_response) - if dns_hash.key?('id') && !dns_hash['id'].nil? - true - else - false - end + RestClient.get( + resource_url, + accept: 'application/json', + content_type: 'application/json', + authorization: token) + true rescue RestClient::Exception => e - if e.http_code == 404 + body = JSON.parse(e.response) + if(body['error']['code']) == 'ResourceNotFound' false else - body = JSON.parse(e.http_body) - msg = "Exception checking if the zone exists: #{body['code']}, #{body['message']}" - fail msg + Fog::Logger.warning "Exception checking if the zone exists in resource group #{resource_group}" + msg = "Exception checking if the zone exists: #{body['error']['code']}, #{body['error']['message']}" + raise msg end end end end + # Mock class for DNS Request class Mock - def check_for_zone(resource_group, name) - + def check_for_zone(_resource_group, _name) + Fog::Logger.debug "Zone name #{_name} is available." + return true end end end end end