mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|iam] Add instrumentation support.
This commit is contained in:
parent
542bfc4dea
commit
154f520ac2
1 changed files with 34 additions and 28 deletions
|
@ -11,7 +11,7 @@ module Fog
|
||||||
class ValidationError < Fog::AWS::IAM::Error; end
|
class ValidationError < Fog::AWS::IAM::Error; end
|
||||||
|
|
||||||
requires :aws_access_key_id, :aws_secret_access_key
|
requires :aws_access_key_id, :aws_secret_access_key
|
||||||
recognizes :host, :path, :port, :scheme, :persistent
|
recognizes :host, :path, :port, :scheme, :persistent, :instrumentor, :instrumentor_name
|
||||||
|
|
||||||
request_path 'fog/aws/requests/iam'
|
request_path 'fog/aws/requests/iam'
|
||||||
request :add_user_to_group
|
request :add_user_to_group
|
||||||
|
@ -70,15 +70,15 @@ module Fog
|
||||||
request :update_user
|
request :update_user
|
||||||
request :upload_server_certificate
|
request :upload_server_certificate
|
||||||
request :upload_signing_certificate
|
request :upload_signing_certificate
|
||||||
|
|
||||||
model_path 'fog/aws/models/iam'
|
model_path 'fog/aws/models/iam'
|
||||||
model :user
|
model :user
|
||||||
collection :users
|
collection :users
|
||||||
model :policy
|
model :policy
|
||||||
collection :policies
|
collection :policies
|
||||||
model :access_key
|
model :access_key
|
||||||
collection :access_keys
|
collection :access_keys
|
||||||
|
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
def self.data
|
def self.data
|
||||||
|
@ -151,6 +151,8 @@ module Fog
|
||||||
@aws_access_key_id = options[:aws_access_key_id]
|
@aws_access_key_id = options[:aws_access_key_id]
|
||||||
@aws_secret_access_key = options[:aws_secret_access_key]
|
@aws_secret_access_key = options[:aws_secret_access_key]
|
||||||
@connection_options = options[:connection_options] || {}
|
@connection_options = options[:connection_options] || {}
|
||||||
|
@instrumentor = options[:instrumentor]
|
||||||
|
@instrumentor_name = options[:instrumentor_name] || 'fog.aws.iam'
|
||||||
@hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
|
@hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
|
||||||
@host = options[:host] || 'iam.amazonaws.com'
|
@host = options[:host] || 'iam.amazonaws.com'
|
||||||
@path = options[:path] || '/'
|
@path = options[:path] || '/'
|
||||||
|
@ -182,35 +184,39 @@ module Fog
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
begin
|
if @instrumentor
|
||||||
response = @connection.request({
|
@instrumentor.instrument("#{@instrumentor_name}.request", params) do
|
||||||
:body => body,
|
_request(body, idempotent, parser)
|
||||||
:expects => 200,
|
end
|
||||||
:idempotent => idempotent,
|
else
|
||||||
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
_request(body, idempotent, parser)
|
||||||
:host => @host,
|
end
|
||||||
:method => 'POST',
|
end
|
||||||
:parser => parser
|
|
||||||
})
|
|
||||||
|
|
||||||
response
|
def _request(body, idempotent, parser)
|
||||||
rescue Excon::Errors::HTTPStatusError => error
|
@connection.request({
|
||||||
if match = error.message.match(/<Code>(.*)<\/Code>(?:.*<Message>(.*)<\/Message>)?/m)
|
:body => body,
|
||||||
case match[1]
|
:expects => 200,
|
||||||
when 'CertificateNotFound', 'NoSuchEntity'
|
:idempotent => idempotent,
|
||||||
raise Fog::AWS::IAM::NotFound.slurp(error, match[2])
|
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||||
when 'EntityAlreadyExists', 'KeyPairMismatch', 'LimitExceeded', 'MalformedCertificate', 'ValidationError'
|
:host => @host,
|
||||||
raise Fog::AWS::IAM.const_get(match[1]).slurp(error, match[2])
|
:method => 'POST',
|
||||||
else
|
:parser => parser
|
||||||
raise Fog::AWS::IAM::Error.slurp(error, "#{match[1]} => #{match[2]}") if match[1]
|
})
|
||||||
raise
|
rescue Excon::Errors::HTTPStatusError => error
|
||||||
end
|
if match = error.message.match(/<Code>(.*)<\/Code>(?:.*<Message>(.*)<\/Message>)?/m)
|
||||||
|
case match[1]
|
||||||
|
when 'CertificateNotFound', 'NoSuchEntity'
|
||||||
|
raise Fog::AWS::IAM::NotFound.slurp(error, match[2])
|
||||||
|
when 'EntityAlreadyExists', 'KeyPairMismatch', 'LimitExceeded', 'MalformedCertificate', 'ValidationError'
|
||||||
|
raise Fog::AWS::IAM.const_get(match[1]).slurp(error, match[2])
|
||||||
else
|
else
|
||||||
|
raise Fog::AWS::IAM::Error.slurp(error, "#{match[1]} => #{match[2]}") if match[1]
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
raise
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue