Sha256: b9258bf56f259cd63079c9ab91d1fef72167013b5bdc1d857e966e2c81acaf6b

Contents?: true

Size: 1.63 KB

Versions: 15

Compression:

Stored size: 1.63 KB

Contents

module Fog
  module AWS
    class Compute
      class Real

        require 'fog/compute/parsers/aws/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

15 entries across 15 versions & 2 rubygems

Version Path
fog-0.8.1 lib/fog/compute/requests/aws/import_key_pair.rb
fog-0.8.0 lib/fog/compute/requests/aws/import_key_pair.rb
fog-0.7.2 lib/fog/compute/requests/aws/import_key_pair.rb
fog-0.7.1 lib/fog/compute/requests/aws/import_key_pair.rb
fog-0.7.0 lib/fog/compute/requests/aws/import_key_pair.rb
fog-0.6.0 lib/fog/compute/requests/aws/import_key_pair.rb
fog-0.5.3 lib/fog/compute/requests/aws/import_key_pair.rb
fog-0.5.2 lib/fog/compute/requests/aws/import_key_pair.rb
fog-0.5.1 lib/fog/compute/requests/aws/import_key_pair.rb
fog-0.5.0 lib/fog/compute/requests/aws/import_key_pair.rb
phpfog-fog-0.4.1.3 lib/fog/compute/requests/aws/import_key_pair.rb
phpfog-fog-0.4.1.2 lib/fog/compute/requests/aws/import_key_pair.rb
phpfog-fog-0.4.1.1 lib/fog/compute/requests/aws/import_key_pair.rb
phpfog-fog-0.4.1 lib/fog/compute/requests/aws/import_key_pair.rb
fog-0.4.1 lib/fog/compute/requests/aws/import_key_pair.rb