mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[AWS|Glacier] Bare glacier service
This commit is contained in:
parent
e008b358dc
commit
0e9996a615
3 changed files with 94 additions and 0 deletions
|
@ -17,6 +17,7 @@ module Fog
|
||||||
service(:elasticache, 'aws/elasticache', 'Elasticache')
|
service(:elasticache, 'aws/elasticache', 'Elasticache')
|
||||||
service(:elb, 'aws/elb', 'ELB')
|
service(:elb, 'aws/elb', 'ELB')
|
||||||
service(:emr, 'aws/emr', 'EMR')
|
service(:emr, 'aws/emr', 'EMR')
|
||||||
|
service(:glacier, 'aws/glacier', 'Glacier')
|
||||||
service(:iam, 'aws/iam', 'IAM')
|
service(:iam, 'aws/iam', 'IAM')
|
||||||
service(:rds, 'aws/rds', 'RDS')
|
service(:rds, 'aws/rds', 'RDS')
|
||||||
service(:ses, 'aws/ses', 'SES')
|
service(:ses, 'aws/ses', 'SES')
|
||||||
|
|
91
lib/fog/aws/glacier.rb
Normal file
91
lib/fog/aws/glacier.rb
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
require 'fog/aws'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module AWS
|
||||||
|
class Glacier < Fog::Service
|
||||||
|
extend Fog::AWS::CredentialFetcher::ServiceMethods
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
request_path 'fog/aws/requests/glacier'
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
|
||||||
|
def initialize(options={})
|
||||||
|
Fog::Mock.not_implemented
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Real
|
||||||
|
include Fog::AWS::CredentialFetcher::ConnectionMethods
|
||||||
|
# Initialize connection to Glacier
|
||||||
|
#
|
||||||
|
# ==== Notes
|
||||||
|
# options parameter must include values for :aws_access_key_id and
|
||||||
|
# :aws_secret_access_key in order to create a connection
|
||||||
|
#
|
||||||
|
# ==== Examples
|
||||||
|
# ses = SES.new(
|
||||||
|
# :aws_access_key_id => your_aws_access_key_id,
|
||||||
|
# :aws_secret_access_key => your_aws_secret_access_key
|
||||||
|
# )
|
||||||
|
#
|
||||||
|
# ==== Parameters
|
||||||
|
# * options<~Hash> - config arguments for connection. Defaults to {}.
|
||||||
|
# * region<~String> - optional region to use. For instance, 'us-east-1' and etc.
|
||||||
|
#
|
||||||
|
# ==== Returns
|
||||||
|
# * Glacier object with connection to AWS.
|
||||||
|
def initialize(options={})
|
||||||
|
|
||||||
|
@use_iam_profile = options[:use_iam_profile]
|
||||||
|
@region = options[:region] || 'us-east-1'
|
||||||
|
|
||||||
|
setup_credentials(options)
|
||||||
|
|
||||||
|
@connection_options = options[:connection_options] || {}
|
||||||
|
@host = options[:host] || "glacier.#{@region}.amazonaws.com"
|
||||||
|
@version = '2012-06-01'
|
||||||
|
@path = options[:path] || '/'
|
||||||
|
@persistent = options[:persistent] || false
|
||||||
|
@port = options[:port] || 443
|
||||||
|
@scheme = options[:scheme] || 'https'
|
||||||
|
|
||||||
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_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,'glacier')
|
||||||
|
end
|
||||||
|
|
||||||
|
def request(params, &block)
|
||||||
|
refresh_credentials_if_expired
|
||||||
|
|
||||||
|
date = Fog::Time.now
|
||||||
|
params[:headers]['Date'] = date.to_date_header
|
||||||
|
params[:headers]['x-amz-date'] = date.to_iso8601_basic
|
||||||
|
|
||||||
|
params[:headers]['Host'] = @host
|
||||||
|
params[:headers]['x-amz-glacier-version'] = @version
|
||||||
|
params[:headers]['x-amz-security-token'] = @aws_session_token if @aws_session_token
|
||||||
|
params[:headers]['Authorization'] = @signer.sign params, date
|
||||||
|
|
||||||
|
response = @connection.request(params, &block)
|
||||||
|
if response.headers['Content-Type'] == 'application/json'
|
||||||
|
response.body = Fog::JSON.decode(response.body)
|
||||||
|
end
|
||||||
|
response
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -25,6 +25,8 @@ class AWS < Fog::Bin
|
||||||
Fog::AWS::ELB
|
Fog::AWS::ELB
|
||||||
when :emr
|
when :emr
|
||||||
Fog::AWS::EMR
|
Fog::AWS::EMR
|
||||||
|
when :glacier
|
||||||
|
Fog::AWS::Glacier
|
||||||
when :iam
|
when :iam
|
||||||
Fog::AWS::IAM
|
Fog::AWS::IAM
|
||||||
when :sdb, :simpledb
|
when :sdb, :simpledb
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue