File: list_hosted_zones.rb

package info (click to toggle)
ruby-fog-aws 3.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,092 kB
  • sloc: ruby: 72,795; javascript: 14; makefile: 9; sh: 4
file content (88 lines) | stat: -rw-r--r-- 2,627 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
module Fog
  module AWS
    class DNS
      class Real
        require 'fog/aws/parsers/dns/list_hosted_zones'

        # Describe all or specified instances
        #
        # ==== Parameters
        # * options<~Hash>
        #   * marker<~String> - Indicates where to begin in your list of hosted zones.
        #   * max_items<~Integer> - The maximum number of hosted zones to be included in the response body
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'HostedZones'<~Array>:
        #       * 'HostedZone'<~Hash>:
        #         * 'Id'<~String> -
        #         * 'Name'<~String> -
        #         * 'CallerReference'<~String>
        #         * 'Comment'<~String> -
        #     * 'Marker'<~String> -
        #     * 'MaxItems'<~Integer> -
        #     * 'IsTruncated'<~String> -
        #     * 'NextMarker'<~String>
        #   * status<~Integer> - 200 when successful
        def list_hosted_zones(options = {})
          parameters = {}
          options.each do |option, value|
            case option
            when :marker
              parameters[option] = value
            when :max_items
              parameters[:maxitems] = value
            end
          end

          request({
            :query   => parameters,
            :parser  => Fog::Parsers::AWS::DNS::ListHostedZones.new,
            :expects => 200,
            :method  => 'GET',
            :path    => "hostedzone"
          })
        end
      end

      class Mock
        def list_hosted_zones(options = {})
          maxitems = [options[:max_items]||100,100].min

          if options[:marker].nil?
            start = 0
          else
            start = self.data[:zones].find_index {|z| z[:id] == options[:marker]}
          end

          zones     = self.data[:zones].values[start, maxitems]
          next_zone = self.data[:zones].values[start + maxitems]
          truncated = !next_zone.nil?

          response = Excon::Response.new
          response.status = 200
          response.body = {
            'HostedZones' => zones.map do |z|
              {
                'Id' => z[:id],
                'Name' => z[:name],
                'CallerReference' => z[:reference],
                'Comment' => z[:comment],
              }
            end,
            'Marker' => options[:marker].to_s,
            'MaxItems' => maxitems,
            'IsTruncated' => truncated
          }

          if truncated
            response.body['NextMarker'] = next_zone[:id]
          end

          response
        end
      end
    end
  end
end