Class: Fog::AWS::Support::Real

Inherits:
Object
  • Object
show all
Includes:
CredentialFetcher::ConnectionMethods
Defined in:
lib/fog/aws/support.rb,
lib/fog/aws/requests/support/describe_trusted_advisor_checks.rb,
lib/fog/aws/requests/support/describe_trusted_advisor_check_result.rb

Instance Method Summary collapse

Methods included from CredentialFetcher::ConnectionMethods

#refresh_credentials_if_expired

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/fog/aws/support.rb', line 89

def initialize(options={})
  @connection_options = options[:connection_options] || {}
  @instrumentor       = options[:instrumentor]
  @instrumentor_name  = options[:instrumentor_name] || 'fog.aws.support'

  @region     = 'us-east-1'
  @host       = options[:host]       || "support.#{@region}.amazonaws.com"
  @path       = options[:path]       || "/"
  @port       = options[:port]       || 443
  @scheme     = options[:scheme]     || "https"
  @persistent = options[:persistent] || false
  @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
  @version    = options[:version]    || '2013-04-15'

  setup_credentials(options)
end

Instance Method Details

#_request(body, headers, idempotent, parser) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/fog/aws/support.rb', line 155

def _request(body, headers, idempotent, parser)
  response = @connection.request({
    :body       => body,
    :expects    => 200,
    :idempotent => idempotent,
    :headers    => headers,
    :method     => 'POST',
    :parser     => parser
  })
  response.body = Fog::JSON.decode(response.body)
  response
end

#describe_trusted_advisor_check_result(options = {}) ⇒ Object

Describe Trusted Advisor Check Result docs.aws.amazon.com/awssupport/latest/APIReference/API_DescribeTrustedAdvisorCheckResult.html

Parameters

  • checkId <~String> - Id of the check obtained from #describe_trusted_advisor_checks

  • language <~String> - Language to return. Supported values are ‘en’ and ‘jp’

Returns

  • response<~Excon::Response>:

    • body<~Hash>



13
14
15
16
17
18
19
# File 'lib/fog/aws/requests/support/describe_trusted_advisor_check_result.rb', line 13

def describe_trusted_advisor_check_result(options={})
  request(
    'Action'   => 'DescribeTrustedAdvisorCheckResult',
    'checkId'  => options[:id],
    'language' => options[:language] || 'en'
  )
end

#describe_trusted_advisor_checks(options = {}) ⇒ Object

Describe Trusted Advisor Checks docs.aws.amazon.com/awssupport/latest/APIReference/API_DescribeTrustedAdvisorChecks.html

Parameters

  • language <~String> - Language to return. Supported values are ‘en’ and ‘jp’

Returns

  • response<~Excon::Response>:

    • body<~Hash>



12
13
14
15
16
17
# File 'lib/fog/aws/requests/support/describe_trusted_advisor_checks.rb', line 12

def describe_trusted_advisor_checks(options={})
  request(
    'Action'   => 'DescribeTrustedAdvisorChecks',
    'language' => options[:language] || 'en'
  )
end

#reloadObject



106
107
108
# File 'lib/fog/aws/support.rb', line 106

def reload
  @connection.reset
end

#request(params) ⇒ Object



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
149
150
151
152
153
# File 'lib/fog/aws/support.rb', line 121

def request(params)
  refresh_credentials_if_expired
  idempotent   = params.delete(:idempotent)
  parser       = params.delete(:parser)
  action       = params.delete('Action')
  request_body = Fog::JSON.encode(params)

  body, headers = Fog::AWS.signed_params_v4(
    params,
    {
      'Content-Type' => "application/x-amz-json-1.1",
      "X-Amz-Target" => "AWSSupport_#{@version.gsub("-", "")}.#{action}"
    },
    {
      :host               => @host,
      :path               => @path,
      :port               => @port,
      :version            => @version,
      :signer             => @signer,
      :aws_session_token  => @aws_session_token,
      :method             => 'POST',
      :body               => request_body
    }
  )

  if @instrumentor
    @instrumentor.instrument("#{@instrumentor_name}.request", params) do
      _request(body, headers, idempotent, parser)
    end
  else
    _request(body, headers, idempotent, parser)
  end
end

#setup_credentials(options) ⇒ Object



110
111
112
113
114
115
116
117
118
119
# File 'lib/fog/aws/support.rb', line 110

def setup_credentials(options)
  @aws_access_key_id         = options[:aws_access_key_id]
  @aws_secret_access_key     = options[:aws_secret_access_key]
  @aws_session_token         = options[:aws_session_token]
  @aws_credentials_expire_at = options[:aws_credentials_expire_at]

  #global services that have no region are signed with the us-east-1 region
  #the only exception is GovCloud, which requires the region to be explicitly specified as us-gov-west-1
  @signer = Fog::AWS::SignatureV4.new(@aws_access_key_id, @aws_secret_access_key, @region, 'support')
end