Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for 0.12.0-preview #78

Merged
merged 8 commits into from
Feb 28, 2017
14 changes: 14 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
2017.02 - version 0.12.0-preview

ALL
* Fixed the issue where `should_retry?` in the retry_filter.rb overwrites the result from derived `apply_retry_policy`. [#76](https://github.com/Azure/azure-storage-ruby/issues/76)
* Fixed the issue where `Azure::Storage::Client.create_from_connection_string` throws an exception. [#77](https://github.com/Azure/azure-storage-ruby/issues/77)
* Added the support for setting the "timeout" option in `get_service_properties` and `set_service_properties`.

BLOB
* Added the metadata to the returning instance when creates a blob.
* Added `transactional_md5` to the options of `put_blob_pages`.

FILE
* Added File Service support, targeting storage service version 2015-04-05.

2016.12 - version 0.11.5-preview

ALL
Expand Down
123 changes: 85 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,29 @@ There are two ways you can set up the connections:

```ruby

require "azure/storage"
require 'azure/storage'

# Setup a specific instance of an Azure::Storage::Client
client = Azure::Storage::Client.create(:storage_account_name => "your account name", :storage_access_key => "your access key")
client = Azure::Storage::Client.create(:storage_account_name => 'your account name', :storage_access_key => 'your access key')

# Or create a client and store as a singleton
Azure::Storage.setup(:storage_account_name => "your account name", :storage_access_key => "your access key")
Azure::Storage.setup(:storage_account_name => 'your account name', :storage_access_key => 'your access key')
# Then you can either call Azure::Storage.client.some_method or Azure::Storage.some_method to invoke a method on the Storage Client

# Configure a ca_cert.pem file if you are having issues with ssl peer verification
client.ca_file = "./ca_file.pem"
client.ca_file = './ca_file.pem'

```

* Against local Emulator (Windows Only)

```ruby

require "azure/storage"
require 'azure/storage'
client = Azure::Storage::Client.create_develpoment

# Or create by options and provide your own proxy_uri
client = Azure::Storage::Client.create(:use_development_storage => true, :development_storage_proxy_uri => "your proxy uri")
client = Azure::Storage::Client.create(:use_development_storage => true, :development_storage_proxy_uri => 'your proxy uri')

```

Expand Down Expand Up @@ -104,16 +104,16 @@ There are two ways you can set up the connections:
```ruby

# Require the azure storage rubygem
require "azure/storage"
require 'azure/storage'

# Setup a specific instance of an Azure::Storage::Client
client = Azure::Storage::Client.create(:storage_account_name => "your account name", :storage_access_key => "your access key")
client = Azure::Storage::Client.create(:storage_account_name => 'your account name', :storage_access_key => 'your access key')

# Get an azure storage blob service object from a specific instance of an Azure::Storage::Client
blobs = client.blob_client

# Or setup the client as a singleton
Azure::Storage.setup(:storage_account_name => "your account name", :storage_access_key => "your access key")
Azure::Storage.setup(:storage_account_name => 'your account name', :storage_access_key => 'your access key')

# Create an azure storage blob service object after you set up the credentials
blobs = Azure::Storage::Blob::BlobService.new
Expand All @@ -122,11 +122,11 @@ blobs = Azure::Storage::Blob::BlobService.new
blobs.with_filter(Azure::Storage::Core::Filter::ExponentialRetryPolicyFilter.new)

# Create a container
container = blobs.create_container("test-container")
container = blobs.create_container('test-container')

# Upload a Blob
content = File.open('test.jpg', 'rb') { |file| file.read }
blobs.create_block_blob(container.name, "image-blob", content)
content = ::File.open('test.jpg', 'rb') { |file| file.read }
blobs.create_block_blob(container.name, 'image-blob', content)

# List containers
blobs.list_containers()
Expand All @@ -135,11 +135,11 @@ blobs.list_containers()
blobs.list_blobs(container.name)

# Download a Blob
blob, content = blobs.get_blob(container.name, "image-blob")
File.open("download.png", "wb") {|f| f.write(content)}
blob, content = blobs.get_blob(container.name, 'image-blob')
::File.open('download.png', 'wb') {|f| f.write(content)}

# Delete a Blob
blobs.delete_blob(container.name, "image-blob")
blobs.delete_blob(container.name, 'image-blob')

```
<a name="tables"></a>
Expand All @@ -148,16 +148,16 @@ blobs.delete_blob(container.name, "image-blob")
```ruby

# Require the azure storage rubygem
require "azure/storage"
require 'azure/storage'

# Setup a specific instance of an Azure::Storage::Client
client = Azure::Storage::Client.create(:storage_account_name => "your account name", :storage_access_key => "your access key")
client = Azure::Storage::Client.create(:storage_account_name => 'your account name', :storage_access_key => 'your access key')

# Get an azure storage table service object from a specific instance of an Azure::Storage::Client
tables = client.table_client

# Or setup the client as a singleton
Azure::Storage.setup(:storage_account_name => "your account name", :storage_access_key => "your access key")
Azure::Storage.setup(:storage_account_name => 'your account name', :storage_access_key => 'your access key')

# Create an azure storage table service object after you set up the credentials
tables = Azure::Storage::Table::TableService.new
Expand All @@ -166,28 +166,28 @@ tables = Azure::Storage::Table::TableService.new
tables.with_filter(Azure::Storage::Core::Filter::ExponentialRetryPolicyFilter.new)

# Create a table
tables.create_table("testtable")
tables.create_table('testtable')

# Insert an entity
entity = { content: "test entity", PartitionKey: "test-partition-key", RowKey: "1" }
tables.insert_entity("testtable", entity)
entity = { content: 'test entity', PartitionKey: 'test-partition-key', RowKey: '1' }
tables.insert_entity('testtable', entity)

# Get an entity
result = tables.get_entity("testtable", "test-partition-key", "1")
result = tables.get_entity('testtable', 'test-partition-key', '1')

# Update an entity
result.properties["content"] = "test entity with updated content"
result.properties['content'] = 'test entity with updated content'
tables.update_entity(result.table, result.properties)

# Query entities
query = { :filter => "content eq 'test entity'" }
result, token = tables.query_entities("testtable", query)
result, token = tables.query_entities('testtable', query)

# Delete an entity
tables.delete_entity("testtable", "test-partition-key", "1")
tables.delete_entity('testtable', 'test-partition-key', '1')

# delete a table
tables.delete_table("testtable")
tables.delete_table('testtable')

```

Expand All @@ -197,16 +197,16 @@ tables.delete_table("testtable")
```ruby

# Require the azure storage rubygem
require "azure/storage"
require 'azure/storage'

# Setup a specific instance of an Azure::Storage::Client
client = Azure::Storage::Client.create(:storage_account_name => "your account name", :storage_access_key => "your access key")
client = Azure::Storage::Client.create(:storage_account_name => 'your account name', :storage_access_key => 'your access key')

# Get an azure storage queue service object from a specific instance of an Azure::Storage::Client
queues = client.queue_client

# Or setup the client as a singleton
Azure::Storage.setup(:storage_account_name => "your account name", :storage_access_key => "your access key")
Azure::Storage.setup(:storage_account_name => 'your account name', :storage_access_key => 'your access key')

# Create an azure storage queue service object after you set up the credentials
queues = Azure::Storage::Queue::QueueService.new
Expand All @@ -215,28 +215,75 @@ queues = Azure::Storage::Queue::QueueService.new
queues.with_filter(Azure::Storage::Core::Filter::ExponentialRetryPolicyFilter.new)

# Create a queue
queues.create_queue("test-queue")
queues.create_queue('test-queue')

# Create a message
queues.create_message("test-queue", "test message")
queues.create_message('test-queue', 'test message')

# Get one or more messages with setting the visibility timeout
result = queues.list_messages("test-queue", 30, { number_of_messages: 10 })
result = queues.list_messages('test-queue', 30, { number_of_messages: 10 })

# Get one or more messages without setting the visibility timeout
result = queues.peek_messages("test-queue", { number_of_messages: 10 })
result = queues.peek_messages('test-queue', { number_of_messages: 10 })

# Update a message
message = queues.list_messages("test-queue", 30)
pop_receipt, time_next_visible = queues.update_message("test-queue", message[0].id, message[0].pop_receipt, "updated test message", 30)
message = queues.list_messages('test-queue', 30)
pop_receipt, time_next_visible = queues.update_message('test-queue', message[0].id, message[0].pop_receipt, 'updated test message', 30)

# Delete a message
message = queues.list_messages("test-queue", 30)
queues.delete_message("test-queue", message[0].id, message[0].pop_receipt)
message = queues.list_messages('test-queue', 30)
queues.delete_message('test-queue', message[0].id, message[0].pop_receipt)

# Delete a queue
queues.delete_queue("test-queue")
queues.delete_queue('test-queue')

```

<a name="files"></a>
## Files

```ruby
# Require the azure storage rubygem
require 'azure/storage'

# Setup a specific instance of an Azure::Storage::Client
client = Azure::Storage::Client.create(:storage_account_name => 'your account name', :storage_access_key => 'your access key')

# Get an azure storage file service object from a specific instance of an Azure::Storage::Client
files = client.file_client

# Or setup the client as a singleton
Azure::Storage.setup(:storage_account_name => 'your account name', :storage_access_key => 'your access key')

# Create an azure storage file service object after you set up the credentials
files = Azure::Storage::File::FileService.new

# Add retry filter to the service object
files.with_filter(Azure::Storage::Core::Filter::ExponentialRetryPolicyFilter.new)

# Create a share
share = files.create_share('test-share')

# Create a directory
directory = files.create_directory(share.name, 'test-directory')

# Create a file and update the file content
content = ::File.open('test.jpg', 'rb') { |file| file.read }
file = files.create_file(share.name, directory.name, 'test-file', content.size)
files.put_file_range(share.name, directory.name, file.name, 0, content.size - 1, content)

# List shares
files.list_shares()

# List directories and files
files.list_directories_and_files(share.name, directory.name)

# Download a File
file, content = files.get_file(share.name, directory.name, file.name)
::File.open('download.png', 'wb') {|f| f.write(content)}

# Delete a File
files.delete_file(share.name, directory.name, file.name)
```

<a name="Customize the user-agent"></a>
Expand Down
8 changes: 8 additions & 0 deletions lib/azure/storage/autoload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,13 @@ module Table
autoload :Query, 'azure/storage/table/query'
end

module File
autoload :FileService, 'azure/storage/file/file_service'
autoload :Share, 'azure/storage/file/share'
autoload :Directory, 'azure/storage/file/directory'
autoload :File, 'azure/storage/file/file'
autoload :Serialization, 'azure/storage/file/serialization'
end

end
end
1 change: 1 addition & 0 deletions lib/azure/storage/blob/append.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def create_append_blob(container, blob, options={})

result = Serialization.blob_from_headers(response.headers)
result.name = blob
result.metadata = options[:metadata] if options[:metadata]

result
end
Expand Down
18 changes: 9 additions & 9 deletions lib/azure/storage/blob/blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_blob(container, blob, options={})
#
# See http://msdn.microsoft.com/en-us/library/azure/dd179394.aspx
#
# Returns the blob properties
# Returns the blob properties with a Blob instance
def get_blob_properties(container, blob, options={})
query = { }
StorageService.with_query query, 'snapshot', options[:snapshot]
Expand Down Expand Up @@ -620,13 +620,13 @@ def create_blob_snapshot(container, blob, options={})
response.headers['x-ms-snapshot']
end

# Public: Copies a source blob to a destination blob.
# Public: Copies a source blob or file to a destination blob.
#
# ==== Attributes
#
# * +source_container+ - String. The destination container name to copy to.
# * +source_blob+ - String. The destination blob name to copy to.
# * +source_blob_uri+ - String. The source blob URI to copy from.
# * +destination_container+ - String. The destination container name to copy to.
# * +destination_blob+ - String. The destination blob name to copy to.
# * +source_uri+ - String. The source blob or file URI to copy from.
# * +options+ - Hash. Optional parameters.
#
# ==== Options
Expand Down Expand Up @@ -675,13 +675,13 @@ def create_blob_snapshot(container, blob, options={})
# "success" - The copy completed successfully.
# "pending" - The copy is in progress.
#
def copy_blob_from_uri(destination_container, destination_blob, source_blob_uri, options={})
def copy_blob_from_uri(destination_container, destination_blob, source_uri, options={})
query = { }
StorageService.with_query query, 'timeout', options[:timeout].to_s if options[:timeout]

uri = blob_uri(destination_container, destination_blob, query)
headers = StorageService.common_headers
StorageService.with_header headers, 'x-ms-copy-source', source_blob_uri
StorageService.with_header headers, 'x-ms-copy-source', source_uri

unless options.empty?
add_blob_conditional_headers options, headers
Expand All @@ -696,8 +696,8 @@ def copy_blob_from_uri(destination_container, destination_blob, source_blob_uri,
#
# ==== Attributes
#
# * +source_container+ - String. The destination container name to copy to.
# * +source_blob+ - String. The destination blob name to copy to.
# * +destination_container+ - String. The destination container name to copy to.
# * +destination_blob+ - String. The destination blob name to copy to.
# * +source_container+ - String. The source container name to copy from.
# * +source_blob+ - String. The source blob name to copy from.
# * +options+ - Hash. Optional parameters.
Expand Down
16 changes: 3 additions & 13 deletions lib/azure/storage/blob/blob_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BlobService < StorageService

def initialize(options = {}, &block)
client_config = options[:client] || Azure::Storage
signer = options[:signer] || Azure::Storage::Core::Auth::SharedKey.new(client_config.storage_account_name, client_config.storage_access_key)
signer = options[:signer] || client_config.signer || Azure::Storage::Core::Auth::SharedKey.new(client_config.storage_account_name, client_config.storage_access_key)
super(signer, client_config.storage_account_name, options, &block)
@host = client.storage_blob_host
end
Expand Down Expand Up @@ -469,19 +469,9 @@ def blob_uri(container_name, blob_name, query={})
if container_name.nil? || container_name.empty?
path = blob_name
else
path = File.join(container_name, blob_name)
path = ::File.join(container_name, blob_name)
end

path = CGI.escape(path.encode('UTF-8'))

# Unencode the forward slashes to match what the server expects.
path = path.gsub(/%2F/, '/')
# Unencode the backward slashes to match what the server expects.
path = path.gsub(/%5C/, '/')
# Re-encode the spaces (encoded as space) to the % encoding.
path = path.gsub(/\+/, '%20')

generate_uri(path, query)
generate_uri(path, query, true)
end

# Adds conditional header with required condition
Expand Down
1 change: 1 addition & 0 deletions lib/azure/storage/blob/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def create_block_blob(container, blob, content, options={})

result = Serialization.blob_from_headers(response.headers)
result.name = blob
result.metadata = options[:metadata] if options[:metadata]

result
end
Expand Down
Loading