Skip to content

Instantly share code, notes, and snippets.

@vsoch
Created July 1, 2018 17:05
Show Gist options
  • Save vsoch/70bf7de3c129931308237342941ef8b9 to your computer and use it in GitHub Desktop.
Save vsoch/70bf7de3c129931308237342941ef8b9 to your computer and use it in GitHub Desktop.
This snippet will help to debug the "cannot create or get bucket" error with the Singularity Registry client
# Test 1: Cannot Create Bucket
# Here is a set of commands to run to better explain the "Cannot get or create
# the group" error. I suspect the underlying issue is not having permissions to use storage.
# make sure these same variables are still exported
export GOOGLE_CLOUD_PROJECT=...
export GOOGLE_APPLICATION_CREDENTIALS="...
# You need to have storage admin permissions on this project
export SREGISTRY_GOOGLE_PROJECT=...
export SREGISTRY_GOOGLE_STORAGE_BUCKET=...
export SREGISTRY_CLIENT=google-compute
## Now open up an ipython shell
# if you have sregistry installed, you will have these dependencies
# ipython
from googleapiclient.discovery import build as discovery_build
from oauth2client.client import GoogleCredentials
from google.cloud import storage
import os
bucket_name = os.environ['SREGISTRY_GOOGLE_STORAGE_BUCKET']
# This is a client for storage, and our credentials from the environment
creds = GoogleCredentials.get_application_default()
# Now handles for interactions with storage and compute
# We are initializing the last two just to make sure no errors trigger
bucket_service = storage.Client()
storage_service = discovery_build('storage', 'v1', credentials=creds)
compute_service = discovery_build('compute', 'v1', credentials=creds)
# Here is where the error is going to trigger - tell me what message you get here
bucket = bucket_service.get_bucket(bucket_name)
# When I run this command (with correct permissions, and an existing bucket)
# I get back a bucket
# bucket
# <Bucket: sregistry-vanessa>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment