Class: AWS::IAM::ServerCertificateCollection

Inherits:
Object
  • Object
show all
Includes:
Collection::WithPrefix
Defined in:
lib/aws/iam/server_certificate_collection.rb

Overview

A collection that provides access to IAM server certificates belonging to this account.

iam = AWS::IAM.new
certificates = iam.server_certificates

Uploading A Server Certificate

You can upload any valid, signed certificate using #upload.

certificates.upload(:name => "MyCert",
                    :certificate_body => my_certificate_body,
                    :private_key => my_private_key)

For information about generating a server certificate for use with IAM, see Creating and Uploading Server Certificates in Using AWS Identity and Access Management.

Getting a Server Certificate by Name

You can get a reference to a server certificate using array notation:

certificate = certificates['MyCert']

Enumerating Server Certificates

Server certificate collections can also be used to enumerate certificates:

certificates.each do |cert|
  puts cert.name
end

You can limit the certificates returned by passing a :prefix option to any of the enumerator methods. When you pass a prefix, only the certificates whose paths start with the given string will be returned.

Instance Attribute Summary

Attributes included from Collection::WithPrefix

#prefix

Instance Method Summary collapse

Methods included from Collection::WithPrefix

#with_prefix

Instance Method Details

#[](name) ⇒ ServerCertificate

Returns a reference to the server certificate with the given name:

certificate = iam.server_certificates['MyCert']

Parameters:

  • name (String)

    Name of the server certificate.

Returns:



119
120
121
# File 'lib/aws/iam/server_certificate_collection.rb', line 119

def [] name
  ServerCertificate.new(name, :config => config)
end

#each(options = {}) {|certificate| ... } ⇒ nil

Yields once for each server certificate

You can limit the number of certificates yielded using :limit and :path_prefix.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :path_prefix (String) — default: '/'

    A path prefix that filters according to the path of the certificate.

  • :limit (Integer)

    The maximum number of certificates to yield.

  • :batch_size (Integer)

    The maximum number of certificates to retrieve in each service request.

Yield Parameters:

Returns:

  • (nil)


141
142
143
# File 'lib/aws/iam/server_certificate_collection.rb', line 141

def each options = {}, &block
  super(options, &block)
end

#enumerator(options = {}) ⇒ Enumerator

Returns an enumerable object for this collection. This can be useful if you want to call an enumerable method that does not accept options (e.g. collect, first, etc).

certificates.enumerator(:path_prefix => '/production').
  collect(&:name)

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :path_prefix (String) — default: '/'

    A path prefix that filters according to the path of the certificate.

  • :limit (Integer)

    The maximum number of certificates to yield.

  • :batch_size (Integer)

    The maximum number of certificates to retrieve in each service request.

Returns:

  • (Enumerator)


155
156
157
# File 'lib/aws/iam/server_certificate_collection.rb', line 155

def enumerator options = {}
  super(options)
end

#upload(options = {}) ⇒ ServerCertificate Also known as: create

Uploads a server certificate entity for the AWS account. The server certificate entity includes a public key certificate, a private key, and an optional certificate chain, which should all be PEM-encoded.

Parameters:

  • options (Hash) (defaults to: {})

    Options for uploading the certificate. :name, :certificate_body, and :private_key are required.

Options Hash (options):

  • :certificate_body (String)

    The contents of the public key certificate in PEM-encoded format.

  • :name (String)

    The name for the server certificate. Do not include the path in this value.

  • :path (String)

    The path for the server certificate. For more information about paths, see Identifiers for IAM Entities in Using AWS Identity and Access Management.

  • :private_key (String)

    The contents of the private key in PEM-encoded format.

  • :certificate_chain (String)

    The contents of the certificate chain. This is typically a concatenation of the PEM-encoded public key certificates of the chain.

Returns:



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/aws/iam/server_certificate_collection.rb', line 93

def upload(options = {})
  client_opts = options.dup
  client_opts[:server_certificate_name] = client_opts.delete(:name)

  if path = client_opts[:path]
    client_opts[:path] = "/#{path}/".
      sub(%r{^//}, "/").
      sub(%r{//$}, "/")
  end

  resp = client.upload_server_certificate(client_opts)
  ServerCertificate.new(resp..
                        server_certificate_name,
                        :config => config)
end