Parent

Files

Class/Module Index [+]

Quicksearch

Fog::AWS::IAM::Mock

Public Class Methods

data() click to toggle source
# File lib/fog/aws/iam.rb, line 60
def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] = {
      :owner_id => Fog::AWS::Mock.owner_id,
      :server_certificates => {}
    }
  end
end
new(options={}) click to toggle source
# File lib/fog/aws/iam.rb, line 77
def initialize(options={})
  @aws_access_key_id = options[:aws_access_key_id]
end
reset() click to toggle source
# File lib/fog/aws/iam.rb, line 69
def self.reset
  @data = nil
end
server_certificate_id() click to toggle source
# File lib/fog/aws/iam.rb, line 73
def self.server_certificate_id
  Fog::Mock.random_hex(16)
end

Public Instance Methods

data() click to toggle source
# File lib/fog/aws/iam.rb, line 81
def data
  self.class.data[@aws_access_key_id]
end
delete_server_certificate(server_certificate_name) click to toggle source
# File lib/fog/aws/requests/iam/delete_server_certificate.rb, line 32
def delete_server_certificate(server_certificate_name)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'RequestId' => Fog::AWS::Mock.request_id
  }

  self.data[:server_certificates].delete(server_certificate_name)

  response
end
get_server_certificate(name) click to toggle source
# File lib/fog/aws/requests/iam/get_server_certificate.rb, line 32
def get_server_certificate(name)
  raise Fog::AWS::IAM::NotFound unless certificate = self.data[:server_certificates][name]

  response = Excon::Response.new
  response.status = 200
  response.body = {
    'Certificate' => certificate,
    'RequestId' => Fog::AWS::Mock.request_id
  }

  response
end
list_server_certificates(options = {}) click to toggle source
# File lib/fog/aws/requests/iam/list_server_certificates.rb, line 42
def list_server_certificates(options = {})
  certificates = self.data[:server_certificates].values
  certificates = certificates.select { |certificate| certificate['Path'] =~ Regexp.new("^#{options['PathPrefix']}") } if options['PathPrefix']
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'Certificates' => certificates
  }

  response
end
reset_data() click to toggle source
# File lib/fog/aws/iam.rb, line 85
def reset_data
  self.class.data.delete(@aws_access_key_id)
end
upload_server_certificate(certificate, private_key, name, options = {}) click to toggle source
# File lib/fog/aws/requests/iam/upload_server_certificate.rb, line 46
def upload_server_certificate(certificate, private_key, name, options = {})
  if certificate.nil? || certificate.empty? || private_key.nil? || private_key.empty?
    raise Fog::AWS::IAM::ValidationError.new
  end
  response = Excon::Response.new

  # Validate cert and key
  begin
    cert = OpenSSL::X509::Certificate.new(certificate)
    chain = OpenSSL::X509::Certificate.new(options['CertificateChain']) if options['CertificateChain']
    key = OpenSSL::PKey::RSA.new(private_key)
  rescue OpenSSL::X509::CertificateError, OpenSSL::PKey::RSAError => e
    message = if e.is_a?(OpenSSL::X509::CertificateError)
                "Invalid Public Key Certificate."
              else
                "Invalid Private Key."
              end
    raise Fog::AWS::IAM::MalformedCertificate.new(message)
  end

  unless cert.check_private_key(key)
    raise Fog::AWS::IAM::KeyPairMismatch.new
  end

  if self.data[:server_certificates][name]
    raise Fog::AWS::IAM::EntityAlreadyExists.new
  else
    response.status = 200
    path = options['path'] || "/"
    data = {
      'Arn' => Fog::AWS::Mock.arn('iam', self.data[:owner_id], "server-certificate/#{name}"),
      'Path' => path,
      'ServerCertificateId' => Fog::AWS::IAM::Mock.server_certificate_id,
      'ServerCertificateName' => name,
      'UploadDate' => Time.now
    }
    self.data[:server_certificates][name] = data
    response.body = {
      'Certificate' => data,
      'RequestId' => Fog::AWS::Mock.request_id
    }
  end

  response
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.