{"action":"created","comment":{"url":"https://api.github.com/repos/google/apitools/pulls/comments/37330276","id":37330276,"diff_hunk":"@@ -48,65 +48,57 @@ def SetCredentialsCacheFileLock(lock):\n     cache_file_lock = lock\n \n \n-# TODO(craigcitro): Expose the extra args here somewhere higher up,\n-# possibly as flags in the generated CLI.\n+# List of additional methods we use when attempting to construct\n+# credentials. Users can register their own methods here, which we try\n+# before the defaults.\n+_CREDENTIALS_METHODS = []\n+\n+\n+def RegisterCredentialsMethod(method, position=None):\n+    \"\"\"Register a new method for fetching credentials.\n+\n+    This new method should be a function with signature:\n+      client_info, **kwds -> Credentials or None\n+    This method can be used as a decorator, unless position needs to\n+    be supplied.\n+\n+    Note that method must *always* accept arbitrary keyword arguments.\n+\n+    Args:\n+      method: New credential-fetching method.\n+      position: (default: None) Where in the list of methods to","path":"apitools/base/py/credentials_lib.py","position":24,"original_position":24,"commit_id":"a4200d6434320f1f32a5fe0e77084754312a5417","original_commit_id":"eb085b9d89a32a8576e6d1a41092b2b68241163c","user":{"login":"thobrla","id":3239120,"avatar_url":"https://avatars.githubusercontent.com/u/3239120?v=3","gravatar_id":"","url":"https://api.github.com/users/thobrla","html_url":"https://github.com/thobrla","followers_url":"https://api.github.com/users/thobrla/followers","following_url":"https://api.github.com/users/thobrla/following{/other_user}","gists_url":"https://api.github.com/users/thobrla/gists{/gist_id}","starred_url":"https://api.github.com/users/thobrla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thobrla/subscriptions","organizations_url":"https://api.github.com/users/thobrla/orgs","repos_url":"https://api.github.com/users/thobrla/repos","events_url":"https://api.github.com/users/thobrla/events{/privacy}","received_events_url":"https://api.github.com/users/thobrla/received_events","type":"User","site_admin":false},"body":"If the caller needs to control it to that extent, what do you think about returning a list of methods to the caller and requiring them to rebuild with their own order, possibly disincluding certain methods? Something along the lines of this, from the caller's perspective:\r\n\r\ndefault_methods = credentials_lib.GetCredentialsMethods()\r\nget_creds_methods = []\r\nget_creds_methods.append(default_methods['GetServiceAccountCredentials'])\r\nget_creds_methods.append(_UserSpecifiedCredentialsMethod)\r\nfor method_name, method in default_methods.iteritems():\r\n  if (method_name != 'GetServiceAccountCredentials' and\r\n      method_name != 'GetApplicationDefaultCredentials'):\r\n    get_creds_methods.append(method)\r\n\r\ncredentials_lib.SetCredentialsMethods(get_creds_methods)\r\n\r\nI don't think we can make it easy on the caller when apitools adds a new method, but at the least we could make the ordering explicit and centralized.","created_at":"2015-08-18T17:51:53Z","updated_at":"2015-08-18T17:51:53Z","html_url":"https://github.com/google/apitools/pull/46#discussion_r37330276","pull_request_url":"https://api.github.com/repos/google/apitools/pulls/46","_links":{"self":{"href":"https://api.github.com/repos/google/apitools/pulls/comments/37330276"},"html":{"href":"https://github.com/google/apitools/pull/46#discussion_r37330276"},"pull_request":{"href":"https://api.github.com/repos/google/apitools/pulls/46"}}},"pull_request":{"url":"https://api.github.com/repos/google/apitools/pulls/46","id":42532250,"html_url":"https://github.com/google/apitools/pull/46","diff_url":"https://github.com/google/apitools/pull/46.diff","patch_url":"https://github.com/google/apitools/pull/46.patch","issue_url":"https://api.github.com/repos/google/apitools/issues/46","number":46,"state":"open","locked":false,"title":"Add a system for registering credentials fetching methods.","user":{"login":"craigcitro","id":468559,"avatar_url":"https://avatars.githubusercontent.com/u/468559?v=3","gravatar_id":"","url":"https://api.github.com/users/craigcitro","html_url":"https://github.com/craigcitro","followers_url":"https://api.github.com/users/craigcitro/followers","following_url":"https://api.github.com/users/craigcitro/following{/other_user}","gists_url":"https://api.github.com/users/craigcitro/gists{/gist_id}","starred_url":"https://api.github.com/users/craigcitro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/craigcitro/subscriptions","organizations_url":"https://api.github.com/users/craigcitro/orgs","repos_url":"https://api.github.com/users/craigcitro/repos","events_url":"https://api.github.com/users/craigcitro/events{/privacy}","received_events_url":"https://api.github.com/users/craigcitro/received_events","type":"User","site_admin":false},"body":"This allows us to add new ways to fetch credentials that apitools itself need\r\nnot know about.\r\n\r\nPTAL @thobrla ","created_at":"2015-08-16T07:25:21Z","updated_at":"2015-08-18T17:51:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6e7190bcc555237d65335374043c95151cd84bc9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/google/apitools/pulls/46/commits","review_comments_url":"https://api.github.com/repos/google/apitools/pulls/46/comments","review_comment_url":"https://api.github.com/repos/google/apitools/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/apitools/issues/46/comments","statuses_url":"https://api.github.com/repos/google/apitools/statuses/a4200d6434320f1f32a5fe0e77084754312a5417","head":{"label":"craigcitro:register_creds","ref":"register_creds","sha":"a4200d6434320f1f32a5fe0e77084754312a5417","user":{"login":"craigcitro","id":468559,"avatar_url":"https://avatars.githubusercontent.com/u/468559?v=3","gravatar_id":"","url":"https://api.github.com/users/craigcitro","html_url":"https://github.com/craigcitro","followers_url":"https://api.github.com/users/craigcitro/followers","following_url":"https://api.github.com/users/craigcitro/following{/other_user}","gists_url":"https://api.github.com/users/craigcitro/gists{/gist_id}","starred_url":"https://api.github.com/users/craigcitro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/craigcitro/subscriptions","organizations_url":"https://api.github.com/users/craigcitro/orgs","repos_url":"https://api.github.com/users/craigcitro/repos","events_url":"https://api.github.com/users/craigcitro/events{/privacy}","received_events_url":"https://api.github.com/users/craigcitro/received_events","type":"User","site_admin":false},"repo":{"id":32879420,"name":"apitools","full_name":"craigcitro/apitools","owner":{"login":"craigcitro","id":468559,"avatar_url":"https://avatars.githubusercontent.com/u/468559?v=3","gravatar_id":"","url":"https://api.github.com/users/craigcitro","html_url":"https://github.com/craigcitro","followers_url":"https://api.github.com/users/craigcitro/followers","following_url":"https://api.github.com/users/craigcitro/following{/other_user}","gists_url":"https://api.github.com/users/craigcitro/gists{/gist_id}","starred_url":"https://api.github.com/users/craigcitro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/craigcitro/subscriptions","organizations_url":"https://api.github.com/users/craigcitro/orgs","repos_url":"https://api.github.com/users/craigcitro/repos","events_url":"https://api.github.com/users/craigcitro/events{/privacy}","received_events_url":"https://api.github.com/users/craigcitro/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/craigcitro/apitools","description":null,"fork":true,"url":"https://api.github.com/repos/craigcitro/apitools","forks_url":"https://api.github.com/repos/craigcitro/apitools/forks","keys_url":"https://api.github.com/repos/craigcitro/apitools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/craigcitro/apitools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/craigcitro/apitools/teams","hooks_url":"https://api.github.com/repos/craigcitro/apitools/hooks","issue_events_url":"https://api.github.com/repos/craigcitro/apitools/issues/events{/number}","events_url":"https://api.github.com/repos/craigcitro/apitools/events","assignees_url":"https://api.github.com/repos/craigcitro/apitools/assignees{/user}","branches_url":"https://api.github.com/repos/craigcitro/apitools/branches{/branch}","tags_url":"https://api.github.com/repos/craigcitro/apitools/tags","blobs_url":"https://api.github.com/repos/craigcitro/apitools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/craigcitro/apitools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/craigcitro/apitools/git/refs{/sha}","trees_url":"https://api.github.com/repos/craigcitro/apitools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/craigcitro/apitools/statuses/{sha}","languages_url":"https://api.github.com/repos/craigcitro/apitools/languages","stargazers_url":"https://api.github.com/repos/craigcitro/apitools/stargazers","contributors_url":"https://api.github.com/repos/craigcitro/apitools/contributors","subscribers_url":"https://api.github.com/repos/craigcitro/apitools/subscribers","subscription_url":"https://api.github.com/repos/craigcitro/apitools/subscription","commits_url":"https://api.github.com/repos/craigcitro/apitools/commits{/sha}","git_commits_url":"https://api.github.com/repos/craigcitro/apitools/git/commits{/sha}","comments_url":"https://api.github.com/repos/craigcitro/apitools/comments{/number}","issue_comment_url":"https://api.github.com/repos/craigcitro/apitools/issues/comments{/number}","contents_url":"https://api.github.com/repos/craigcitro/apitools/contents/{+path}","compare_url":"https://api.github.com/repos/craigcitro/apitools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/craigcitro/apitools/merges","archive_url":"https://api.github.com/repos/craigcitro/apitools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/craigcitro/apitools/downloads","issues_url":"https://api.github.com/repos/craigcitro/apitools/issues{/number}","pulls_url":"https://api.github.com/repos/craigcitro/apitools/pulls{/number}","milestones_url":"https://api.github.com/repos/craigcitro/apitools/milestones{/number}","notifications_url":"https://api.github.com/repos/craigcitro/apitools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/craigcitro/apitools/labels{/name}","releases_url":"https://api.github.com/repos/craigcitro/apitools/releases{/id}","created_at":"2015-03-25T17:15:38Z","updated_at":"2015-05-05T23:40:00Z","pushed_at":"2015-08-18T04:35:23Z","git_url":"git://github.com/craigcitro/apitools.git","ssh_url":"git@github.com:craigcitro/apitools.git","clone_url":"https://github.com/craigcitro/apitools.git","svn_url":"https://github.com/craigcitro/apitools","homepage":null,"size":735,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"google:master","ref":"master","sha":"5dca8372da3bc796fb313008716bb7b929572384","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":30675223,"name":"apitools","full_name":"google/apitools","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/apitools","description":null,"fork":false,"url":"https://api.github.com/repos/google/apitools","forks_url":"https://api.github.com/repos/google/apitools/forks","keys_url":"https://api.github.com/repos/google/apitools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/apitools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/apitools/teams","hooks_url":"https://api.github.com/repos/google/apitools/hooks","issue_events_url":"https://api.github.com/repos/google/apitools/issues/events{/number}","events_url":"https://api.github.com/repos/google/apitools/events","assignees_url":"https://api.github.com/repos/google/apitools/assignees{/user}","branches_url":"https://api.github.com/repos/google/apitools/branches{/branch}","tags_url":"https://api.github.com/repos/google/apitools/tags","blobs_url":"https://api.github.com/repos/google/apitools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/apitools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/apitools/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/apitools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/apitools/statuses/{sha}","languages_url":"https://api.github.com/repos/google/apitools/languages","stargazers_url":"https://api.github.com/repos/google/apitools/stargazers","contributors_url":"https://api.github.com/repos/google/apitools/contributors","subscribers_url":"https://api.github.com/repos/google/apitools/subscribers","subscription_url":"https://api.github.com/repos/google/apitools/subscription","commits_url":"https://api.github.com/repos/google/apitools/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/apitools/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/apitools/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/apitools/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/apitools/contents/{+path}","compare_url":"https://api.github.com/repos/google/apitools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/apitools/merges","archive_url":"https://api.github.com/repos/google/apitools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/apitools/downloads","issues_url":"https://api.github.com/repos/google/apitools/issues{/number}","pulls_url":"https://api.github.com/repos/google/apitools/pulls{/number}","milestones_url":"https://api.github.com/repos/google/apitools/milestones{/number}","notifications_url":"https://api.github.com/repos/google/apitools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/apitools/labels{/name}","releases_url":"https://api.github.com/repos/google/apitools/releases{/id}","created_at":"2015-02-11T23:27:13Z","updated_at":"2015-08-13T18:11:22Z","pushed_at":"2015-08-18T04:35:23Z","git_url":"git://github.com/google/apitools.git","ssh_url":"git@github.com:google/apitools.git","clone_url":"https://github.com/google/apitools.git","svn_url":"https://github.com/google/apitools","homepage":null,"size":910,"stargazers_count":14,"watchers_count":14,"language":"Python","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":12,"forks":13,"open_issues":12,"watchers":14,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/google/apitools/pulls/46"},"html":{"href":"https://github.com/google/apitools/pull/46"},"issue":{"href":"https://api.github.com/repos/google/apitools/issues/46"},"comments":{"href":"https://api.github.com/repos/google/apitools/issues/46/comments"},"review_comments":{"href":"https://api.github.com/repos/google/apitools/pulls/46/comments"},"review_comment":{"href":"https://api.github.com/repos/google/apitools/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/apitools/pulls/46/commits"},"statuses":{"href":"https://api.github.com/repos/google/apitools/statuses/a4200d6434320f1f32a5fe0e77084754312a5417"}}}}