aws-sdk-glacier 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,179 @@
1
+ # WARNING ABOUT GENERATED CODE
2
+ #
3
+ # This file is generated. See the contributing for info on making contributions:
4
+ # https://github.com/aws/aws-sdk-ruby/blob/master/CONTRIBUTING.md
5
+ #
6
+ # WARNING ABOUT GENERATED CODE
7
+
8
+ module Aws
9
+ module Glacier
10
+ class Notification
11
+
12
+ extend Aws::Deprecations
13
+
14
+ # @overload def initialize(account_id, vault_name, options = {})
15
+ # @param [String] account_id
16
+ # @param [String] vault_name
17
+ # @option options [Client] :client
18
+ # @overload def initialize(options = {})
19
+ # @option options [required, String] :account_id
20
+ # @option options [required, String] :vault_name
21
+ # @option options [Client] :client
22
+ def initialize(*args)
23
+ options = Hash === args.last ? args.pop.dup : {}
24
+ @account_id = extract_account_id(args, options)
25
+ @vault_name = extract_vault_name(args, options)
26
+ @data = options.delete(:data)
27
+ @client = options.delete(:client) || Client.new(options)
28
+ end
29
+
30
+ # @!group Read-Only Attributes
31
+
32
+ # @return [String]
33
+ def account_id
34
+ @account_id
35
+ end
36
+
37
+ # @return [String]
38
+ def vault_name
39
+ @vault_name
40
+ end
41
+
42
+ # The Amazon Simple Notification Service (Amazon SNS) topic Amazon
43
+ # Resource Name (ARN).
44
+ # @return [String]
45
+ def sns_topic
46
+ data.sns_topic
47
+ end
48
+
49
+ # A list of one or more events for which Amazon Glacier will send a
50
+ # notification to the specified Amazon SNS topic.
51
+ # @return [Array<String>]
52
+ def events
53
+ data.events
54
+ end
55
+
56
+ # @!endgroup
57
+
58
+ # @return [Client]
59
+ def client
60
+ @client
61
+ end
62
+
63
+ # Loads, or reloads {#data} for the current {Notification}.
64
+ # Returns `self` making it possible to chain methods.
65
+ #
66
+ # notification.reload.data
67
+ #
68
+ # @return [self]
69
+ def load
70
+ resp = @client.get_vault_notifications(
71
+ account_id: @account_id,
72
+ vault_name: @vault_name
73
+ )
74
+ @data = resp.vaultnotificationconfig
75
+ self
76
+ end
77
+ alias :reload :load
78
+
79
+ # @return [Types::VaultNotificationConfig]
80
+ # Returns the data for this {Notification}. Calls
81
+ # {Client#get_vault_notifications} if {#data_loaded?} is `false`.
82
+ def data
83
+ load unless @data
84
+ @data
85
+ end
86
+
87
+ # @return [Boolean]
88
+ # Returns `true` if this resource is loaded. Accessing attributes or
89
+ # {#data} on an unloaded resource will trigger a call to {#load}.
90
+ def data_loaded?
91
+ !!@data
92
+ end
93
+
94
+ # @!group Actions
95
+
96
+ # @example Request syntax with placeholder values
97
+ #
98
+ # notification.delete()
99
+ # @param [Hash] options ({})
100
+ # @return [EmptyStructure]
101
+ def delete(options = {})
102
+ options = options.merge(
103
+ account_id: @account_id,
104
+ vault_name: @vault_name
105
+ )
106
+ resp = @client.delete_vault_notifications(options)
107
+ resp.data
108
+ end
109
+
110
+ # @example Request syntax with placeholder values
111
+ #
112
+ # notification.set({
113
+ # vault_notification_config: {
114
+ # sns_topic: "string",
115
+ # events: ["string"],
116
+ # },
117
+ # })
118
+ # @param [Hash] options ({})
119
+ # @option options [Types::VaultNotificationConfig] :vault_notification_config
120
+ # Provides options for specifying notification configuration.
121
+ # @return [EmptyStructure]
122
+ def set(options = {})
123
+ options = options.merge(
124
+ account_id: @account_id,
125
+ vault_name: @vault_name
126
+ )
127
+ resp = @client.set_vault_notifications(options)
128
+ resp.data
129
+ end
130
+
131
+ # @!group Associations
132
+
133
+ # @return [Vault]
134
+ def vault
135
+ Vault.new(
136
+ account_id: @account_id,
137
+ name: @vault_name,
138
+ client: @client
139
+ )
140
+ end
141
+
142
+ # @deprecated
143
+ # @api private
144
+ def identifiers
145
+ {
146
+ account_id: @account_id,
147
+ vault_name: @vault_name
148
+ }
149
+ end
150
+ deprecated(:identifiers)
151
+
152
+ private
153
+
154
+ def extract_account_id(args, options)
155
+ value = args[0] || options.delete(:account_id)
156
+ case value
157
+ when String then value
158
+ when nil then raise ArgumentError, "missing required option :account_id"
159
+ else
160
+ msg = "expected :account_id to be a String, got #{value.class}"
161
+ raise ArgumentError, msg
162
+ end
163
+ end
164
+
165
+ def extract_vault_name(args, options)
166
+ value = args[1] || options.delete(:vault_name)
167
+ case value
168
+ when String then value
169
+ when nil then raise ArgumentError, "missing required option :vault_name"
170
+ else
171
+ msg = "expected :vault_name to be a String, got #{value.class}"
172
+ raise ArgumentError, msg
173
+ end
174
+ end
175
+
176
+ class Collection < Aws::Resources::Collection; end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,22 @@
1
+ module Aws
2
+ module Glacier
3
+ module Plugins
4
+ class AccountId < Seahorse::Client::Plugin
5
+
6
+ option(:account_id,
7
+ default: '-',
8
+ doc_type: String,
9
+ docstring: <<-DOCS)
10
+ The default Glacier AWS account ID to use for all glacier
11
+ operations. The default value of `-` uses the account
12
+ your `:credentials` belong to.
13
+ DOCS
14
+
15
+ handle_request(step: :initialize) do |context|
16
+ context.params[:account_id] ||= context.config.account_id
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Aws
2
+ module Glacier
3
+ module Plugins
4
+ # @api private
5
+ class ApiVersion < Seahorse::Client::Plugin
6
+
7
+ class Handler < Seahorse::Client::Handler
8
+
9
+ def call(context)
10
+ version = context.config.api.version
11
+ context.http_request.headers['x-amz-glacier-version'] = version
12
+ @handler.call(context)
13
+ end
14
+
15
+ end
16
+
17
+ handler(Handler)
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,91 @@
1
+ require_relative '../tree_hash'
2
+ require 'openssl'
3
+
4
+ module Aws
5
+ module Glacier
6
+ module Plugins
7
+ # Computes the `:checksum` of the HTTP request body for operations
8
+ # that require the `X-Amz-Sha256-Tree-Hash` header. This includes:
9
+ #
10
+ # * `:complete_multipart_upload`
11
+ # * `:upload_archive`
12
+ # * `:upload_multipart_part`
13
+ #
14
+ # The `:upload_archive` and `:upload_multipart_part` operations
15
+ # accept a `:checksum` request parameter. If this param
16
+ # is present, then the checksum is assumed to be the proper
17
+ # tree hash of the file to be uploaded. If this param is
18
+ # not present, then the required tree hash checksum will
19
+ # be generated.
20
+ #
21
+ # The `:complete_multipart_upload` operation does not accept
22
+ # a checksum and this plugin will always compute this of the
23
+ # HTTP request body on your behalf.
24
+ #
25
+ # @api private
26
+ class Checksums < Seahorse::Client::Plugin
27
+
28
+ CHECKSUM_OPERATIONS = [
29
+ :upload_archive,
30
+ :upload_multipart_part,
31
+ ]
32
+
33
+ class Handler < Seahorse::Client::Handler
34
+
35
+ HASH = 'X-Amz-Content-Sha256'
36
+
37
+ TREE_HASH = 'X-Amz-Sha256-Tree-Hash'
38
+
39
+ def call(context)
40
+ unless context.http_request.headers[TREE_HASH]
41
+ populate_checksum_headers(context)
42
+ end
43
+ @handler.call(context)
44
+ end
45
+
46
+ private
47
+
48
+ def populate_checksum_headers(context)
49
+ compute_checksums(context.http_request.body) do |hash, tree_hash|
50
+ context.http_request.headers[HASH] = hash
51
+ context.http_request.headers[TREE_HASH] = tree_hash.digest
52
+ context[:tree_hash] = tree_hash
53
+ end
54
+ end
55
+
56
+ # Computes two checksums of the body. The tree hash is required
57
+ # by Glacier for operations where you upload a file. The other
58
+ # checksum is required by signature version 4. We compute both
59
+ # here so the sigv4 signer does not need to re-read the body.
60
+ def compute_checksums(body, &block)
61
+
62
+ tree_hash = TreeHash.new
63
+ digest = OpenSSL::Digest.new('sha256')
64
+
65
+ # if the body is empty/EOF, then we should compute the
66
+ # digests of the empty string
67
+ if body.size == 0
68
+ tree_hash.update('')
69
+ digest.update('')
70
+ end
71
+
72
+ # Rewind body before performing checksum computation.
73
+ body.rewind
74
+
75
+ while chunk = body.read(1024 * 1024) # read 1MB
76
+ tree_hash.update(chunk)
77
+ digest.update(chunk)
78
+ end
79
+ body.rewind
80
+
81
+ yield(digest.to_s, tree_hash)
82
+
83
+ end
84
+ end
85
+
86
+ handler(Handler, operations: CHECKSUM_OPERATIONS)
87
+
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,82 @@
1
+ # WARNING ABOUT GENERATED CODE
2
+ #
3
+ # This file is generated. See the contributing for info on making contributions:
4
+ # https://github.com/aws/aws-sdk-ruby/blob/master/CONTRIBUTING.md
5
+ #
6
+ # WARNING ABOUT GENERATED CODE
7
+
8
+ module Aws
9
+ module Glacier
10
+ class Resource
11
+
12
+ # @param options ({})
13
+ # @option options [Client] :client
14
+ def initialize(options = {})
15
+ @client = options[:client] || Client.new(options)
16
+ end
17
+
18
+ # @return [Client]
19
+ def client
20
+ @client
21
+ end
22
+
23
+ # @!group Actions
24
+
25
+ # @example Request syntax with placeholder values
26
+ #
27
+ # vault = glacier.create_vault({
28
+ # vault_name: "string", # required
29
+ # })
30
+ # @param [Hash] options ({})
31
+ # @option options [required, String] :vault_name
32
+ # The name of the vault.
33
+ # @return [Vault]
34
+ def create_vault(options = {})
35
+ options = options.merge(account_id: "-")
36
+ resp = @client.create_vault(options)
37
+ Vault.new(
38
+ account_id: options[:account_id],
39
+ name: options[:vault_name],
40
+ client: @client
41
+ )
42
+ end
43
+
44
+ # @!group Associations
45
+
46
+ # @param [String] id
47
+ # @return [Account]
48
+ def account(id)
49
+ Account.new(
50
+ id: id,
51
+ client: @client
52
+ )
53
+ end
54
+
55
+ # @example Request syntax with placeholder values
56
+ #
57
+ # vaults = glacier.vaults()
58
+ # @param [Hash] options ({})
59
+ # @return [Vault::Collection]
60
+ def vaults(options = {})
61
+ batches = Enumerator.new do |y|
62
+ options = options.merge(account_id: "-")
63
+ resp = @client.list_vaults(options)
64
+ resp.each_page do |page|
65
+ batch = []
66
+ page.data.vault_list.each do |v|
67
+ batch << Vault.new(
68
+ account_id: options[:account_id],
69
+ name: v.vault_name,
70
+ data: v,
71
+ client: @client
72
+ )
73
+ end
74
+ y.yield(batch)
75
+ end
76
+ end
77
+ Vault::Collection.new(batches)
78
+ end
79
+
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,76 @@
1
+ require 'openssl'
2
+
3
+ module Aws
4
+ module Glacier
5
+ # Used for computing a tree hash SHA256 checksum of an object.
6
+ #
7
+ # tree_hash = TreeHash.new
8
+ # tree_hash.update(file.read(1024 * 1024)) until file.eof?
9
+ # tree_hash.digest
10
+ #
11
+ # == Limitations and Notes
12
+ #
13
+ # There are two main limitations to be aware of when using TreeHash:
14
+ #
15
+ # * TreeHash is not thread safe. Use multiple TreeHash objects to concurrently
16
+ # compute a tree hash of a large object. Join their hashes at the end into
17
+ # a single TreeHash and then call {#digest}
18
+ #
19
+ # TreeHash.new(tree_hashes.map(&:hashes).flatten)
20
+ #
21
+ # * You must call {#update} with 1MB chunks of data. Only the final
22
+ # chunk may be smaller than 1MB.
23
+ #
24
+ # If you have a large object/file, and you would like to compute the
25
+ # chunks concurrently, you must break the original file/data into sections
26
+ # that are evenly divisible by 1MB. Each section of data requires
27
+ # a seperate TreeHash object to compute hashes. Once all sections of
28
+ # data are complete, you can rejoin their {#hashes} in sequential order
29
+ # into a single TreeHash, then call {#digest} on the final tree hash.
30
+ #
31
+ class TreeHash
32
+
33
+ def initialize(hashes = [])
34
+ @digest = OpenSSL::Digest.new('sha256')
35
+ @hashes = hashes
36
+ end
37
+
38
+ # @return [Array<String>] The built up list of hashes. Each hash is
39
+ # a sha255 digest of a 1MB chunk.
40
+ attr_accessor :hashes
41
+
42
+ # @param [String] chunk
43
+ # @return [String] Returns the computed SHA256 digest of the chunk.
44
+ def update(chunk)
45
+ @hashes << @digest.update(chunk).digest
46
+ @digest.reset
47
+ @hashes.last
48
+ end
49
+
50
+ def digest
51
+ hashes = @hashes
52
+ digest = OpenSSL::Digest.new('sha256')
53
+ until hashes.count == 1
54
+ hashes = hashes.each_slice(2).map do |h1,h2|
55
+ digest.reset
56
+ if h2
57
+ digest.update(h1)
58
+ digest.update(h2)
59
+ digest.digest
60
+ else
61
+ h1
62
+ end
63
+ end
64
+ end
65
+ hashes.first.bytes.map{|x| x.to_i.to_s(16).rjust(2, '0')}.join('')
66
+ end
67
+
68
+ end
69
+ end
70
+
71
+ # For backwards compatability, we are aliasing Aws::Glacier::TreeHash to
72
+ # Aws::TreeHash. It is no longer vendors in the aws-sdk-core gem, but
73
+ # users should still be able to use the old constant.
74
+ # @api private
75
+ TreeHash = Glacier::TreeHash
76
+ end