File: list_keys.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 (82 lines) | stat: -rw-r--r-- 2,217 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
73
74
75
76
77
78
79
80
81
82
module Fog
  module AWS
    class KMS
      class Real

        require 'fog/aws/parsers/kms/list_keys'

        def list_keys(options={})
          params = {}

          if options[:marker]
            params['Marker'] = options[:marker]
          end

          if options[:limit]
            params['Limit'] = options[:limit]
          end

          request({
            'Action' => 'ListKeys',
            :parser  => Fog::Parsers::AWS::KMS::ListKeys.new
          }.merge(params))
        end
      end

      class Mock
        def list_keys(options={})
          limit  = options[:limit]
          marker = options[:marker]

          if limit
            if limit > 1_000
              raise Fog::AWS::KMS::Error.new(
                "ValidationError => 1 validation error detected: Value '#{limit}' at 'limit' failed to satisfy constraint: Member must have value less than or equal to 1000"
              )
            elsif limit <  1
              raise Fog::AWS::KMS::Error.new(
                "ValidationError => 1 validation error detected: Value '#{limit}' at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1"
              )
            end
          end

          key_set = if marker
                      self.data[:markers][marker] || []
                    else
                      self.data[:keys].inject([]) { |r,(k,v)|
                        r << { "KeyId" => k, "KeyArn" => v["Arn"] }
                      }
                    end

          keys = if limit
                   key_set.slice!(0, limit)
                 else
                   key_set
                 end

          truncated = keys.size < key_set.size

          marker = truncated && "metadata/l/#{account_id}/#{UUID.uuid}"

          response = Excon::Response.new

          body = {
            'Keys'      => keys,
            'Truncated' => truncated,
            'RequestId' => Fog::AWS::Mock.request_id
          }

          if marker
            self.data[:markers][marker] = key_set
            body.merge!('Marker' => marker)
          end

          response.body = body
          response.status = 200

          response
        end
      end
    end
  end
end