Skip to content

feat(storage): 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

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

Conversation

@SalvatoreT

@SalvatoreT SalvatoreT commented Jun 8, 2026 •

Copy link
Copy Markdown

Summary

Adds STORAGE_EMULATOR_HOST support to google-cloud-storage so the client can talk to a local Cloud Storage emulator. The Python client supports the same variable (googleapis/google-cloud-python#9219), and the Ruby pubsub, datastore, firestore, and bigtable gems already read their own *_EMULATOR_HOST variables.

Fixes #34022

Behavior

The emulator host can be set three ways, highest precedence first:

Google::Cloud::Storage.new emulator_host: "localhost:9000"
Google::Cloud::Storage.configure { |c| c.emulator_host = "localhost:9000" }
ENV["STORAGE_EMULATOR_HOST"] = "localhost:9000"

With an emulator host set:

  • Requests go to the emulator. A host without a scheme gets http://, and a trailing slash is added because the API client appends storage/v1/ to the root URL.
  • The client connects anonymously and skips the Application Default Credentials lookup. Credentials passed to Storage.new are still used.
  • A project ID is optional.
  • The emulator host overrides endpoint, like the other Ruby emulator-aware gems.
  • Storage.anonymous uses the emulator host from config or the environment.
  • A blank STORAGE_EMULATOR_HOST is treated as unset.

Storage is REST-based, so emulator mode uses nil credentials (as Storage.anonymous already does) instead of the gRPC :this_channel_is_insecure sentinel.

A new EMULATOR.md guide, linked from OVERVIEW.md, documents this.

Testing

  • storage_test.rb: the emulator tests build a real Storage::Service and assert on root_url. They cover the env var, argument, and config; bare and full hosts; a blank env var; no project; explicit credentials; precedence over endpoint; Storage.anonymous; and emulator_host passing through Google::Cloud#storage and Google::Cloud.storage.
  • bundle exec rake test: 985 runs, 0 failures.
  • Against fake-gcs-server 1.50.2 with STORAGE_EMULATOR_HOST=localhost:4443: created a bucket, uploaded (simple and resumable), listed, and downloaded.
  • No new rubocop offenses in 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 2 times, most recently 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?

@SalvatoreT
SalvatoreT force-pushed the salvatoret/34022/support-storage-emulator-host branch from 972a705 to 22c5979 Compare June 15, 2026 21:13
@bajajneha27 bajajneha27 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 9, 2026
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 9, 2026
Comment thread google-cloud-storage/lib/google/cloud/storage.rb Outdated
Comment thread google-cloud-storage/lib/google-cloud-storage.rb
Comment thread google-cloud-storage/test/google/cloud/storage_test.rb Outdated
Comment thread google-cloud-storage/test/google/cloud/storage_test.rb
Comment thread google-cloud-storage/lib/google-cloud-storage.rb
@SalvatoreT
SalvatoreT force-pushed the salvatoret/34022/support-storage-emulator-host branch from 22c5979 to 1f8e6d7 Compare October 26, 2026 22:06
@SalvatoreT SalvatoreT changed the title feat: support STORAGE_EMULATOR_HOST environment variable feat(storage): support STORAGE_EMULATOR_HOST environment variable Oct 26, 2026
Point the client at a local Cloud Storage emulator with the
STORAGE_EMULATOR_HOST environment variable, the emulator_host config
field, or the emulator_host argument to Storage.new. With an emulator
host set, the client connects anonymously unless credentials are passed,
doesn't require a project ID, and ignores the endpoint option.
Storage.anonymous also uses the emulator host.

A host without a scheme gets http://, and the root URL always ends in a
slash because the API client appends storage/v1/ to it. A blank
STORAGE_EMULATOR_HOST is treated as unset.

Fixes googleapis#34022
@SalvatoreT
SalvatoreT force-pushed the salvatoret/34022/support-storage-emulator-host branch from 1f8e6d7 to c00538c Compare October 26, 2026 22:10
@SalvatoreT
SalvatoreT requested a review from kalragauri October 26, 2026 22:18
@SalvatoreT

Copy link
Copy Markdown
Author

Ready for a second pass, @kalragauri!

This branch has not been deployed

No deployments
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

5 participants