mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[AWS|Glacier} basic vault operations
This commit is contained in:
parent
0e9996a615
commit
da187fd760
9 changed files with 285 additions and 0 deletions
|
@ -10,6 +10,14 @@ module Fog
|
|||
|
||||
request_path 'fog/aws/requests/glacier'
|
||||
|
||||
request :create_vault
|
||||
request :delete_vault
|
||||
request :delete_vault_notification_configuration
|
||||
request :describe_vault
|
||||
request :get_vault_notification_configuration
|
||||
request :list_vaults
|
||||
request :set_vault_notification_configuration
|
||||
|
||||
class Mock
|
||||
|
||||
def initialize(options={})
|
||||
|
|
34
lib/fog/aws/requests/glacier/create_vault.rb
Normal file
34
lib/fog/aws/requests/glacier/create_vault.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class Glacier
|
||||
class Real
|
||||
|
||||
# This operation creates a new vault with the specified name. .
|
||||
#
|
||||
# ==== Parameters
|
||||
# * name<~String> 1-255 characters. must be unique within a region for an AWS account
|
||||
# * options<~Hash>
|
||||
# * account_id<~String> - The AWS account id. Defaults to the account owning the credentials making the request
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/amazonglacier/latest/dev/api-vault-put.html
|
||||
#
|
||||
def create_vault(name,options={})
|
||||
account_id = options['account_id'] || '-'
|
||||
path = "/#{account_id}/vaults/#{Fog::AWS.escape(name)}"
|
||||
request(options.merge({
|
||||
:expects => 201,
|
||||
:idempotent => true,
|
||||
:headers => {},
|
||||
:method => :put,
|
||||
:path => path,
|
||||
}))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
34
lib/fog/aws/requests/glacier/delete_vault.rb
Normal file
34
lib/fog/aws/requests/glacier/delete_vault.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class Glacier
|
||||
class Real
|
||||
|
||||
# Delete a vault. Amazon Glacier will delete a vault only if there are no archives in the vault as per the last inventory
|
||||
# and there have been no writes to the vault since the last inventory
|
||||
#
|
||||
# ==== Parameters
|
||||
# * name<~String> Name of the vault to delete
|
||||
# * options<~Hash>
|
||||
# * account_id<~String> - The AWS account id. Defaults to the account owning the credentials making the request
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/amazonglacier/latest/dev/api-vault-delete.html
|
||||
#
|
||||
def delete_vault(name,options={})
|
||||
account_id = options['account_id'] || '-'
|
||||
path = "/#{account_id}/vaults/#{Fog::AWS.escape(name)}"
|
||||
request(
|
||||
:expects => 204,
|
||||
:idempotent => true,
|
||||
:headers => {},
|
||||
:method => :delete,
|
||||
:path => path,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,33 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class Glacier
|
||||
class Real
|
||||
|
||||
# Delete vault's notification configuration
|
||||
#
|
||||
# ==== Parameters
|
||||
# * name<~String> Name of the vault
|
||||
# * options<~Hash>
|
||||
# * account_id<~String> - The AWS account id. Defaults to the account owning the credentials making the request
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/amazonglacier/latest/dev/api-vault-notifications-delete.html
|
||||
#
|
||||
def delete_vault_notification_configuration(name,options={})
|
||||
account_id = options['account_id'] || '-'
|
||||
path = "/#{account_id}/vaults/#{Fog::AWS.escape(name)}/notification-configuration"
|
||||
request(
|
||||
:expects => 204,
|
||||
:idempotent => true,
|
||||
:headers => {},
|
||||
:method => :delete,
|
||||
:path => path,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
34
lib/fog/aws/requests/glacier/describe_vault.rb
Normal file
34
lib/fog/aws/requests/glacier/describe_vault.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class Glacier
|
||||
class Real
|
||||
|
||||
# This operation returns information about a vault
|
||||
#
|
||||
# ==== Parameters
|
||||
# * name<~String> Vault name
|
||||
# * options<~Hash>
|
||||
# * account_id<~String> - The AWS account id. Defaults to the account owning the credentials making the request
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/amazonglacier/latest/dev/api-vault-get.html
|
||||
#
|
||||
def describe_vault(name,options={})
|
||||
account_id = options['account_id'] || '-'
|
||||
path = "/#{account_id}/vaults/#{Fog::AWS.escape(name)}"
|
||||
request(
|
||||
:expects => 200,
|
||||
:idempotent => true,
|
||||
:headers => {},
|
||||
:method => :get,
|
||||
:path => path,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,34 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class Glacier
|
||||
class Real
|
||||
|
||||
# Get a vault's notification configuration
|
||||
#
|
||||
# ==== Parameters
|
||||
# * name<~String> Name of the vault
|
||||
# * options<~Hash>
|
||||
# * account_id<~String> - The AWS account id. Defaults to the account owning the credentials making the request
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/amazonglacier/latest/dev/api-vault-notifications-get.html
|
||||
#
|
||||
def get_vault_notification_configuration(name,options={})
|
||||
account_id = options['account_id'] || '-'
|
||||
path = "/#{account_id}/vaults/#{Fog::AWS.escape(name)}/notification-configuration"
|
||||
request(
|
||||
:expects => 200,
|
||||
:idempotent => true,
|
||||
:headers => {},
|
||||
:method => :get,
|
||||
:path => path,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
36
lib/fog/aws/requests/glacier/list_vaults.rb
Normal file
36
lib/fog/aws/requests/glacier/list_vaults.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class Glacier
|
||||
class Real
|
||||
|
||||
# This operation lists all vaults owned by the calling user’s account.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * options<~Hash>
|
||||
# * limit<~Integer> - The maximum number of items returned in the response. (default 1000)
|
||||
# * marker<~String> - marker used for pagination
|
||||
# * account_id<~String> - The AWS account id. Defaults to the account owning the credentials making the request
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/amazonglacier/latest/dev/api-vaults-get.html
|
||||
#
|
||||
def list_vaults(options={})
|
||||
account_id = options.delete('account_id') || '-'
|
||||
path = "/#{account_id}/vaults"
|
||||
request(
|
||||
:expects => 200,
|
||||
:idempotent => true,
|
||||
:headers => {},
|
||||
:method => 'GET',
|
||||
:path => path,
|
||||
:query => options
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,37 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class Glacier
|
||||
class Real
|
||||
|
||||
# Set a vault's notification configuration
|
||||
#
|
||||
# ==== Parameters
|
||||
# * name<~String> Name of the vault
|
||||
# * SnsTopic<~String> ARN of the topic to notify
|
||||
# * events<~Array> Events you wish to receive. Valid events are ArchiveRetrievalCompleted, InventoryRetrievalCompleted
|
||||
# * options<~Hash>
|
||||
# * account_id<~String> - The AWS account id. Defaults to the account owning the credentials making the request
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/amazonglacier/latest/dev/api-vault-notifications-put.html
|
||||
#
|
||||
def set_vault_notification_configuration(name,sns_topic, events, options={})
|
||||
account_id = options['account_id'] || '-'
|
||||
path = "/#{account_id}/vaults/#{Fog::AWS.escape(name)}/notification-configuration"
|
||||
request(
|
||||
:expects => 204,
|
||||
:idempotent => true,
|
||||
:headers => {},
|
||||
:method => :put,
|
||||
:path => path,
|
||||
:body => Fog::JSON.encode('SNSTopic' => sns_topic, 'Events' => events)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
35
tests/aws/requests/glacier/vault_tests.rb
Normal file
35
tests/aws/requests/glacier/vault_tests.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
Shindo.tests('AWS::Glacier | glacier vault requests', ['aws']) do
|
||||
pending if Fog.mocking?
|
||||
|
||||
topic_arn = Fog::AWS[:sns].create_topic( 'fog_test_glacier_topic').body['TopicArn']
|
||||
Fog::AWS[:glacier].create_vault('Fog-Test-Vault')
|
||||
|
||||
tests('list_vaults') do
|
||||
returns(true){Fog::AWS[:glacier].list_vaults.body['VaultList'].collect {|data| data['VaultName']}.include?('Fog-Test-Vault')}
|
||||
end
|
||||
|
||||
tests('describe_vault') do
|
||||
returns('Fog-Test-Vault'){Fog::AWS[:glacier].describe_vault('Fog-Test-Vault').body['VaultName']}
|
||||
end
|
||||
|
||||
tests('set_vault_notification_configuration') do
|
||||
Fog::AWS[:glacier].set_vault_notification_configuration 'Fog-Test-Vault', topic_arn, ['ArchiveRetrievalCompleted']
|
||||
end
|
||||
|
||||
tests('get_vault_notification_configuration') do
|
||||
returns('SNSTopic' => topic_arn, 'Events' => ['ArchiveRetrievalCompleted']){ Fog::AWS[:glacier].get_vault_notification_configuration( 'Fog-Test-Vault').body}
|
||||
end
|
||||
|
||||
tests('delete_vault_notification_configuration') do
|
||||
Fog::AWS[:glacier].delete_vault_notification_configuration( 'Fog-Test-Vault')
|
||||
raises(Excon::Errors::NotFound){Fog::AWS[:glacier].get_vault_notification_configuration( 'Fog-Test-Vault')}
|
||||
end
|
||||
|
||||
tests('delete_vault') do
|
||||
Fog::AWS[:glacier].delete_vault( 'Fog-Test-Vault')
|
||||
raises(Excon::Errors::NotFound){Fog::AWS[:glacier].describe_vault( 'Fog-Test-Vault')}
|
||||
end
|
||||
|
||||
Fog::AWS[:sns].delete_topic topic_arn
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue