GCSとActiveStorageを使った時に秘密鍵でエラー
サービスアカウントを発行して、キーを発行してその中身を
1
| bundle exec rails credentials:edit
|
してstorage.ymlで読み出そうとした時にprivate_keyに改行があるためにうまくいかなかった。
dumpを使えばおっけー
1
| Rails.application.credentials.gcs[:private_key].dump
|
全体はこう。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| google:
service: GCS
credentials:
type: "service_account"
project_id: <%= Rails.application.credentials.gcs[:project_id] %>
private_key_id: <%= Rails.application.credentials.gcs[:private_key_id] %>
private_key: <%= Rails.application.credentials.gcs[:private_key].dump %>
client_email: <%= Rails.application.credentials.gcs[:client_email] %>
client_id: <%= Rails.application.credentials.gcs[:client_id] %>
auth_uri: "https://accounts.google.com/o/oauth2/auth"
token_uri: "https://accounts.google.com/o/oauth2/token"
auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs"
client_x509_cert_url: <%= Rails.application.credentials.gcs[:client_x509_cert_url] %>
project: ''
|
参考
https://github.com/rails/rails/blob/master/guides/source/active_storage_overview.md