繁体   English   中英

使用Fog-google中的服务帐户(电子邮件和密钥)进行身份验证

[英]Authenticating with service account (email & key) in fog-google

我不断收到Missing required arguments: google_storage_access_key_id, google_storage_secret_access_key 我知道应该将凭据“放在/.fog”文件中,但是我不太了解在Rails应用程序中该如何工作。 有人可以详细说明如何配置吗? 我曾尝试在初始化传递设置(如建议在这里 ),但他们似乎并没有得到在认可validate_options方法。

config / initializers / fog.rb GoogleStorage = Fog::Storage.new( provider: 'Google', google_project: 'xxxxxxxxxxxxx', google_client_email: 'xxxxxxxxxxxxx-yyyyyyyyyyyyy@developer.gserviceaccount.com', google_key_location: 'private/google-cloud-service-key.p12' )

事实证明, fog-google宝石目前无法做到这一点。 请参阅此Github问题 当gem更新为处理此身份验证策略时,我将更新此答案。

请改用Figaro Gem安全地处理您要存储并在整个应用程序中使用的任何ENV变量。

将Figaro添加到您的Gemfile并bundle install

gem "figaro"

Figaro的安装很简单:

$ bundle exec figaro install

这将创建一个带注释的config/application.yml文件,并将其添加到您的.gitignore中。 将您自己的配置添加到此文件,就可以完成!

示例application.yml文件

# config/application.yml

GOOGLE_ID: "ID"
GOOGLE_KEY: "KEY"

然后config / initializers / fog.rb

GoogleStorage = Fog::Storage.new(
  provider: 'Google',
  google_project: 'xxxxxxxxxxxxx',
  google_client_email: 'xxxxxxxxxxxxx-yyyyyyyyyyyyy@developer.gserviceaccount.com',
  google_key_location: Rails.root.join('private','google-cloud-service-key.p12'),
  google_storage_secret_access_key_id: ENV["GOOGLE_ID"],
  google_storage_secret_access_key: ENV["GOOGLE_KEY"]
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM