Sha256: 597006a542fe3e8dba4faf5c03573b5bd63f4df95d968d0b62d5fd7009076d18

Contents?: true

Size: 1.63 KB

Versions: 37

Compression:

Stored size: 1.63 KB

Contents

module Fog
  module AWS
    class Compute
      class Real

        require 'fog/aws/parsers/compute/import_key_pair'

        # Import an existing public key to create a new key pair
        #
        # ==== Parameters
        # * key_name<~String> - Unique name for key pair.
        # * public_key_material<~String> - RSA public key
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'keyFingerprint'<~String> - SHA-1 digest of DER encoded private key
        #     * 'keyName'<~String> - Name of key
        #     * 'requestId'<~String> - Id of request
        def import_key_pair(key_name, public_key_material)
          request(
            'Action'  => 'ImportKeyPair',
            'KeyName' => key_name,
            'PublicKeyMaterial' => Base64::encode64(public_key_material),
            :parser   => Fog::Parsers::AWS::Compute::ImportKeyPair.new
          )
        end

      end

      class Mock

        def import_key_pair(key_name, public_key_material)
          response = Excon::Response.new
          unless @data[:key_pairs][key_name]
            response.status = 200
            data = {
              'keyFingerprint'  => Fog::AWS::Mock.key_fingerprint,
              'keyName'         => key_name
            }
            @data[:key_pairs][key_name] = data
            response.body = {
              'requestId' => Fog::AWS::Mock.request_id
            }.merge!(data)
            response
          else
            raise Fog::AWS::Compute::Error.new("InvalidKeyPair.Duplicate => The keypair '#{key_name}' already exists.")
          end
        end

      end
    end
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
fog-0.4.0 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.34 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.33 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.32 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.31 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.30 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.29 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.28 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.27 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.26 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.25 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.24 lib/fog/aws/requests/compute/import_key_pair.rb
bbcloud-0.8.1 lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.23 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.22 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.21 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.20 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.19 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.18 lib/fog/aws/requests/compute/import_key_pair.rb
fog-0.3.17 lib/fog/aws/requests/compute/import_key_pair.rb