After our last talk, there have been quite a few different ideas tossed around to make it clear and obvious which credentials and project IDs are in use during a particular API call, some of those have been....
- Changing the default values globally
- Making "Connections" a context manager (
with connection: # do something) - Creating the concept of a client
We do (1), are talking about doing (2), while the others tend to do (3) -- and comparing the code, I think (3) is the nicest.
gcloud-node:
vargcloud=require('gcloud');varproject1_storage=gcloud.storage({projectId: 'project1',keyFilename: '/path/to/key'});varproject2_storage_auto=gcloud.storage();
# Dothingswiththetwo"clients"...bucket1=project1_storage.get_bucket('bucket-1')bucket2=project2_storage_auto.get_bucket('bucket2')gcloud-ruby
require'gcloud/storage'project1_storage=Gcloud.storage"project-id-1""/path/to/key"project2_storage_auto=Gcloud.storage# Magically figure out the project ID and credentials# Do things with the two "clients"...bucket1=project1_storage.find_bucket"bucket-1"bucket2=project2_storage_auto.find_bucket"bucket-2"
gcloud-python
fromgcloudimportstoragefromgcloud.credentialsimportget_for_service_account_json# Create two different credentials.credentials1=get_for_service_account_json('key1.json')
credentials2=get_for_service_account_json('key2.json')
# Create two different connections.connection1=storage.Connection(credentials=credentials1)
connection2=storage.Connection(credentials=credentials2)
# Get two different bucketsbucket1=storage.get_bucket('bucket-1', project='project1', connection=connection1)
bucket2=storage.get_bucket('bucket-2', project='project2', connection=connection2)gcloud-python if we followed the client pattern:
fromgcloudimportstorageproject1_storage=storage.Client('project1', '/path/to/key')
project2_storage_auto=storage.Client()
# Do things with the two "clients"...bucket1=project1_storage.get_bucket('bucket-1')
bucket2=project2_storage_auto.get_bucket('bucket-2')Another option for gcloud-python using the client pattern:
importgcloudproject1_storage=gcloud.storage('project1', '/path/to/key')
project2_storage_auto=gcloud.storage()
# Do things with the two "clients"bucket1=project1_storage.get_bucket('bucket-1')
bucket2=project2_storage_auto.get_bucket('bucket-2')/cc @dhermes@tseaver
After our last talk, there have been quite a few different ideas tossed around to make it clear and obvious which credentials and project IDs are in use during a particular API call, some of those have been....
with connection: # do something)We do (1), are talking about doing (2), while the others tend to do (3) -- and comparing the code, I think (3) is the nicest.
gcloud-node:
gcloud-ruby
gcloud-python
gcloud-python if we followed the client pattern:
Another option for gcloud-python using the client pattern:
/cc @dhermes@tseaver