Sha256: 7f60b8d1ff9a1ffc1a19fdf46b3ed39d91852a31374651a503e97426ce7a93f4

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

module Fog
  module DNS
    class AzureRM
      class Real
        def list_record_sets(dns_resource_group, zone_name)
          resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{dns_resource_group}/providers/Microsoft.Network/dnsZones/#{zone_name}/recordsets?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 record_sets: #{body['code']}, #{body['message']}"
            else
              msg = "Exception fetching record_sets: #{body['code']}, #{body['message']}"
            end
            raise msg
          end
        end
      end

      class Mock
        def list_record_sets(dns_resource_group, zone_name)
          rset = {
            :name => 'fogtestrecordset',
            :resource_group => 'fog-test-resource-group',
            :zone_name => 'fogtestzone.com',
            :records => ['1.2.3.4', '1.2.3.3'],
            :type => 'A',
            :ttl => 60
          }
          [rset]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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