Skip to content

feat: support STORAGE_EMULATOR_HOST environment variable#34023

Open
SalvatoreT wants to merge 1 commit into
googleapis:mainfrom
SalvatoreT:salvatoret/34022/support-storage-emulator-host
Open

feat: support STORAGE_EMULATOR_HOST environment variable#34023
SalvatoreT wants to merge 1 commit into
googleapis:mainfrom
SalvatoreT:salvatoret/34022/support-storage-emulator-host

Conversation

@SalvatoreT

Copy link
Copy Markdown

Summary

Adds support for the STORAGE_EMULATOR_HOST environment variable to google-cloud-storage, so the client can be pointed at a local Cloud Storage emulator (e.g. fake-gcs-server, the gcloud storage emulator). This brings the Ruby library in line with the Python google-cloud-storage library (see googleapis/google-cloud-python#9219) and the existing emulator-aware Ruby gems (pubsub, datastore, firestore, bigtable, bigquery).

Fixes #34022

Behavior

The emulator can be selected in three ways (in precedence order):

  • Google::Cloud::Storage.new emulator_host: "http://localhost:9000"
  • Google::Cloud::Storage.configure { |c| c.emulator_host = "http://localhost:9000" }
  • STORAGE_EMULATOR_HOST=http://localhost:9000 environment variable

When an emulator host is set:

  • It is used as the API endpoint (storage is REST-based, so this sets the underlying root_url).
  • Authentication is not required: the client connects anonymously (no Application Default Credentials lookup), but any explicitly-provided credentials/keyfile are still honored.
  • A project ID is not required (it is still resolved from the argument / config / GOOGLE_CLOUD_PROJECT when available).

This mirrors the Python client's use of anonymous credentials and an optional project when the emulator is active. Unlike the gRPC-based gems, storage does not use the :this_channel_is_insecure sentinel, since that is a gRPC concept; the REST equivalent is anonymous (nil) credentials, as already used by Google::Cloud::Storage.anonymous.

Changes

  • lib/google-cloud-storage.rb: register the emulator_host config field (defaulting to STORAGE_EMULATOR_HOST) and thread emulator_host: through the Google::Cloud.storage / Google::Cloud#storage convenience methods.
  • lib/google/cloud/storage.rb: add the emulator_host: keyword to Storage.new, connect anonymously to the emulator without requiring credentials or a project, and document the option.
  • test/google/cloud/storage_test.rb: unit tests covering the env var, the keyword argument, the config field, the optional project, and honoring explicitly-provided credentials.

Testing

  • test/google/cloud/storage_test.rb: 22 runs, 303 assertions, 0 failures.
  • Rubocop clean on the changed library files.

🤖 Generated with Claude Code

@SalvatoreT SalvatoreT requested review from a team and yoshi-approver as code owners June 8, 2026 18:27
@google-cla

google-cla Bot commented Jun 8, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@SalvatoreT SalvatoreT force-pushed the salvatoret/34022/support-storage-emulator-host branch from 9edc261 to fc95213 Compare June 8, 2026 18:31
Allow pointing the Storage client at a local emulator via the
STORAGE_EMULATOR_HOST environment variable, the emulator_host config
field, or an emulator_host keyword argument. When set, the client
connects to the emulator anonymously and does not require credentials
or a project ID.

Fixes googleapis#34022
@SalvatoreT SalvatoreT force-pushed the salvatoret/34022/support-storage-emulator-host branch from fc95213 to 0b6a94e Compare June 9, 2026 17:07
@SalvatoreT

Copy link
Copy Markdown
Author

Hey @cpriti-os @aandreassa @bajajneha27 if y'all are open to externally-authored PRs, would one of you be able to review this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support STORAGE_EMULATOR_HOST in the google-cloud-storage Gem

1 participant