mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
122 lines
4.8 KiB
Ruby
122 lines
4.8 KiB
Ruby
module Fog
|
|
module AWS
|
|
class Kinesis < Fog::Service
|
|
extend Fog::AWS::CredentialFetcher::ServiceMethods
|
|
|
|
class LimitExceeded < Fog::Errors::Error; end
|
|
class ResourceNotFound < Fog::Errors::Error; end
|
|
class ExpiredIterator < Fog::Errors::Error; end
|
|
class InvalidArgument < Fog::Errors::Error; end
|
|
class ProvisionedThroughputExceeded < Fog::Errors::Error; end
|
|
|
|
requires :aws_access_key_id, :aws_secret_access_key
|
|
recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at, :instrumentor, :instrumentor_name
|
|
|
|
request_path 'fog/aws/requests/kinesis'
|
|
|
|
request :list_streams
|
|
request :describe_stream
|
|
request :create_stream
|
|
request :delete_stream
|
|
request :get_shard_iterator
|
|
request :put_records
|
|
request :get_records
|
|
|
|
class Real
|
|
include Fog::AWS::CredentialFetcher::ConnectionMethods
|
|
|
|
def initialize(options={})
|
|
@use_iam_profile = options[:use_iam_profile]
|
|
|
|
@connection_options = options[:connection_options] || {}
|
|
|
|
@instrumentor = options[:instrumentor]
|
|
@instrumentor_name = options[:instrumentor_name] || 'fog.aws.kinesis'
|
|
|
|
options[:region] ||= 'us-east-1'
|
|
@region = options[:region]
|
|
@host = options[:host] || "kinesis.#{options[:region]}.amazonaws.com"
|
|
@path = options[:path] || '/'
|
|
@persistent = options[:persistent] || false
|
|
@port = options[:port] || 443
|
|
@scheme = options[:scheme] || 'https'
|
|
@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
|
|
|
|
setup_credentials(options)
|
|
end
|
|
|
|
private
|
|
|
|
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]
|
|
|
|
@signer = Fog::AWS::SignatureV4.new( @aws_access_key_id, @aws_secret_access_key, @region, 'kinesis')
|
|
end
|
|
|
|
def request(params)
|
|
refresh_credentials_if_expired
|
|
idempotent = params.delete(:idempotent)
|
|
parser = params.delete(:parser)
|
|
|
|
date = Fog::Time.now
|
|
headers = {
|
|
'X-Amz-Target' => params['X-Amz-Target'],
|
|
'Content-Type' => 'application/x-amz-json-1.1',
|
|
'Host' => @host,
|
|
'x-amz-date' => date.to_iso8601_basic
|
|
}
|
|
headers['x-amz-security-token'] = @aws_session_token if @aws_session_token
|
|
body = MultiJson.dump(params[:body])
|
|
headers['Authorization'] = @signer.sign({method: "POST", headers: headers, body: body, query: {}, path: @path}, date)
|
|
|
|
if @instrumentor
|
|
@instrumentor.instrument("#{@instrumentor_name}.request", params) do
|
|
_request(body, headers, idempotent, parser)
|
|
end
|
|
else
|
|
_request(body, headers, idempotent, parser)
|
|
end
|
|
end
|
|
|
|
def _request(body, headers, idempotent, parser)
|
|
@connection.request({
|
|
:body => body,
|
|
:expects => 200,
|
|
:headers => headers,
|
|
:idempotent => idempotent,
|
|
:method => 'POST',
|
|
:parser => parser
|
|
})
|
|
rescue Excon::Errors::HTTPStatusError => error
|
|
match = Fog::AWS::Errors.match_error(error)
|
|
raise if match.empty?
|
|
raise case match[:code]
|
|
when 'LimitExceededException'
|
|
Fog::AWS::Kinesis::LimitExceeded.slurp(error, match[:message])
|
|
when 'ResourceNotFoundException'
|
|
Fog::AWS::Kinesis::ResourceNotFound.slurp(error, match[:message])
|
|
when 'ExpiredIteratorException'
|
|
Fog::AWS::Kinesis::ExpiredIterator.slurp(error, match[:message])
|
|
when 'InvalidArgumentException'
|
|
Fog::AWS::Kinesis::InvalidArgument.slurp(error, match[:message])
|
|
when 'ProvisionedThroughputExceededException'
|
|
Fog::AWS::Kinesis::ProvisionedThroughputExceeded.slurp(error, match[:message])
|
|
else
|
|
Fog::AWS::Kinesis::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
class Mock
|
|
def initialize(options={})
|
|
raise Fog::Mock::NotImplementedError
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|