Code Monkey home page Code Monkey logo

shrine-google_cloud_storage's Introduction

Gem Version

Shrine::Storage::GoogleCloudStorage

Provides Google Cloud Storage (GCS) storage for Shrine.

Installation

gem "shrine-google_cloud_storage"

Authentication

The GCS plugin uses the google-cloud-storage gem. Please refer to its documentation for setting up authentication.

Usage

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:

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 file

To 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:

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. For example:

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:

$ bundle exec rake test

For additional debug, add the following to your .env file:

GCS_DEBUG=true

License

MIT

shrine-google_cloud_storage's People

Contributors

renchap avatar janko avatar ianks avatar sho918 avatar hwo411 avatar joshuarose avatar rosskevin avatar majksner avatar taykangsheng avatar herenow avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.