Skip to content

Instantly share code, notes, and snippets.

@makeittotop
Created March 23, 2015 11:04
Show Gist options
  • Save makeittotop/7908f417bddb7196a416 to your computer and use it in GitHub Desktop.
Save makeittotop/7908f417bddb7196a416 to your computer and use it in GitHub Desktop.
List all your google cloud storage bucket
# https://cloud.google.com/storage/docs/gspythonlibrary
# https://github.com/pyca/pyopenssl/issues/128
# faced issue with pyopenssl version 0.10 and 0.14 both on the system in different dirs, lib64 and lib respectively. Needed to remove
# lib64 one.
'''
In [1]: import OpenSSL
In [2]: OpenSSL.__version__
Out[2]: '0.14'
In [3]: OpenSSL.__file__
Out[3]: '/usr/lib/python2.6/site-packages/OpenSSL/__init__.pyc'
'''
# pip install gcs-oauth2-boto-plugin==1.8
# gsutil config -e
#!/usr/bin/env python
import boto
import gcs_oauth2_boto_plugin
import os
import shutil
import StringIO
import tempfile
import time
# URI scheme for Google Cloud Storage.
GOOGLE_STORAGE = 'gs'
# URI scheme for accessing local files.
LOCAL_FILE = 'file'
# Your project ID can be found at https://console.developers.google.com/
# If there is no domain for your project, then project_id = 'YOUR_PROJECT'
project_id = 'iron-atom-89306'
header_values = {"x-goog-project-id": project_id}
uri = boto.storage_uri('', GOOGLE_STORAGE)
# If the default project is defined, call get_all_buckets() without arguments.
for bucket in uri.get_all_buckets(headers=header_values):
print bucket.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment