ruby-on-railsfogfog-google

Fog-Google Storage Specify Project


There appear to be a lot of different docs on how to configure Google Storage with Fog. I've been able to get Paperclip to work with just a few parameters and was hoping to keep things simple for doing some basic file storage and manipulation:

connection = Fog::Storage.new({
  provider:                         'Google',
  google_project:                   'MYPROJECT',
  google_storage_access_key_id:     'MYKEYID',
  google_storage_secret_access_key: 'MYSECRET'
})

This will generate a warning:

[fog][WARNING] Unrecognized arguments: google_project

I'm able to store files, create buckets, and do everything I need EXCEPT I only have access to the default project. Does anyone know how I can simply specify the Google Project in the Fog::Storage.new hash?


Solution

  • Google storage credentials through Fog can be confusing because Google has two separate storage APIs. By using an access_key_id, you are opting to use the legacy XML storage API, which has no understanding of projects. If you remove the project arg, it works fine.

    Since they are using a access_key and secret pair (and by doing so using the Google Storage XML API), they do not need to specify a project, since access keys are tied to a project.

    $ irb 2.4.0 :001 > require 'fog/google' => true 2.4.0 :002 > 2.4.0 :003 > connection = Fog::Storage.new({ 2.4.0 :004 > provider: 'Google', 2.4.0 :005 > google_storage_access_key_id: 'MYKEYID', 2.4.0 :006 > google_storage_secret_access_key: 'MYSECRET' 2.4.0 :007?> }) => #<Fog::Storage::GoogleXML::Real:70271319462720 @google_storage_access_key_id="MYKEYID" @google_storage_secret_access_key="MYSECRET" @connection_options={} @hmac=#<Fog::HMAC:0x007fd2a211a1a8 @key="MYSECRET", @digest=#<OpenSSL::Digest: da39a3ee5e6b4b0d3255bfef95601890afd80709>, @signer=#<Proc:0x007fd2a2119de8@/Users/natwelch/.rvm/gems/ruby-2.4.0/gems/fog-core-1.45.0/lib/fog/core/hmac.rb:21 (lambda)>> @host="storage.googleapis.com" @persistent=true @port=443 @scheme="https" @path_style=false>

    The API docs for XML are at https://cloud.google.com/storage/docs/xml-api/overview and the fog-google code is at https://github.com/fog/fog-google/tree/master/lib/fog/storage/google_xml