File: get_hosted_zone.rb

package info (click to toggle)
ruby-fog-aws 3.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,816 kB
  • sloc: ruby: 68,587; makefile: 6
file content (60 lines) | stat: -rw-r--r-- 1,935 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module Fog
  module AWS
    class DNS
      class Real
        require 'fog/aws/parsers/dns/get_hosted_zone'

        # retrieve information about a hosted zone
        #
        # ==== Parameters
        # * zone_id<~String> - The ID of the hosted zone
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'HostedZone'<~Hash>:
        #       * 'Id'<~String> -
        #       * 'Name'<~String> -
        #       * 'CallerReference'<~String>
        #       * 'Comment'<~String> -
        #     * 'NameServers'<~Array>
        #       * 'NameServer'<~String>
        #   * status<~Integer> - 200 when successful
        def get_hosted_zone(zone_id)
          # AWS methods return zone_ids that looks like '/hostedzone/id'.  Let the caller either use
          # that form or just the actual id (which is what this request needs)
          zone_id = zone_id.sub('/hostedzone/', '')

          request({
            :expects => 200,
            :idempotent => true,
            :method  => 'GET',
            :parser  => Fog::Parsers::AWS::DNS::GetHostedZone.new,
            :path    => "hostedzone/#{zone_id}"
          })
        end
      end

      class Mock
        def get_hosted_zone(zone_id)
          response = Excon::Response.new
          if (zone = self.data[:zones][zone_id])
            response.status = 200
            response.body = {
              'HostedZone' => {
                'Id' => zone[:id],
                'Name' => zone[:name],
                'CallerReference' => zone[:reference],
                'Comment' => zone[:comment]
              },
              'NameServers' => Fog::AWS::Mock.nameservers
            }
            response
          else
            raise Fog::AWS::DNS::NotFound.new("NoSuchHostedZone => A hosted zone with the specified hosted zone ID does not exist.")
          end
        end
      end
    end
  end
end