Sha256: d1ce379f5b6ebdd633bb40fa8d08d9734cf1b3fcacaa4b37f402b2a36f3921bc

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

module Fog
  module DNS
    class AzureRM
      class Real
        def list_zones
          zone_hash_array = []
          @resources.resource_groups.each do |rg|
            list_zones(rg.name).each do |zone_hash|
              zone_hash['resource_group'] = rg.name              
              zone_hash_array << zone_hash
            end
          end
          zone_hash_array
        end

        def list_zones(dns_resource_group)
          resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{dns_resource_group}/providers/Microsoft.Network/dnsZones?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)
            response_hash = JSON.parse(dns_response)
            response_hash['value']
          rescue RestClient::Exception => e
            body = JSON.parse(e.http_body)
            if body.key?('error')
              body = body['error']
              msg = "Exception fetching zones: #{body['code']}, #{body['message']}"
            else
              msg = "Exception fetching zones: #{body['code']}, #{body['message']}"
            end
            raise msg
          end
        end
      end

      class Mock
        def list_zones
          zone = {
            id: '/subscriptions/########-####-####-####-############/resourceGroups/fog-test-resource-group/Microsoft.Network/dnszones/fogtestzone.com',
            name: 'fogtestzone.com',
            resource_group: 'fog-test-resource-group'
          }
          [zone]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fog-azure-rm-0.0.0 lib/fog/azurerm/requests/dns/list_zones.rb