Coder Social home page Coder Social logo

gcs-signer's Introduction

gcs-signer

Simple signed URL generator for Google Cloud Storage.

Features

  • No network connection required to generate signed URL.
  • Can read JSON service-account credentials from environment variables. So it can be used with google-cloud-ruby without additional configurations.

Installation

gem install gcs-signer

Usage

Authentication

If you already configured GOOGLE_APPLICATION_CREDENTIALS for google-cloud-ruby gem, just

signer = GcsSigner.new

You can also set GOOGLE_CLOUD_KEYFILE_JSON environment varialble to the content of service-account.json.

puts ENV["GOOGLE_CLOUD_KEYFILE_JSON"]
# => { "type": "service_account", ...
signer = GcsSigner.new

or you can give path of the service account file, or contents of it without using environment variables.

signer = GcsSigner.new path: "/home/leo/path/to/service_account.json"

signer = GcsSigner.new keyfile_json: '{ "type": "service_account", ...'

Signing URL

#sign_url to generate signed URL.

# The signed URL is valid for 5 minutes by default.
signer.sign_url "bucket-name", "path/to/object"

# You can specify timestamps or how many seconds the signed URL is valid for.
signer.sign_url "bucket-name", "object-name",
                expires: Time.new(2016, 12, 26, 14, 31, 48)

signer.sign_url "bucket-name", "object_name", valid_for: 600

# If you use AcriveSupport in your project, you can use some sugar like:
signer.sign_url "bucket", "object", valid_for: 45.minutes
signer.sign_url "bucket", "object", expires_at: 5.minutes.from_now

# You can set response_content_disposition and response_content_type to change response headers.
signer.sign_url "bucket", "object", response_content_type: "video/mp4"
signer.sign_url "bucket", "object", response_content_disposition: "attachment; filename=video.mp4"

# You can use V4 signing if you prefer longer URL
signer.sign_url "bucket", "object", version: :v4

License

gcs-signer is distributed under the MIT License.

gcs-signer's People

Contributors

premist avatar relip avatar yosangwon avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

rubythonode

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.