Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/renchap/shrine-google_cloud_storage
Google Cloud Storage for Shrine
https://github.com/renchap/shrine-google_cloud_storage
google-cloud-storage ruby shrine
Last synced: 8 days ago
JSON representation
Google Cloud Storage for Shrine
- Host: GitHub
- URL: https://github.com/renchap/shrine-google_cloud_storage
- Owner: renchap
- License: mit
- Created: 2016-08-28T11:11:12.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2024-05-16T19:00:29.000Z (6 months ago)
- Last Synced: 2024-10-03T12:39:17.971Z (about 1 month ago)
- Topics: google-cloud-storage, ruby, shrine
- Language: Ruby
- Homepage:
- Size: 117 KB
- Stars: 33
- Watchers: 3
- Forks: 26
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![Gem Version](https://badge.fury.io/rb/shrine-google_cloud_storage.svg)](https://badge.fury.io/rb/shrine-google_cloud_storage)
# Shrine::Storage::GoogleCloudStorage
Provides [Google Cloud Storage] (GCS) storage for [Shrine].
## Installation
```ruby
gem "shrine-google_cloud_storage"
```## Authentication
The GCS plugin uses the `google-cloud-storage` gem. Please refer to [its documentation for setting up authentication](https://googleapis.dev/ruby/google-cloud-storage/latest/file.AUTHENTICATION.html).
## Usage
```rb
require "shrine/storage/google_cloud_storage"Shrine.storages = {
cache: Shrine::Storage::GoogleCloudStorage.new(bucket: "cache"),
store: Shrine::Storage::GoogleCloudStorage.new(bucket: "store"),
}
```You can set a predefined ACL on created objects, as well as custom headers using the `object_options` parameter:
```rb
Shrine::Storage::GoogleCloudStorage.new(
bucket: "store",
default_acl: 'publicRead',
object_options: {
cache_control: 'public, max-age: 7200'
},
)
```## Contributing
### Test setup
#### Option 1 - use the script
Review the script `test/create_test_environment.sh`. It will:
- create a Google Cloud project
- associate it with your billing account
- create a service account
- add the `roles/storage.admin` iam policy
- download the json credentials
- create a test bucket
- add the needed variables to your `.env` fileTo run, it assumes you have already run `gcloud auth login`.
It also needs a `.env` file in the project root containing the project name
and the billing account to use:```sh
cp .env.sample .env
# Edit .env to fill in your project and billing accounts
./test/create_test_environment.sh
```#### Option 2 - manual setup
Create your own bucket and provide variables that allow for [project and credential lookup](https://googleapis.dev/ruby/google-cloud-storage/latest/file.AUTHENTICATION.html#project-and-credential-lookup).
For example:```sh
GCS_BUCKET=shrine-gcs-test-my-project
GOOGLE_CLOUD_PROJECT=my-project
GOOGLE_CLOUD_KEYFILE=/Users/user/.gcp/my-project/shrine-gcs-test.json
```**Warning**: all content of the bucket is cleared between tests, create a new one only for this usage!
### Running tests
After setting up your bucket, run the tests:
```sh
$ bundle exec rake test
```For additional debug, add the following to your `.env` file:
```sh
GCS_DEBUG=true
```## License
[MIT](http://opensource.org/licenses/MIT)
[Google Cloud Storage]: https://cloud.google.com/storage/
[Shrine]: https://github.com/shrinerb/shrine