Skip to content

Commit

Permalink
Merge pull request #53 from yaxia/dev
Browse files Browse the repository at this point in the history
Changes for v0.11.1-preview
  • Loading branch information
vinjiang authored Sep 30, 2016
2 parents bf84124 + c8ecbf7 commit 61c7227
Show file tree
Hide file tree
Showing 21 changed files with 974 additions and 530 deletions.
10 changes: 10 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2016.09 - version 0.11.1-preview

ALL
* Added the support for setting the client request ID via the "request_id" parameter.
* Added the retry for the timeout errors.
* Added the retry for the connection reset error.

BLOB
* Fixed the issue where "list_blobs" doesn't work when delimiter is specified. (https://github.com/Azure/azure-storage-ruby/issues/41)

2016.08 - version 0.11.0-preview

ALL
Expand Down
12 changes: 8 additions & 4 deletions lib/azure/storage/blob/append.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ module Blob
# and also can be used to attach additional metadata
# * +:metadata+ - Hash. Custom metadata values to store with the blob.
# * +:timeout+ - Integer. A timeout in seconds.
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
# in the analytics logs when storage analytics logging is enabled.
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
# the Blob service returns status code 412 (Precondition Failed).
Expand All @@ -69,7 +71,7 @@ def create_append_blob(container, blob, options={})

uri = blob_uri(container, blob, query)

headers = StorageService.service_properties_headers
headers = StorageService.common_headers

# set x-ms-blob-type to AppendBlob
StorageService.with_header headers, 'x-ms-blob-type', 'AppendBlob'
Expand All @@ -90,7 +92,7 @@ def create_append_blob(container, blob, options={})
add_blob_conditional_headers options, headers

# call PutBlob with empty body
response = call(:put, uri, nil, headers)
response = call(:put, uri, nil, headers, options)

result = Serialization.blob_from_headers(response.headers)
result.name = blob
Expand All @@ -116,6 +118,8 @@ def create_append_blob(container, blob, options={})
# * +:max_size+ - Integer. The max length in bytes permitted for the append blob
# * +:append_position+ - Integer. A number indicating the byte offset to compare. It will succeed only if the append position is equal to this number
# * +:timeout+ - Integer. A timeout in seconds.
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
# in the analytics logs when storage analytics logging is enabled.
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to append a block only if
# the blob has been modified since the specified date/time. If the blob has not been modified,
# the Blob service returns status code 412 (Precondition Failed).
Expand All @@ -138,13 +142,13 @@ def append_blob_block(container, blob, content, options={})

uri = blob_uri(container, blob, query)

headers = StorageService.service_properties_headers
headers = StorageService.common_headers
StorageService.with_header headers, 'Content-MD5', options[:content_md5]
StorageService.with_header headers, 'x-ms-lease-id', options[:lease_id]

add_blob_conditional_headers options, headers

response = call(:put, uri, content, headers)
response = call(:put, uri, content, headers, options)
result = Serialization.blob_from_headers(response.headers)
result.name = blob

Expand Down
66 changes: 48 additions & 18 deletions lib/azure/storage/blob/blob.rb

Large diffs are not rendered by default.

37 changes: 25 additions & 12 deletions lib/azure/storage/blob/blob_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def initialize(options = {})
@host = client.storage_blob_host
end

def call(method, uri, body=nil, headers={})
def call(method, uri, body=nil, headers={}, options={})
# Force the request.body to the content encoding of specified in the header
# (content encoding probably shouldn't be used this way)
if headers && !body.nil?
Expand Down Expand Up @@ -96,6 +96,9 @@ def call(method, uri, body=nil, headers={})
#
# * +:timeout+ - Integer. A timeout in seconds.
#
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
# in the analytics logs when storage analytics logging is enabled.
#
# NOTE: Metadata requested with the :metadata parameter must have been stored in
# accordance with the naming restrictions imposed by the 2009-09-19 version of the Blob
# service. Beginning with that version, all metadata names must adhere to the naming
Expand All @@ -120,7 +123,7 @@ def list_containers(options={})
end

uri = containers_uri(query)
response = call(:get, uri)
response = call(:get, uri, nil, {}, options)

Serialization.container_enumeration_results_from_xml(response.body)
end
Expand All @@ -142,6 +145,8 @@ def list_containers(options={})
# * +:proposed_lease_id+ - String. Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request)
# if the proposed lease ID is not in the correct format. (optional)
# * +:timeout+ - Integer. A timeout in seconds.
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
# in the analytics logs when storage analytics logging is enabled.
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
# the Blob service returns status code 412 (Precondition Failed).
Expand Down Expand Up @@ -174,13 +179,13 @@ def acquire_lease(container, blob, options={})
duration = -1
duration = options[:duration] if options[:duration]

headers = Service::StorageService.service_properties_headers
headers = Service::StorageService.common_headers
Service::StorageService.with_header headers, 'x-ms-lease-action', 'acquire'
Service::StorageService.with_header headers, 'x-ms-lease-duration', duration.to_s if duration
Service::StorageService.with_header headers, 'x-ms-proposed-lease-id', options[:proposed_lease_id]
add_blob_conditional_headers options, headers

response = call(:put, uri, nil, headers)
response = call(:put, uri, nil, headers, options)
response.headers['x-ms-lease-id']
end

Expand All @@ -200,6 +205,8 @@ def acquire_lease(container, blob, options={})
#
# Accepted key/value pairs in options parameter are:
# * +:timeout+ - Integer. A timeout in seconds.
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
# in the analytics logs when storage analytics logging is enabled.
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to renew the lease
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
# the Blob service returns status code 412 (Precondition Failed).
Expand Down Expand Up @@ -228,12 +235,12 @@ def renew_lease(container, blob, lease, options={})
uri = container_uri(container, query)
end

headers = Service::StorageService.service_properties_headers
headers = Service::StorageService.common_headers
Service::StorageService.with_header headers, 'x-ms-lease-action', 'renew'
Service::StorageService.with_header headers, 'x-ms-lease-id', lease
add_blob_conditional_headers options, headers

response = call(:put, uri, nil, headers)
response = call(:put, uri, nil, headers, options)
response.headers['x-ms-lease-id']
end

Expand All @@ -252,6 +259,8 @@ def renew_lease(container, blob, lease, options={})
#
# Accepted key/value pairs in options parameter are:
# * +:timeout+ - Integer. A timeout in seconds.
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
# in the analytics logs when storage analytics logging is enabled.
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to change the lease
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
# the Blob service returns status code 412 (Precondition Failed).
Expand Down Expand Up @@ -281,13 +290,13 @@ def change_lease(container, blob, lease, proposed_lease, options={})
uri = container_uri(container, query)
end

headers = Service::StorageService.service_properties_headers
headers = Service::StorageService.common_headers
Service::StorageService.with_header headers, 'x-ms-lease-action', 'change'
Service::StorageService.with_header headers, 'x-ms-lease-id', lease
Service::StorageService.with_header headers, 'x-ms-proposed-lease-id', proposed_lease
add_blob_conditional_headers options, headers

response = call(:put, uri, nil, headers)
response = call(:put, uri, nil, headers, options)
response.headers['x-ms-lease-id']
end

Expand All @@ -306,6 +315,8 @@ def change_lease(container, blob, lease, proposed_lease, options={})
#
# Accepted key/value pairs in options parameter are:
# * +:timeout+ - Integer. A timeout in seconds.
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
# in the analytics logs when storage analytics logging is enabled.
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to release the lease
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
# the Blob service returns status code 412 (Precondition Failed).
Expand Down Expand Up @@ -334,12 +345,12 @@ def release_lease(container, blob, lease, options={})
uri = container_uri(container, query)
end

headers = Service::StorageService.service_properties_headers
headers = Service::StorageService.common_headers
Service::StorageService.with_header headers, 'x-ms-lease-action', 'release'
Service::StorageService.with_header headers, 'x-ms-lease-id', lease
add_blob_conditional_headers options, headers

call(:put, uri, nil, headers)
call(:put, uri, nil, headers, options)
nil
end

Expand Down Expand Up @@ -370,6 +381,8 @@ def release_lease(container, blob, lease, options={})
# If this option is not used, a fixed-duration lease breaks after the remaining lease
# period elapses, and an infinite lease breaks immediately.
# * +:timeout+ - Integer. A timeout in seconds.
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
# in the analytics logs when storage analytics logging is enabled.
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
# the Blob service returns status code 412 (Precondition Failed).
Expand Down Expand Up @@ -400,12 +413,12 @@ def break_lease(container, blob, options={})
uri = container_uri(container, query)
end

headers = Service::StorageService.service_properties_headers
headers = Service::StorageService.common_headers
Service::StorageService.with_header headers, 'x-ms-lease-action', 'break'
Service::StorageService.with_header headers, 'x-ms-lease-break-period', options[:break_period].to_s if options[:break_period]
add_blob_conditional_headers options, headers

response = call(:put, uri, nil, headers)
response = call(:put, uri, nil, headers, options)
response.headers['x-ms-lease-time'].to_i
end

Expand Down
36 changes: 22 additions & 14 deletions lib/azure/storage/blob/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def initialize
# and also can be used to attach additional metadata
# * +:metadata+ - Hash. Custom metadata values to store with the blob.
# * +:timeout+ - Integer. A timeout in seconds.
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
# in the analytics logs when storage analytics logging is enabled.
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
# the Blob service returns status code 412 (Precondition Failed).
Expand All @@ -91,7 +93,7 @@ def create_block_blob(container, blob, content, options={})

uri = blob_uri(container, blob, query)

headers = StorageService.service_properties_headers
headers = StorageService.common_headers

# set x-ms-blob-type to BlockBlob
StorageService.with_header headers, 'x-ms-blob-type', 'BlockBlob'
Expand All @@ -109,7 +111,7 @@ def create_block_blob(container, blob, content, options={})
add_blob_conditional_headers options, headers

# call PutBlob with empty body
response = call(:put, uri, content, headers)
response = call(:put, uri, content, headers, options)

result = Serialization.blob_from_headers(response.headers)
result.name = blob
Expand All @@ -132,6 +134,8 @@ def create_block_blob(container, blob, content, options={})
# Accepted key/value pairs in options parameter are:
# * +:content_md5+ - String. Content MD5 for the request contents.
# * +:timeout+ - Integer. A timeout in seconds.
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
# in the analytics logs when storage analytics logging is enabled.
#
# See http://msdn.microsoft.com/en-us/library/azure/dd135726.aspx
#
Expand All @@ -143,10 +147,10 @@ def put_blob_block(container, blob, block_id, content, options={})

uri = blob_uri(container, blob, query)

headers = StorageService.service_properties_headers
headers = StorageService.common_headers
StorageService.with_header headers, 'Content-MD5', options[:content_md5]

response = call(:put, uri, content, headers)
response = call(:put, uri, content, headers, options)
response.headers['Content-MD5']
end

Expand Down Expand Up @@ -186,6 +190,8 @@ def put_blob_block(container, blob, block_id, content, options={})
# and also can be used to attach additional metadata
# * +:metadata+ - Hash. Custom metadata values to store with the blob.
# * +:timeout+ - Integer. A timeout in seconds.
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
# in the analytics logs when storage analytics logging is enabled.
#
# This operation also supports the use of conditional headers to commit the block list if a specified condition is met.
# For more information, see https://msdn.microsoft.com/en-us/library/azure/dd179371.aspx
Expand All @@ -199,7 +205,7 @@ def commit_blob_blocks(container, blob, block_list, options={})

uri = blob_uri(container, blob, query)

headers = StorageService.service_properties_headers
headers = StorageService.common_headers
unless options.empty?
StorageService.with_header headers, 'Content-MD5', options[:transactional_md5]
StorageService.with_header headers, 'x-ms-blob-content-type', options[:content_type]
Expand All @@ -214,7 +220,7 @@ def commit_blob_blocks(container, blob, block_list, options={})
end

body = Serialization.block_list_to_xml(block_list)
call(:put, uri, body, headers)
call(:put, uri, body, headers, options)
nil
end

Expand All @@ -230,17 +236,19 @@ def commit_blob_blocks(container, blob, block_list, options={})
#
# ==== Attributes
#
# * +container+ - String. The container name.
# * +blob+ - String. The blob name.
# * +options+ - Hash. Optional parameters.
# * +container+ - String. The container name.
# * +blob+ - String. The blob name.
# * +options+ - Hash. Optional parameters.
#
# ==== Options
#
# Accepted key/value pairs in options parameter are:
# * +:blocklist_type+ - Symbol. One of :all, :committed, :uncommitted. Defaults to :all (optional)
# * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
# retrieve information from. (optional)
# * +:timeout+ - Integer. A timeout in seconds.
# * +:blocklist_type+ - Symbol. One of :all, :committed, :uncommitted. Defaults to :all (optional)
# * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
# retrieve information from. (optional)
# * +:timeout+ - Integer. A timeout in seconds.
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
# in the analytics logs when storage analytics logging is enabled.
#
# See http://msdn.microsoft.com/en-us/library/azure/dd179400.aspx
#
Expand All @@ -256,7 +264,7 @@ def list_blob_blocks(container, blob, options={})

uri = blob_uri(container, blob, query)

response = call(:get, uri)
response = call(:get, uri, nil, {}, options)

Serialization.block_list_from_xml(response.body)
end
Expand Down
Loading

0 comments on commit 61c7227

Please sign in to comment.