{"action":"created","comment":{"url":"https://api.github.com/repos/snapcore/snapcraft/pulls/comments/75052525","id":75052525,"diff_hunk":"@@ -73,6 +75,84 @@ def logout():\n     logger.info('Credentials cleared.')\n \n \n+def _get_usable_secret_keys(query=None):\n+    ctx = gpgme.Context()\n+    for key in ctx.keylist(query, True):\n+        if not key.subkeys or not key.uids or key.disabled or not key.can_sign:\n+            continue\n+        mainkey = key.subkeys[0]\n+        if (mainkey.expired or mainkey.revoked or mainkey.disabled or\n+                mainkey.invalid):\n+            continue\n+        # We're currently only interested in RSA >= 4096-bit.\n+        if mainkey.pubkey_algo != gpgme.PK_RSA or mainkey.length < 4096:\n+            continue\n+        yield key\n+\n+\n+def _display_fingerprint(fingerprint):\n+    assert len(fingerprint) == 40\n+    chunks = [fingerprint[i:i + 4] for i in range(0, 40, 4)]\n+    return '{}  {}'.format(' '.join(chunks[:5]), ' '.join(chunks[5:]))\n+\n+\n+_display_key_algorithm = {\n+    gpgme.PK_RSA: 'R',\n+}\n+\n+\n+def _display_key(key):\n+    mainkey = key.subkeys[0]\n+    return '%d%s: %s' % (\n+        mainkey.length, _display_key_algorithm[mainkey.pubkey_algo],\n+        _display_fingerprint(mainkey.fpr))\n+\n+\n+def _select_key(keys):\n+    if len(keys) > 1:\n+        print('Select a key:')\n+        print()\n+        width = len(str(len(keys)))\n+        for i, key in enumerate(keys):\n+            print('{index:{width}d}. {key}'.format(\n+                index=i + 1, key=_display_key(key), width=width))\n+            print('{blank:{width}}  {uid}'.format(\n+                blank='', uid=key.uids[0].uid, width=width))\n+        print()\n+        while True:\n+            try:\n+                keynum = int(input('Key number: ')) - 1\n+            except ValueError:\n+                continue\n+            if keynum >= 0 and keynum < len(keys):\n+                return keys[keynum]\n+    else:\n+        return keys[0]\n+\n+\n+def register_key(query):\n+    keys = list(_get_usable_secret_keys(query=query))\n+    if not keys:\n+        raise RuntimeError(\n+            'You have no usable GPG secret keys matching \"{}\".'.format(query))\n+    key = _select_key(keys)\n+    fingerprint = key.subkeys[0].fpr\n+    ctx = gpgme.Context()","path":"snapcraft/_store.py","position":80,"original_position":80,"commit_id":"176be542e40d3e824f1073ddaa59236a6a9509f3","original_commit_id":"176be542e40d3e824f1073ddaa59236a6a9509f3","user":{"login":"elopio","id":617831,"avatar_url":"https://avatars.githubusercontent.com/u/617831?v=3","gravatar_id":"","url":"https://api.github.com/users/elopio","html_url":"https://github.com/elopio","followers_url":"https://api.github.com/users/elopio/followers","following_url":"https://api.github.com/users/elopio/following{/other_user}","gists_url":"https://api.github.com/users/elopio/gists{/gist_id}","starred_url":"https://api.github.com/users/elopio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elopio/subscriptions","organizations_url":"https://api.github.com/users/elopio/orgs","repos_url":"https://api.github.com/users/elopio/repos","events_url":"https://api.github.com/users/elopio/events{/privacy}","received_events_url":"https://api.github.com/users/elopio/received_events","type":"User","site_admin":false},"body":"s/ctx/context\r\nOn the line above I was wondering what fpr was, then I saw you assigned it to \"fingerprint\", that's lovely :D","created_at":"2016-08-17T02:00:35Z","updated_at":"2016-08-17T02:00:35Z","html_url":"https://github.com/snapcore/snapcraft/pull/726#discussion_r75052525","pull_request_url":"https://api.github.com/repos/snapcore/snapcraft/pulls/726","_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/comments/75052525"},"html":{"href":"https://github.com/snapcore/snapcraft/pull/726#discussion_r75052525"},"pull_request":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/726"}}},"pull_request":{"url":"https://api.github.com/repos/snapcore/snapcraft/pulls/726","id":81148260,"html_url":"https://github.com/snapcore/snapcraft/pull/726","diff_url":"https://github.com/snapcore/snapcraft/pull/726.diff","patch_url":"https://github.com/snapcore/snapcraft/pull/726.patch","issue_url":"https://api.github.com/repos/snapcore/snapcraft/issues/726","number":726,"state":"open","locked":false,"title":"Implement basic form of `snapcraft register-key`","user":{"login":"cjwatson","id":2429141,"avatar_url":"https://avatars.githubusercontent.com/u/2429141?v=3","gravatar_id":"","url":"https://api.github.com/users/cjwatson","html_url":"https://github.com/cjwatson","followers_url":"https://api.github.com/users/cjwatson/followers","following_url":"https://api.github.com/users/cjwatson/following{/other_user}","gists_url":"https://api.github.com/users/cjwatson/gists{/gist_id}","starred_url":"https://api.github.com/users/cjwatson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjwatson/subscriptions","organizations_url":"https://api.github.com/users/cjwatson/orgs","repos_url":"https://api.github.com/users/cjwatson/repos","events_url":"https://api.github.com/users/cjwatson/events{/privacy}","received_events_url":"https://api.github.com/users/cjwatson/received_events","type":"User","site_admin":false},"body":"This adds a basic register-key command that can be used to register keys\r\nfrom your GPG keyring.  At present, they must already be associated with\r\nyour Launchpad account, although after the work to move this to SSO is\r\ncompleted we'll be able to add such associations inline in snapcraft as\r\nwell.\r\n\r\nWe don't yet have all the prescribed error modes in place, and nor are\r\nwe able to tell which keys are already enabled.  That requires some more\r\nwork on the store side.","created_at":"2016-08-12T16:40:49Z","updated_at":"2016-08-17T02:00:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4c253c7f66758fdc3248ac41b2dc176b1d8854b6","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/snapcore/snapcraft/pulls/726/commits","review_comments_url":"https://api.github.com/repos/snapcore/snapcraft/pulls/726/comments","review_comment_url":"https://api.github.com/repos/snapcore/snapcraft/pulls/comments{/number}","comments_url":"https://api.github.com/repos/snapcore/snapcraft/issues/726/comments","statuses_url":"https://api.github.com/repos/snapcore/snapcraft/statuses/176be542e40d3e824f1073ddaa59236a6a9509f3","head":{"label":"cjwatson:register-key","ref":"register-key","sha":"176be542e40d3e824f1073ddaa59236a6a9509f3","user":{"login":"cjwatson","id":2429141,"avatar_url":"https://avatars.githubusercontent.com/u/2429141?v=3","gravatar_id":"","url":"https://api.github.com/users/cjwatson","html_url":"https://github.com/cjwatson","followers_url":"https://api.github.com/users/cjwatson/followers","following_url":"https://api.github.com/users/cjwatson/following{/other_user}","gists_url":"https://api.github.com/users/cjwatson/gists{/gist_id}","starred_url":"https://api.github.com/users/cjwatson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjwatson/subscriptions","organizations_url":"https://api.github.com/users/cjwatson/orgs","repos_url":"https://api.github.com/users/cjwatson/repos","events_url":"https://api.github.com/users/cjwatson/events{/privacy}","received_events_url":"https://api.github.com/users/cjwatson/received_events","type":"User","site_admin":false},"repo":{"id":62801718,"name":"snapcraft","full_name":"cjwatson/snapcraft","owner":{"login":"cjwatson","id":2429141,"avatar_url":"https://avatars.githubusercontent.com/u/2429141?v=3","gravatar_id":"","url":"https://api.github.com/users/cjwatson","html_url":"https://github.com/cjwatson","followers_url":"https://api.github.com/users/cjwatson/followers","following_url":"https://api.github.com/users/cjwatson/following{/other_user}","gists_url":"https://api.github.com/users/cjwatson/gists{/gist_id}","starred_url":"https://api.github.com/users/cjwatson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjwatson/subscriptions","organizations_url":"https://api.github.com/users/cjwatson/orgs","repos_url":"https://api.github.com/users/cjwatson/repos","events_url":"https://api.github.com/users/cjwatson/events{/privacy}","received_events_url":"https://api.github.com/users/cjwatson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cjwatson/snapcraft","description":"Snapcraft is a delightful packaging tool","fork":true,"url":"https://api.github.com/repos/cjwatson/snapcraft","forks_url":"https://api.github.com/repos/cjwatson/snapcraft/forks","keys_url":"https://api.github.com/repos/cjwatson/snapcraft/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cjwatson/snapcraft/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cjwatson/snapcraft/teams","hooks_url":"https://api.github.com/repos/cjwatson/snapcraft/hooks","issue_events_url":"https://api.github.com/repos/cjwatson/snapcraft/issues/events{/number}","events_url":"https://api.github.com/repos/cjwatson/snapcraft/events","assignees_url":"https://api.github.com/repos/cjwatson/snapcraft/assignees{/user}","branches_url":"https://api.github.com/repos/cjwatson/snapcraft/branches{/branch}","tags_url":"https://api.github.com/repos/cjwatson/snapcraft/tags","blobs_url":"https://api.github.com/repos/cjwatson/snapcraft/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cjwatson/snapcraft/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cjwatson/snapcraft/git/refs{/sha}","trees_url":"https://api.github.com/repos/cjwatson/snapcraft/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cjwatson/snapcraft/statuses/{sha}","languages_url":"https://api.github.com/repos/cjwatson/snapcraft/languages","stargazers_url":"https://api.github.com/repos/cjwatson/snapcraft/stargazers","contributors_url":"https://api.github.com/repos/cjwatson/snapcraft/contributors","subscribers_url":"https://api.github.com/repos/cjwatson/snapcraft/subscribers","subscription_url":"https://api.github.com/repos/cjwatson/snapcraft/subscription","commits_url":"https://api.github.com/repos/cjwatson/snapcraft/commits{/sha}","git_commits_url":"https://api.github.com/repos/cjwatson/snapcraft/git/commits{/sha}","comments_url":"https://api.github.com/repos/cjwatson/snapcraft/comments{/number}","issue_comment_url":"https://api.github.com/repos/cjwatson/snapcraft/issues/comments{/number}","contents_url":"https://api.github.com/repos/cjwatson/snapcraft/contents/{+path}","compare_url":"https://api.github.com/repos/cjwatson/snapcraft/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cjwatson/snapcraft/merges","archive_url":"https://api.github.com/repos/cjwatson/snapcraft/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cjwatson/snapcraft/downloads","issues_url":"https://api.github.com/repos/cjwatson/snapcraft/issues{/number}","pulls_url":"https://api.github.com/repos/cjwatson/snapcraft/pulls{/number}","milestones_url":"https://api.github.com/repos/cjwatson/snapcraft/milestones{/number}","notifications_url":"https://api.github.com/repos/cjwatson/snapcraft/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cjwatson/snapcraft/labels{/name}","releases_url":"https://api.github.com/repos/cjwatson/snapcraft/releases{/id}","deployments_url":"https://api.github.com/repos/cjwatson/snapcraft/deployments","created_at":"2016-07-07T11:29:03Z","updated_at":"2016-07-07T11:29:04Z","pushed_at":"2016-08-12T16:41:51Z","git_url":"git://github.com/cjwatson/snapcraft.git","ssh_url":"git@github.com:cjwatson/snapcraft.git","clone_url":"https://github.com/cjwatson/snapcraft.git","svn_url":"https://github.com/cjwatson/snapcraft","homepage":null,"size":4634,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"snapcore:master","ref":"master","sha":"a2358fcd0503343b0e27fa9a5d9fc7729ece62d8","user":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars.githubusercontent.com/u/19532717?v=3","gravatar_id":"","url":"https://api.github.com/users/snapcore","html_url":"https://github.com/snapcore","followers_url":"https://api.github.com/users/snapcore/followers","following_url":"https://api.github.com/users/snapcore/following{/other_user}","gists_url":"https://api.github.com/users/snapcore/gists{/gist_id}","starred_url":"https://api.github.com/users/snapcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snapcore/subscriptions","organizations_url":"https://api.github.com/users/snapcore/orgs","repos_url":"https://api.github.com/users/snapcore/repos","events_url":"https://api.github.com/users/snapcore/events{/privacy}","received_events_url":"https://api.github.com/users/snapcore/received_events","type":"Organization","site_admin":false},"repo":{"id":45199136,"name":"snapcraft","full_name":"snapcore/snapcraft","owner":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars.githubusercontent.com/u/19532717?v=3","gravatar_id":"","url":"https://api.github.com/users/snapcore","html_url":"https://github.com/snapcore","followers_url":"https://api.github.com/users/snapcore/followers","following_url":"https://api.github.com/users/snapcore/following{/other_user}","gists_url":"https://api.github.com/users/snapcore/gists{/gist_id}","starred_url":"https://api.github.com/users/snapcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snapcore/subscriptions","organizations_url":"https://api.github.com/users/snapcore/orgs","repos_url":"https://api.github.com/users/snapcore/repos","events_url":"https://api.github.com/users/snapcore/events{/privacy}","received_events_url":"https://api.github.com/users/snapcore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/snapcore/snapcraft","description":"Snapcraft is a delightful packaging tool","fork":false,"url":"https://api.github.com/repos/snapcore/snapcraft","forks_url":"https://api.github.com/repos/snapcore/snapcraft/forks","keys_url":"https://api.github.com/repos/snapcore/snapcraft/keys{/key_id}","collaborators_url":"https://api.github.com/repos/snapcore/snapcraft/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/snapcore/snapcraft/teams","hooks_url":"https://api.github.com/repos/snapcore/snapcraft/hooks","issue_events_url":"https://api.github.com/repos/snapcore/snapcraft/issues/events{/number}","events_url":"https://api.github.com/repos/snapcore/snapcraft/events","assignees_url":"https://api.github.com/repos/snapcore/snapcraft/assignees{/user}","branches_url":"https://api.github.com/repos/snapcore/snapcraft/branches{/branch}","tags_url":"https://api.github.com/repos/snapcore/snapcraft/tags","blobs_url":"https://api.github.com/repos/snapcore/snapcraft/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/snapcore/snapcraft/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/snapcore/snapcraft/git/refs{/sha}","trees_url":"https://api.github.com/repos/snapcore/snapcraft/git/trees{/sha}","statuses_url":"https://api.github.com/repos/snapcore/snapcraft/statuses/{sha}","languages_url":"https://api.github.com/repos/snapcore/snapcraft/languages","stargazers_url":"https://api.github.com/repos/snapcore/snapcraft/stargazers","contributors_url":"https://api.github.com/repos/snapcore/snapcraft/contributors","subscribers_url":"https://api.github.com/repos/snapcore/snapcraft/subscribers","subscription_url":"https://api.github.com/repos/snapcore/snapcraft/subscription","commits_url":"https://api.github.com/repos/snapcore/snapcraft/commits{/sha}","git_commits_url":"https://api.github.com/repos/snapcore/snapcraft/git/commits{/sha}","comments_url":"https://api.github.com/repos/snapcore/snapcraft/comments{/number}","issue_comment_url":"https://api.github.com/repos/snapcore/snapcraft/issues/comments{/number}","contents_url":"https://api.github.com/repos/snapcore/snapcraft/contents/{+path}","compare_url":"https://api.github.com/repos/snapcore/snapcraft/compare/{base}...{head}","merges_url":"https://api.github.com/repos/snapcore/snapcraft/merges","archive_url":"https://api.github.com/repos/snapcore/snapcraft/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/snapcore/snapcraft/downloads","issues_url":"https://api.github.com/repos/snapcore/snapcraft/issues{/number}","pulls_url":"https://api.github.com/repos/snapcore/snapcraft/pulls{/number}","milestones_url":"https://api.github.com/repos/snapcore/snapcraft/milestones{/number}","notifications_url":"https://api.github.com/repos/snapcore/snapcraft/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/snapcore/snapcraft/labels{/name}","releases_url":"https://api.github.com/repos/snapcore/snapcraft/releases{/id}","deployments_url":"https://api.github.com/repos/snapcore/snapcraft/deployments","created_at":"2015-10-29T17:23:15Z","updated_at":"2016-08-16T12:03:14Z","pushed_at":"2016-08-17T01:56:49Z","git_url":"git://github.com/snapcore/snapcraft.git","ssh_url":"git@github.com:snapcore/snapcraft.git","clone_url":"https://github.com/snapcore/snapcraft.git","svn_url":"https://github.com/snapcore/snapcraft","homepage":null,"size":6872,"stargazers_count":202,"watchers_count":202,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":108,"mirror_url":null,"open_issues_count":21,"forks":108,"open_issues":21,"watchers":202,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/726"},"html":{"href":"https://github.com/snapcore/snapcraft/pull/726"},"issue":{"href":"https://api.github.com/repos/snapcore/snapcraft/issues/726"},"comments":{"href":"https://api.github.com/repos/snapcore/snapcraft/issues/726/comments"},"review_comments":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/726/comments"},"review_comment":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/726/commits"},"statuses":{"href":"https://api.github.com/repos/snapcore/snapcraft/statuses/176be542e40d3e824f1073ddaa59236a6a9509f3"}}}}
{"actor":{"display_login":"elopio"}}