Title: Explore going the route of using Clients ? · Issue #861 · googleapis/google-cloud-python · GitHub
Open Graph Title: Explore going the route of using Clients ? · Issue #861 · googleapis/google-cloud-python
X Title: Explore going the route of using Clients ? · Issue #861 · googleapis/google-cloud-python
Description: 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 value...
Open Graph Description: 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 ...
X Description: 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 ...
Opengraph URL: https://github.com/googleapis/google-cloud-python/issues/861
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Explore going the route of using Clients ?","articleBody":"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....\n1. Changing the default values globally\n2. Making \"Connections\" a context manager (`with connection: # do something`)\n3. Creating the concept of a client\n\nWe do (1), are talking about doing (2), while the others tend to do (3) -- and comparing the code, I think (3) is the nicest. \n\ngcloud-node:\n\n``` javascript\nvar gcloud = require('gcloud');\nvar project1_storage = gcloud.storage({projectId: 'project1', keyFilename: '/path/to/key'});\nvar project2_storage_auto = gcloud.storage();\n\n# Do things with the two \"clients\"...\nbucket1 = project1_storage.get_bucket('bucket-1')\nbucket2 = project2_storage_auto.get_bucket('bucket2')\n```\n\ngcloud-ruby\n\n``` ruby\nrequire 'gcloud/storage'\nproject1_storage = Gcloud.storage \"project-id-1\" \"/path/to/key\"\nproject2_storage_auto = Gcloud.storage # Magically figure out the project ID and credentials\n\n# Do things with the two \"clients\"...\nbucket1 = project1_storage.find_bucket \"bucket-1\"\nbucket2 = project2_storage_auto.find_bucket \"bucket-2\"\n```\n\ngcloud-python\n\n``` python\nfrom gcloud import storage\nfrom gcloud.credentials import get_for_service_account_json\n\n# Create two different credentials.\ncredentials1 = get_for_service_account_json('key1.json')\ncredentials2 = get_for_service_account_json('key2.json')\n\n# Create two different connections.\nconnection1 = storage.Connection(credentials=credentials1)\nconnection2 = storage.Connection(credentials=credentials2)\n\n# Get two different buckets\nbucket1 = storage.get_bucket('bucket-1', project='project1', connection=connection1)\nbucket2 = storage.get_bucket('bucket-2', project='project2', connection=connection2)\n```\n\ngcloud-python if we followed the client pattern:\n\n``` python\nfrom gcloud import storage\n\nproject1_storage = storage.Client('project1', '/path/to/key')\nproject2_storage_auto = storage.Client()\n\n# Do things with the two \"clients\"...\nbucket1 = project1_storage.get_bucket('bucket-1')\nbucket2 = project2_storage_auto.get_bucket('bucket-2')\n```\n\nAnother option for gcloud-python using the client pattern:\n\n``` python\nimport gcloud\n\nproject1_storage = gcloud.storage('project1', '/path/to/key')\nproject2_storage_auto = gcloud.storage()\n\n# Do things with the two \"clients\"\nbucket1 = project1_storage.get_bucket('bucket-1')\nbucket2 = project2_storage_auto.get_bucket('bucket-2')\n```\n\n/cc @dhermes @tseaver \n","author":{"url":"https://github.com/jgeewax","@type":"Person","name":"jgeewax"},"datePublished":"2015-05-05T19:08:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":60},"url":"https://github.com/861/google-cloud-python/issues/861"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ce979f93-bba5-7645-cd0e-3afdc572c5a3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E20A:2992F:935CAF:C6741F:6A4DB2DF |
| html-safe-nonce | fd55bb7cedb5f8f3f7c5767d25d3c90a88855e2d4f62a60764411d3a874e1afb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjBBOjI5OTJGOjkzNUNBRjpDNjc0MUY6NkE0REIyREYiLCJ2aXNpdG9yX2lkIjoiNTQxMzMzOTY3MzE0NDQzOTUxOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | bd65a86006a36910e2009f020ddf1c03c99898829f94fe77ce8e20331c639783 |
| hovercard-subject-tag | issue:73402634 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/google-cloud-python/861/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ed15c97aaef661ea5d3867632a55ead12cf0d27ab89800b6ffa13dbcf36e3ffe/googleapis/google-cloud-python/issues/861 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ed15c97aaef661ea5d3867632a55ead12cf0d27ab89800b6ffa13dbcf36e3ffe/googleapis/google-cloud-python/issues/861 |
| og:image:alt | 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 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jgeewax |
| hostname | github.com |
| expected-hostname | github.com |
| None | 06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/google-cloud-python git https://github.com/googleapis/google-cloud-python.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 16316451 |
| octolytics-dimension-repository_nwo | googleapis/google-cloud-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 16316451 |
| octolytics-dimension-repository_network_root_nwo | googleapis/google-cloud-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 32f7b614aca06e6bbd89842b1370df1328264f68 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width