From c631c29d6915beb015c7a49b5eaa8bb420b32a49 Mon Sep 17 00:00:00 2001 From: Yang Xia Date: Fri, 25 Nov 2016 15:56:24 +0800 Subject: [PATCH 1/2] * Removed the unnecessary dependencies. This resolves: [#55](https://github.com/Azure/azure-storage-ruby/issues/55), [#67](https://github.com/Azure/azure-storage-ruby/issues/67) * Fixed the issue when checking the content encoding. * Fixed the wrong "Content-Encoding" value in the test cases. --- ChangeLog.md | 9 +++++++++ azure-storage.gemspec | 17 ++++++----------- lib/azure/storage.rb | 2 -- lib/azure/storage/blob/blob.rb | 2 +- lib/azure/storage/blob/blob_service.rb | 4 ++-- lib/azure/storage/version.rb | 2 +- test/integration/blob/append_blob_test.rb | 2 +- test/integration/blob/blob_properties_test.rb | 2 +- test/integration/blob/block_blob_test.rb | 2 +- test/integration/blob/create_page_blob_test.rb | 2 +- .../core/auth/shared_access_signature_test.rb | 6 +++--- 11 files changed, 26 insertions(+), 24 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 1dbe9c49..f730a0a7 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,12 @@ +2016.11 - version 0.11.4-preview + +ALL +* Removed the unnecessary dependencies. This resolves: [#55](https://github.com/Azure/azure-storage-ruby/issues/55), [#67](https://github.com/Azure/azure-storage-ruby/issues/67) + +BLOB +* Fixed the issue when checking the content encoding. +* Fixed the wrong "Content-Encoding" value in the test cases. + 2016.10 - version 0.11.3-preview ALL diff --git a/azure-storage.gemspec b/azure-storage.gemspec index c208260d..0620e6cc 100644 --- a/azure-storage.gemspec +++ b/azure-storage.gemspec @@ -38,21 +38,16 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 1.9.3' - s.add_runtime_dependency('addressable', '~> 2.3') s.add_runtime_dependency('azure-core', '~> 0.1') s.add_runtime_dependency('faraday', '~> 0.9') s.add_runtime_dependency('faraday_middleware', '~> 0.10') - s.add_runtime_dependency('json', '~> 1.8') - s.add_runtime_dependency('mime-types', '~> 2.0') s.add_runtime_dependency('nokogiri', '~> 1.6') - s.add_runtime_dependency('systemu', '~> 2.6') - s.add_runtime_dependency('thor', '~> 0.19') - s.add_development_dependency('dotenv', '~> 2.0') - s.add_development_dependency('minitest', '~> 5') - s.add_development_dependency('minitest-reporters', '~> 1') - s.add_development_dependency('mocha', '~> 1.0') - s.add_development_dependency('rake', '~> 10.0') - s.add_development_dependency('timecop', '~> 0.7') + s.add_development_dependency('dotenv', '~> 2.0') + s.add_development_dependency('minitest', '~> 5') + s.add_development_dependency('minitest-reporters', '~> 1') + s.add_development_dependency('mocha', '~> 1.0') + s.add_development_dependency('rake', '~> 10.0') + s.add_development_dependency('timecop', '~> 0.7') s.add_development_dependency('yard', '~> 0.8') end diff --git a/lib/azure/storage.rb b/lib/azure/storage.rb index 05fbc285..a6a8ed55 100644 --- a/lib/azure/storage.rb +++ b/lib/azure/storage.rb @@ -27,8 +27,6 @@ require 'base64' require 'openssl' require 'uri' -require 'rexml/document' -require 'addressable/uri' require 'faraday' require 'faraday_middleware' diff --git a/lib/azure/storage/blob/blob.rb b/lib/azure/storage/blob/blob.rb index c782339d..aa057972 100644 --- a/lib/azure/storage/blob/blob.rb +++ b/lib/azure/storage/blob/blob.rb @@ -125,7 +125,7 @@ def get_blob(container, blob, options={}) # # See http://msdn.microsoft.com/en-us/library/azure/dd179394.aspx # - # Returns a Blob + # Returns the blob properties def get_blob_properties(container, blob, options={}) query = { } StorageService.with_query query, 'snapshot', options[:snapshot] diff --git a/lib/azure/storage/blob/blob_service.rb b/lib/azure/storage/blob/blob_service.rb index 6d9e4e9e..d8a56f8a 100644 --- a/lib/azure/storage/blob/blob_service.rb +++ b/lib/azure/storage/blob/blob_service.rb @@ -47,12 +47,12 @@ def initialize(options = {}) def call(method, uri, body=nil, headers={}, options={}) # Force the request.body to the content encoding of specified in the header - if headers && !body.nil? && !(body.encoding.to_s <=> 'ASCII_8BIT') + if headers && !body.nil? && ((body.encoding.to_s <=> 'ASCII_8BIT') != 0) if headers['x-ms-blob-content-type'].nil? Service::StorageService.with_header headers, 'x-ms-blob-content-type', "text/plain; charset=#{body.encoding.to_s}" else charset = parse_charset_from_content_type(headers['x-ms-blob-content-type']) - body.force_encoding(charset) + body.force_encoding(charset) if charset end end diff --git a/lib/azure/storage/version.rb b/lib/azure/storage/version.rb index 74953ca1..1293f6f2 100644 --- a/lib/azure/storage/version.rb +++ b/lib/azure/storage/version.rb @@ -28,7 +28,7 @@ class Version # Fields represent the parts defined in http://semver.org/ MAJOR = 0 unless defined? MAJOR MINOR = 11 unless defined? MINOR - UPDATE = 3 unless defined? UPDATE + UPDATE = 4 unless defined? UPDATE PRE = 'preview' unless defined? PRE class << self diff --git a/test/integration/blob/append_blob_test.rb b/test/integration/blob/append_blob_test.rb index b969ee42..dbe4331f 100644 --- a/test/integration/blob/append_blob_test.rb +++ b/test/integration/blob/append_blob_test.rb @@ -60,7 +60,7 @@ it 'sets additional properties when the options hash is used' do options = { :content_type=>"application/xml", - :content_encoding=>"utf-8", + :content_encoding=>"gzip", :content_language=>"en-US", :cache_control=>"max-age=1296000", :metadata => { "CustomMetadataProperty"=>"CustomMetadataValue"} diff --git a/test/integration/blob/blob_properties_test.rb b/test/integration/blob/blob_properties_test.rb index 3fe95ee8..2ec815d3 100644 --- a/test/integration/blob/blob_properties_test.rb +++ b/test/integration/blob/blob_properties_test.rb @@ -38,7 +38,7 @@ } let(:options){{ :content_type=>"application/my-special-format", - :content_encoding=>"utf-16", + :content_encoding=>"gzip", :content_language=>"klingon", :cache_control=>"max-age=1296000", }} diff --git a/test/integration/blob/block_blob_test.rb b/test/integration/blob/block_blob_test.rb index c27be24d..8a16588a 100644 --- a/test/integration/blob/block_blob_test.rb +++ b/test/integration/blob/block_blob_test.rb @@ -57,7 +57,7 @@ it 'sets additional properties when the options hash is used' do options = { :content_type=>"application/xml", - :content_encoding=>"utf-8", + :content_encoding=>"gzip", :content_language=>"en-US", :cache_control=>"max-age=1296000", :metadata => { "CustomMetadataProperty"=>"CustomMetadataValue"} diff --git a/test/integration/blob/create_page_blob_test.rb b/test/integration/blob/create_page_blob_test.rb index 3c8514d4..49a81fe6 100644 --- a/test/integration/blob/create_page_blob_test.rb +++ b/test/integration/blob/create_page_blob_test.rb @@ -64,7 +64,7 @@ it 'sets additional properties when the options hash is used' do options = { :content_type=>"application/xml", - :content_encoding=>"utf-8", + :content_encoding=>"gzip", :content_language=>"en-US", :cache_control=>"max-age=1296000", :metadata => { "CustomMetadataProperty"=>"CustomMetadataValue"} diff --git a/test/unit/core/auth/shared_access_signature_test.rb b/test/unit/core/auth/shared_access_signature_test.rb index 1ae0718a..5fc4bf39 100644 --- a/test/unit/core/auth/shared_access_signature_test.rb +++ b/test/unit/core/auth/shared_access_signature_test.rb @@ -40,7 +40,7 @@ ip_range: '168.1.5.60-168.1.5.70', cache_control: 'public', content_disposition: 'inline, filename=nyan.cat', - content_encoding: 'utf-8', + content_encoding: 'gzip', content_language: 'English', content_type: 'binary' } @@ -66,7 +66,7 @@ subject.signable_string_for_service(service_type, path, service_options).must_equal( "rwd\n#{Time.parse('2020-12-10T00:00:00Z').utc.iso8601}\n#{Time.parse('2020-12-11T00:00:00Z').utc.iso8601}\n" + "/blob/account-name/example/path\n\n168.1.5.60-168.1.5.70\nhttps,http\n#{Azure::Storage::Default::STG_VERSION}\n" + - "public\ninline, filename=nyan.cat\nutf-8\nEnglish\nbinary" + "public\ninline, filename=nyan.cat\ngzip\nEnglish\nbinary" ) end @@ -95,7 +95,7 @@ query_hash['spr'].must_equal 'https,http' query_hash['rscc'].must_equal 'public' query_hash['rscd'].must_equal 'inline, filename=nyan.cat' - query_hash['rsce'].must_equal 'utf-8' + query_hash['rsce'].must_equal 'gzip' query_hash['rscl'].must_equal 'English' query_hash['rsct'].must_equal 'binary' end From e62ff95d6ce6e9f620080fc88ff2abd57cf73854 Mon Sep 17 00:00:00 2001 From: Yang Xia Date: Fri, 25 Nov 2016 16:01:13 +0800 Subject: [PATCH 2/2] Fixed the issue where it cannot use the create_block_blob method with an IO/File object --- ChangeLog.md | 3 ++- lib/azure/storage/blob/blob_service.rb | 2 +- test/integration/blob/block_blob_test.rb | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index f730a0a7..86537b81 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,11 +1,12 @@ 2016.11 - version 0.11.4-preview ALL -* Removed the unnecessary dependencies. This resolves: [#55](https://github.com/Azure/azure-storage-ruby/issues/55), [#67](https://github.com/Azure/azure-storage-ruby/issues/67) +* Removed the unnecessary dependencies. [#55](https://github.com/Azure/azure-storage-ruby/issues/55), [#67](https://github.com/Azure/azure-storage-ruby/issues/67) BLOB * Fixed the issue when checking the content encoding. * Fixed the wrong "Content-Encoding" value in the test cases. +* Fixed the issue where it cannot use the `create_block_blob` method with an IO/File object. [#61](https://github.com/Azure/azure-storage-ruby/issues/61) 2016.10 - version 0.11.3-preview diff --git a/lib/azure/storage/blob/blob_service.rb b/lib/azure/storage/blob/blob_service.rb index d8a56f8a..1fdc241e 100644 --- a/lib/azure/storage/blob/blob_service.rb +++ b/lib/azure/storage/blob/blob_service.rb @@ -47,7 +47,7 @@ def initialize(options = {}) def call(method, uri, body=nil, headers={}, options={}) # Force the request.body to the content encoding of specified in the header - if headers && !body.nil? && ((body.encoding.to_s <=> 'ASCII_8BIT') != 0) + if headers && !body.nil? && (body.is_a? String) && ((body.encoding.to_s <=> 'ASCII_8BIT') != 0) if headers['x-ms-blob-content-type'].nil? Service::StorageService.with_header headers, 'x-ms-blob-content-type', "text/plain; charset=#{body.encoding.to_s}" else diff --git a/test/integration/blob/block_blob_test.rb b/test/integration/blob/block_blob_test.rb index 8a16588a..f4af958a 100644 --- a/test/integration/blob/block_blob_test.rb +++ b/test/integration/blob/block_blob_test.rb @@ -41,6 +41,23 @@ blob = subject.create_block_blob container_name, blob_name, content blob.name.must_equal blob_name end + + it 'creates a block blob with IO' do + begin + file = File.open blob_name, 'w+' + file.write content + file.seek 0 + subject.create_block_blob container_name, blob_name, file + blob = subject.get_blob_properties container_name, blob_name + blob.name.must_equal blob_name + blob.properties[:content_length].must_equal content.length + ensure + unless file.nil? + file.close + File.delete blob_name + end + end + end it 'should create a block blob with spaces in name' do blob_name = 'blob with spaces'