Sha256: d872cba19619fdb4b135d0a82a29f1cb8345ee614713e5a9e37cffdb548fb51b

Contents?: true

Size: 1.66 KB

Versions: 30

Compression:

Stored size: 1.66 KB

Contents

module Fog
  module AWS
    module EC2
      class Real

        # Describe all or specified key pairs
        #
        # ==== Parameters
        # * key_name<~Array>:: List of key names to describe, defaults to all
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'requestId'<~String> - Id of request
        #     * 'keySet'<~Array>:
        #       * 'keyName'<~String> - Name of key
        #       * 'keyFingerprint'<~String> - Fingerprint of key
        def describe_key_pairs(key_name = [])
          params = AWS.indexed_param('KeyName', key_name)
          request({
            'Action'  => 'DescribeKeyPairs',
            :parser   => Fog::Parsers::AWS::EC2::DescribeKeyPairs.new
          }.merge!(params))
        end

      end

      class Mock

        def describe_key_pairs(key_name = [])
          response = Excon::Response.new
          key_name = [*key_name]
          if key_name != []
            key_set = @data[:key_pairs].reject {|key, value| !key_name.include?(key)}.values
          else
            key_set = @data[:key_pairs].values
          end
          if key_name.length == 0 || key_name.length == key_set.length
            response.status = 200
            response.body = {
              'requestId' => Fog::AWS::Mock.request_id,
              'keySet'    => key_set.map do |key|
                key.reject {|key,value| !['keyFingerprint', 'keyName'].include?(key)}
              end
            }
          else
            response.status = 400
            raise(Excon::Errors.status_error({:expects => 200}, response))
          end
          response
        end

      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
fog-0.1.1 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.1.0 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.100 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.99 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.98 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.97 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.96 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.95 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.94 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.93 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.92 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.91 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.90 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.89 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.88 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.87 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.86 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.85 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.84 lib/fog/aws/requests/ec2/describe_key_pairs.rb
fog-0.0.83 lib/fog/aws/requests/ec2/describe_key_pairs.rb