{"action":"created","comment":{"url":"https://api.github.com/repos/docker/notary/pulls/comments/53199680","id":53199680,"diff_hunk":"@@ -51,34 +148,64 @@ func (s *KeyFileStore) Name() string {\n }\n \n // AddKey stores the contents of a PEM-encoded private key as a PEM block\n-func (s *KeyFileStore) AddKey(name, role string, privKey data.PrivateKey) error {\n+func (s *KeyFileStore) AddKey(privKey data.PrivateKey, keyInfo KeyInfo) error {\n \ts.Lock()\n \tdefer s.Unlock()\n-\treturn addKey(s, s.Retriever, s.cachedKeys, name, role, privKey)\n+\tif keyInfo.Role == data.CanonicalRootRole || data.IsDelegation(keyInfo.Role) || !data.ValidRole(keyInfo.Role) {\n+\t\tkeyInfo.Gun = \"\"\n+\t}\n+\terr := addKey(s, s.Retriever, s.cachedKeys, filepath.Join(keyInfo.Gun, privKey.ID()), keyInfo.Role, privKey)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\ts.keyInfoMap[privKey.ID()] = keyInfo\n+\treturn nil\n }\n \n // GetKey returns the PrivateKey given a KeyID\n func (s *KeyFileStore) GetKey(name string) (data.PrivateKey, string, error) {\n \ts.Lock()\n \tdefer s.Unlock()\n+\t// If this is a bare key ID without the gun, prepend the gun so the filestore lookup succeeds\n+\tif keyInfo, ok := s.keyInfoMap[name]; ok {\n+\t\tname = filepath.Join(keyInfo.Gun, name)\n+\t}\n \treturn getKey(s, s.Retriever, s.cachedKeys, name)\n }\n \n // ListKeys returns a list of unique PublicKeys present on the KeyFileStore.\n-func (s *KeyFileStore) ListKeys() map[string]string {\n-\treturn listKeys(s)\n+func (s *KeyFileStore) ListKeys() map[string]KeyInfo {\n+\treturn s.keyInfoMap","path":"trustmanager/keyfilestore.go","position":165,"original_position":165,"commit_id":"b7a438e7209e24cc4f63c54bec50e08de56f2b53","original_commit_id":"b7a438e7209e24cc4f63c54bec50e08de56f2b53","user":{"login":"riyazdf","id":1865981,"avatar_url":"https://avatars.githubusercontent.com/u/1865981?v=3","gravatar_id":"","url":"https://api.github.com/users/riyazdf","html_url":"https://github.com/riyazdf","followers_url":"https://api.github.com/users/riyazdf/followers","following_url":"https://api.github.com/users/riyazdf/following{/other_user}","gists_url":"https://api.github.com/users/riyazdf/gists{/gist_id}","starred_url":"https://api.github.com/users/riyazdf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/riyazdf/subscriptions","organizations_url":"https://api.github.com/users/riyazdf/orgs","repos_url":"https://api.github.com/users/riyazdf/repos","events_url":"https://api.github.com/users/riyazdf/events{/privacy}","received_events_url":"https://api.github.com/users/riyazdf/received_events","type":"User","site_admin":false},"body":"Good idea, `ListKeys` should never be used to modify state so I'll change this!","created_at":"2016-02-17T17:30:07Z","updated_at":"2016-02-17T17:30:07Z","html_url":"https://github.com/docker/notary/pull/552#discussion_r53199680","pull_request_url":"https://api.github.com/repos/docker/notary/pulls/552","_links":{"self":{"href":"https://api.github.com/repos/docker/notary/pulls/comments/53199680"},"html":{"href":"https://github.com/docker/notary/pull/552#discussion_r53199680"},"pull_request":{"href":"https://api.github.com/repos/docker/notary/pulls/552"}}},"pull_request":{"url":"https://api.github.com/repos/docker/notary/pulls/552","id":58501169,"html_url":"https://github.com/docker/notary/pull/552","diff_url":"https://github.com/docker/notary/pull/552.diff","patch_url":"https://github.com/docker/notary/pull/552.patch","issue_url":"https://api.github.com/repos/docker/notary/issues/552","number":552,"state":"open","locked":false,"title":"Flatten keystore by adding key info map","user":{"login":"riyazdf","id":1865981,"avatar_url":"https://avatars.githubusercontent.com/u/1865981?v=3","gravatar_id":"","url":"https://api.github.com/users/riyazdf","html_url":"https://github.com/riyazdf","followers_url":"https://api.github.com/users/riyazdf/followers","following_url":"https://api.github.com/users/riyazdf/following{/other_user}","gists_url":"https://api.github.com/users/riyazdf/gists{/gist_id}","starred_url":"https://api.github.com/users/riyazdf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/riyazdf/subscriptions","organizations_url":"https://api.github.com/users/riyazdf/orgs","repos_url":"https://api.github.com/users/riyazdf/repos","events_url":"https://api.github.com/users/riyazdf/events{/privacy}","received_events_url":"https://api.github.com/users/riyazdf/received_events","type":"User","site_admin":false},"body":"This introduces a `keyInfo` map to the key store that maps key IDs to the key's role and GUN.  The underlying filestore/memorystore remains the same, but we can now call `GetKey` and `RemoveKey` without a gun for `targets` and `snapshot` keys.  \r\n\r\nThe tradeoff is that we have to initialize and load this map when creating our keystore, and keep it up to date as we add/remove keys.\r\n\r\nCloses #502 \r\n\r\nSigned-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>","created_at":"2016-02-05T23:54:57Z","updated_at":"2016-02-17T17:30:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"46fb9ffabed16436b273d0e1be81c804fe7b0a90","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/docker/notary/pulls/552/commits","review_comments_url":"https://api.github.com/repos/docker/notary/pulls/552/comments","review_comment_url":"https://api.github.com/repos/docker/notary/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/notary/issues/552/comments","statuses_url":"https://api.github.com/repos/docker/notary/statuses/b7a438e7209e24cc4f63c54bec50e08de56f2b53","head":{"label":"docker:flatten-keystore","ref":"flatten-keystore","sha":"b7a438e7209e24cc4f63c54bec50e08de56f2b53","user":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"repo":{"id":37743436,"name":"notary","full_name":"docker/notary","owner":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/docker/notary","description":"Notary is a Docker project that allows anyone to have trust over arbitrary collections of data","fork":false,"url":"https://api.github.com/repos/docker/notary","forks_url":"https://api.github.com/repos/docker/notary/forks","keys_url":"https://api.github.com/repos/docker/notary/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/notary/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/notary/teams","hooks_url":"https://api.github.com/repos/docker/notary/hooks","issue_events_url":"https://api.github.com/repos/docker/notary/issues/events{/number}","events_url":"https://api.github.com/repos/docker/notary/events","assignees_url":"https://api.github.com/repos/docker/notary/assignees{/user}","branches_url":"https://api.github.com/repos/docker/notary/branches{/branch}","tags_url":"https://api.github.com/repos/docker/notary/tags","blobs_url":"https://api.github.com/repos/docker/notary/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/notary/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/notary/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/notary/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/notary/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/notary/languages","stargazers_url":"https://api.github.com/repos/docker/notary/stargazers","contributors_url":"https://api.github.com/repos/docker/notary/contributors","subscribers_url":"https://api.github.com/repos/docker/notary/subscribers","subscription_url":"https://api.github.com/repos/docker/notary/subscription","commits_url":"https://api.github.com/repos/docker/notary/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/notary/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/notary/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/notary/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/notary/contents/{+path}","compare_url":"https://api.github.com/repos/docker/notary/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/notary/merges","archive_url":"https://api.github.com/repos/docker/notary/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/notary/downloads","issues_url":"https://api.github.com/repos/docker/notary/issues{/number}","pulls_url":"https://api.github.com/repos/docker/notary/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/notary/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/notary/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/notary/labels{/name}","releases_url":"https://api.github.com/repos/docker/notary/releases{/id}","deployments_url":"https://api.github.com/repos/docker/notary/deployments","created_at":"2015-06-19T20:07:53Z","updated_at":"2016-02-16T00:43:01Z","pushed_at":"2016-02-17T07:19:56Z","git_url":"git://github.com/docker/notary.git","ssh_url":"git@github.com:docker/notary.git","clone_url":"https://github.com/docker/notary.git","svn_url":"https://github.com/docker/notary","homepage":"https://docker.com","size":24189,"stargazers_count":479,"watchers_count":479,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":72,"mirror_url":null,"open_issues_count":91,"forks":72,"open_issues":91,"watchers":479,"default_branch":"master"}},"base":{"label":"docker:master","ref":"master","sha":"9010989a208abd414e0ab01e5a772045937a6098","user":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"repo":{"id":37743436,"name":"notary","full_name":"docker/notary","owner":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/docker/notary","description":"Notary is a Docker project that allows anyone to have trust over arbitrary collections of data","fork":false,"url":"https://api.github.com/repos/docker/notary","forks_url":"https://api.github.com/repos/docker/notary/forks","keys_url":"https://api.github.com/repos/docker/notary/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/notary/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/notary/teams","hooks_url":"https://api.github.com/repos/docker/notary/hooks","issue_events_url":"https://api.github.com/repos/docker/notary/issues/events{/number}","events_url":"https://api.github.com/repos/docker/notary/events","assignees_url":"https://api.github.com/repos/docker/notary/assignees{/user}","branches_url":"https://api.github.com/repos/docker/notary/branches{/branch}","tags_url":"https://api.github.com/repos/docker/notary/tags","blobs_url":"https://api.github.com/repos/docker/notary/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/notary/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/notary/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/notary/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/notary/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/notary/languages","stargazers_url":"https://api.github.com/repos/docker/notary/stargazers","contributors_url":"https://api.github.com/repos/docker/notary/contributors","subscribers_url":"https://api.github.com/repos/docker/notary/subscribers","subscription_url":"https://api.github.com/repos/docker/notary/subscription","commits_url":"https://api.github.com/repos/docker/notary/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/notary/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/notary/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/notary/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/notary/contents/{+path}","compare_url":"https://api.github.com/repos/docker/notary/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/notary/merges","archive_url":"https://api.github.com/repos/docker/notary/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/notary/downloads","issues_url":"https://api.github.com/repos/docker/notary/issues{/number}","pulls_url":"https://api.github.com/repos/docker/notary/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/notary/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/notary/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/notary/labels{/name}","releases_url":"https://api.github.com/repos/docker/notary/releases{/id}","deployments_url":"https://api.github.com/repos/docker/notary/deployments","created_at":"2015-06-19T20:07:53Z","updated_at":"2016-02-16T00:43:01Z","pushed_at":"2016-02-17T07:19:56Z","git_url":"git://github.com/docker/notary.git","ssh_url":"git@github.com:docker/notary.git","clone_url":"https://github.com/docker/notary.git","svn_url":"https://github.com/docker/notary","homepage":"https://docker.com","size":24189,"stargazers_count":479,"watchers_count":479,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":72,"mirror_url":null,"open_issues_count":91,"forks":72,"open_issues":91,"watchers":479,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/notary/pulls/552"},"html":{"href":"https://github.com/docker/notary/pull/552"},"issue":{"href":"https://api.github.com/repos/docker/notary/issues/552"},"comments":{"href":"https://api.github.com/repos/docker/notary/issues/552/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/notary/pulls/552/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/notary/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/notary/pulls/552/commits"},"statuses":{"href":"https://api.github.com/repos/docker/notary/statuses/b7a438e7209e24cc4f63c54bec50e08de56f2b53"}}}}