Search code examples
gsutilgoogle-cloud-sdk

gsutil rsync provide key at runtime


I am currently extending the functionality of a file transfer application to include Google Cloud synchronizations, however I'm running into an issue. In the backend, we are merely running gsutil rsync commands on a linux server.

The users of the application will need to sync to different Google Cloud repositories/buckets, and I'd like to be able to tell the command which credentials/key file to use per sync job. For example, gsutil rsync "/source/path" "gs://destination-bucket" --key "/usr/local/google-cloud-sdk/config/rss.key"

The AWS CLI has sync profiles that can be specified at runtime (eg, aws s3 sync "/source/path" "s3://destination-bucket" --profile sync_profile_1), but I can't seem to find anything similar with Google Cloud's CLI.

Any assistance would be appreciated.


Solution

  • The gsutil CLI uses Boto configs to load entire configuration files -- see these docs. You can tell gsutil to load additional Boto configs (i.e. to load several project- or key-specific settings) using the environment variables mentioned in the docs, or you can override individual config options using the top-level -o flag, as shown here.

    You'll probably want to override the Credentials:gs_service_key_file option. If you're not using a JSON keyfile, you'll also need to override the other options that start with gs_service_, as mentioned in the docs for gsutil config -e.