File: domain_metadata.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 (72 lines) | stat: -rw-r--r-- 2,726 bytes parent folder | download | duplicates (5)
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
module Fog
  module AWS
    class SimpleDB
      class Real
        require 'fog/aws/parsers/simpledb/domain_metadata'

        # List metadata for SimpleDB domain
        #
        # ==== Parameters
        # * domain_name<~String> - Name of domain. Must be between 3 and 255 of the
        # following characters: a-z, A-Z, 0-9, '_', '-' and '.'.
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'AttributeNameCount' - number of unique attribute names in domain
        #     * 'AttributeNamesSizeBytes' - total size of unique attribute names, in bytes
        #     * 'AttributeValueCount' - number of all name/value pairs in domain
        #     * 'AttributeValuesSizeBytes' - total size of attributes, in bytes
        #     * 'BoxUsage'
        #     * 'ItemCount' - number of items in domain
        #     * 'ItemNameSizeBytes' - total size of item names in domain, in bytes
        #     * 'RequestId'
        #     * 'Timestamp' - last update time for metadata.
        def domain_metadata(domain_name)
          request(
            'Action'      => 'DomainMetadata',
            'DomainName'  => domain_name,
            :idempotent   => true,
            :parser       => Fog::Parsers::AWS::SimpleDB::DomainMetadata.new(@nil_string)
          )
        end
      end

      class Mock
        def domain_metadata(domain_name)
          response = Excon::Response.new
          if domain = self.data[:domains][domain_name]
            response.status = 200

            attribute_names = []
            attribute_values = []
            for item in domain.values
              for key, values in item
                attribute_names << key
                for value in values
                  attribute_values << value
                end
              end
            end

            response.body = {
              'AttributeNameCount'        => attribute_names.length,
              'AttributeNamesSizeBytes'   => attribute_names.join('').length,
              'AttributeValueCount'       => attribute_values.length,
              'AttributeValuesSizeBytes'  => attribute_values.join('').length,
              'BoxUsage'                  => Fog::AWS::Mock.box_usage,
              'ItemCount'                 => domain.keys.length,
              'ItemNamesSizeBytes'        => domain.keys.join('').length,
              'RequestId'                 => Fog::AWS::Mock.request_id,
              'Timestamp'                 => Time.now
            }
          else
            response.status = 400
            raise(Excon::Errors.status_error({:expects => 200}, response))
          end
          response
        end
      end
    end
  end
end