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

support Azure Blob storage #363

Merged
merged 11 commits into from
Dec 12, 2017
Merged

Conversation

d-tasaki
Copy link
Contributor

@d-tasaki d-tasaki commented Dec 7, 2017

I added AzureRM provider to support Azure Blob storage. It depends on fog-azure-rm gem.

@PikachuEXE
Copy link
Member

Thanks for the PR
Gonna check it next week
Busy today

else
raise ArgumentError, "AssetSync Unknown provider: #{fog_provider} only AWS, Rackspace and Google are supported currently."
end

options.merge!({:region => fog_region}) if fog_region && !rackspace?
options.merge!({:region => fog_region}) if fog_region && !rackspace? && !azure_rm?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should really put this line into every if except rackspace

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can refactor this later you can leave this unchanged :P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean like below?

if aws?
  ...
  options.merge!({:region => fog_region}) if fog_region
elsif rackspace?
  ...
  options.merge!({:rackspace_region => fog_region}) if fog_region
elsif google?
  ...
  options.merge!({:region => fog_region}) if fog_region
elsif azure_rm?
  ...
  options.merge!({:environment => fog_region}) if fog_region
else
  ...
end

@@ -202,6 +202,10 @@ def upload_file(f)
})
end

if config.azure_rm?
file[:content_type] = file[:content_type].content_type if file[:content_type].is_a?(::MIME::Type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't quite understand why this is needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, sorry...
but, I got an error as below without the content_type conversion.

rake aborted!
NoMethodError: undefined method `length' for #<MIME::Type:0x007fda42e79040>
vendor/bundle/ruby/2.3.0/gems/azure-storage-0.11.5.preview/lib/azure/storage/core/utility.rb:112:in `parse_charset_from_content_type'
vendor/bundle/ruby/2.3.0/gems/azure-storage-0.11.5.preview/lib/azure/storage/blob/blob_service.rb:54:in `call'
vendor/bundle/ruby/2.3.0/gems/azure-storage-0.11.5.preview/lib/azure/storage/blob/block.rb:114:in `create_block_blob'
vendor/bundle/ruby/2.3.0/gems/fog-azure-rm-0.3.8/lib/fog/azurerm/requests/storage/create_block_blob.rb:31:in `create_block_blob'
vendor/bundle/ruby/2.3.0/gems/fog-azure-rm-0.3.8/lib/fog/azurerm/models/storage/file.rb:250:in `save_blob'
vendor/bundle/ruby/2.3.0/gems/fog-azure-rm-0.3.8/lib/fog/azurerm/models/storage/file.rb:93:in `save'
vendor/bundle/ruby/2.3.0/gems/fog-core-1.45.0/lib/fog/core/collection.rb:50:in `create'
vendor/bundle/ruby/2.3.0/bundler/gems/asset_sync-2fa4d474d97e/lib/asset_sync/storage.rb:205:in `upload_file'
vendor/bundle/ruby/2.3.0/bundler/gems/asset_sync-2fa4d474d97e/lib/asset_sync/storage.rb:220:in `block in upload_files'
vendor/bundle/ruby/2.3.0/bundler/gems/asset_sync-2fa4d474d97e/lib/asset_sync/storage.rb:218:in `each'
vendor/bundle/ruby/2.3.0/bundler/gems/asset_sync-2fa4d474d97e/lib/asset_sync/storage.rb:218:in `upload_files'
vendor/bundle/ruby/2.3.0/bundler/gems/asset_sync-2fa4d474d97e/lib/asset_sync/storage.rb:234:in `sync'
vendor/bundle/ruby/2.3.0/bundler/gems/asset_sync-2fa4d474d97e/lib/asset_sync/asset_sync.rb:29:in `block in sync'
vendor/bundle/ruby/2.3.0/bundler/gems/asset_sync-2fa4d474d97e/lib/asset_sync/asset_sync.rb:51:in `with_config'
vendor/bundle/ruby/2.3.0/bundler/gems/asset_sync-2fa4d474d97e/lib/asset_sync/asset_sync.rb:28:in `sync'
vendor/bundle/ruby/2.3.0/bundler/gems/asset_sync-2fa4d474d97e/lib/tasks/asset_sync.rake:5:in `block (2 levels) in <top (required)>'
vendor/bundle/ruby/2.3.0/bundler/gems/asset_sync-2fa4d474d97e/lib/tasks/asset_sync.rake:28:in `block in <top (required)>'

I think Azure::Storage::Core::Utility#parse_charset_from_content_type needs content_type as a String, not as a MIME::Type, because it calls length and split(';') methods of content_type. so, I put the code to convert from MIME::Type to String.

module Azure::Storage
  module Core
    module Utility
      ...
      def parse_charset_from_content_type(content_type)
        if (content_type && content_type.length > 0)
          charset = content_type.split(';').delete_if { |attribute| !attribute.lstrip.start_with?('charset=') }.map { |x| x.lstrip }[0]
          charset['charset='.length...charset.length] if charset
        end
      end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess add a code comment to briefly explain this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment!

@d-tasaki
Copy link
Contributor Author

I added an integration spec for AzureRM, and I got results as below with my Azure account.

$ bundle exec rspec spec/integration/azure_rm_integration_spec.rb
I, [2017-12-12T00:14:09.260139 #74900]  INFO -- : Writing /Users/d-tasaki/dev/asset_sync/spec/dummy_app/public/d799c6b65cfc/application-f9444510dc7403e41049deb133f6892aa6a63c05591b2b59e4ee5b234d7bbd99.js
I, [2017-12-12T00:14:09.265277 #74900]  INFO -- : Writing /Users/d-tasaki/dev/asset_sync/spec/dummy_app/public/d799c6b65cfc/application-f9444510dc7403e41049deb133f6892aa6a63c05591b2b59e4ee5b234d7bbd99.js.gz
.I, [2017-12-12T00:14:16.176589 #74907]  INFO -- : Writing /Users/d-tasaki/dev/asset_sync/spec/dummy_app/public/a57ad61f7e01/application-f9444510dc7403e41049deb133f6892aa6a63c05591b2b59e4ee5b234d7bbd99.js
I, [2017-12-12T00:14:16.181744 #74907]  INFO -- : Writing /Users/d-tasaki/dev/asset_sync/spec/dummy_app/public/a57ad61f7e01/application-f9444510dc7403e41049deb133f6892aa6a63c05591b2b59e4ee5b234d7bbd99.js.gz
.I, [2017-12-12T00:14:19.893733 #74913]  INFO -- : Writing /Users/d-tasaki/dev/asset_sync/spec/dummy_app/public/bad9eb1d5a22/application-f9444510dc7403e41049deb133f6892aa6a63c05591b2b59e4ee5b234d7bbd99.js
I, [2017-12-12T00:14:19.898947 #74913]  INFO -- : Writing /Users/d-tasaki/dev/asset_sync/spec/dummy_app/public/bad9eb1d5a22/application-f9444510dc7403e41049deb133f6892aa6a63c05591b2b59e4ee5b234d7bbd99.js.gz
.

Finished in 17.01 seconds (files took 0.61792 seconds to load)
3 examples, 0 failures

@PikachuEXE PikachuEXE merged commit 1050326 into AssetSync:master Dec 12, 2017
@PikachuEXE
Copy link
Member

Will release next week (or you can try master to see if it works first)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants