File: server_certificate.rb

package info (click to toggle)
ruby-aws-sdk 1.52.0-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,164 kB
  • ctags: 4,821
  • sloc: ruby: 28,085; makefile: 7
file content (148 lines) | stat: -rw-r--r-- 4,826 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Copyright 2011-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
#     http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

module AWS
  class IAM

    # Respresents a server certificate.
    #
    #     certificate = iam.server_certificates["MyCert"]
    #
    # You can use this class to get information about a certificate
    # and to delete it.
    #
    # @attr [String] name The name that identifies the server certificate.
    #
    # @attr_reader [String] id The stable and unique string identifying
    #   the server certificate.
    #
    # @attr_reader [Time] updload_date The date when the server certificate was
    #   uploaded.
    #
    # @attr_reader [String] arn The Amazon Resource Name (ARN)
    #   specifying the server certificate. For more information
    #   about ARNs and how to use them in policies, see
    #   {http://docs.amazonwebservices.com/IAM/latest/UserGuide/index.html?Using_Identifiers.html
    #   Identifiers for IAM Entities} in <i>Using AWS Identity and
    #   Access Management</i>.
    #
    # @attr [String] path Path to the server certificate.
    #
    # @attr_reader [String] certificate_body The contents of the public key
    #   certificate.
    #
    # @attr_reader [String] certificate_chain The contents of the public key
    #   certificate chain.
    #
    class ServerCertificate < Resource

      prefix_update_attributes

      # @api private
      def initialize(name, opts={})
        opts[:name] = name
        super(opts)
      end

      mutable_attribute :name, :static => true, :from => :server_certificate_name

      attribute :id, :static => true, :from => :server_certificate_id

      attribute :upload_date, :static => true

      attribute :arn

      mutable_attribute :path do
        translates_input do |path|
          path = "/#{path}" unless path[0] == ?/
          path = "#{path}/" unless path[-1] == ?/
          path
        end
      end

      attribute :certificate_body

      attribute :certificate_chain

      provider(:get_server_certificate) do |provider|
        # for metadata attributes
        provider.find do |resp|
          cert, meta = response_objects(resp)
          meta
        end
        provider.provides :name, :id, :upload_date, :arn, :path
      end

      provider(:get_server_certificate) do |provider|
        # for data attributes
        provider.find do |resp|
          cert, meta = response_objects(resp)
          cert
        end
        provider.provides :certificate_body, :certificate_chain
      end

      populates_from(:upload_server_certificate) do |resp|
        resp.server_certificate_metadata if
          resp.server_certificate_metadata.server_certificate_name == name
      end

      populates_from(:list_server_certificates) do |resp|
        resp.server_certificate_metadata_list.find do |sc|
          sc.server_certificate_name == name
        end
      end

      # Deletes the specified server certificate.
      #
      # @note If you are using a server certificate with Elastic Load
      #   Balancing, deleting the certificate could have implications
      #   for your application. If Elastic Load Balancing doesn't
      #   detect the deletion of bound certificates, it may continue
      #   to use the certificates. This could cause Elastic Load
      #   Balancing to stop accepting traffic. We recommend that you
      #   remove the reference to the certificate from Elastic Load
      #   Balancing before using this command to delete the
      #   certificate. For more information, go to
      #   {http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/API_DeleteLoadBalancerListeners.html
      #   DeleteLoadBalancerListeners} in the _Elastic Load Balancing
      #   API Reference_.
      #
      # @return [nil]
      def delete
        client.delete_server_certificate(resource_options)
        nil
      end

      # @api private
      protected
      def resource_identifiers
        [[:server_certificate_name, name]]
      end

      # extract response objects from get_server_certificate
      private
      def response_objects(resp)
        if cert = resp.server_certificate and
            meta = cert.server_certificate_metadata and
            meta.server_certificate_name == name
          [cert, meta]
        else
          [nil, nil]
        end
      end

    end

  end
end