Sha256: ec23424e2565795efdbcd469aa371fa5bdecb62349742bdb45f6ad672fa7170c

Contents?: true

Size: 1.78 KB

Versions: 61

Compression:

Stored size: 1.78 KB

Contents

module Fog
  module Compute
    class AWS
      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
        #
        # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-ImportKeyPair.html]
        def import_key_pair(key_name, public_key_material)
          request(
            'Action'  => 'ImportKeyPair',
            'KeyName' => key_name,
            'PublicKeyMaterial' => Base64::encode64(public_key_material),
            :parser   => Fog::Parsers::Compute::AWS::ImportKeyPair.new
          )
        end
      end

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

Version data entries

61 entries across 59 versions & 6 rubygems

Version Path
fog-aws-3.1.0 lib/fog/aws/requests/compute/import_key_pair.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-aws-2.0.1/lib/fog/aws/requests/compute/import_key_pair.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-aws-2.0.1/lib/fog/aws/requests/compute/import_key_pair.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-aws-2.0.1/lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-3.0.0 lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-2.0.1 lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-2.0.0 lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-1.4.1 lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-1.4.0 lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-1.3.0 lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-1.2.1 lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-1.2.0 lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-1.1.0 lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-1.0.0 lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-0.13.0 lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-0.12.0 lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-0.11.0 lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-0.10.0 lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-0.9.4 lib/fog/aws/requests/compute/import_key_pair.rb
fog-aws-0.9.3 lib/fog/aws/requests/compute/import_key_pair.rb