{"action":"created","comment":{"url":"https://api.github.com/repos/riyazdf/cli/pulls/comments/132578638","pull_request_review_id":55676088,"id":132578638,"diff_hunk":"@@ -1,17 +1,152 @@\n package trust\n \n import (\n+\t\"fmt\"\n+\t\"io\"\n+\t\"os\"\n+\t\"strings\"\n+\n+\t\"github.com/docker/notary/client\"\n+\t\"github.com/docker/notary/tuf/data\"\n+\n \t\"github.com/docker/cli/cli\"\n \t\"github.com/docker/cli/cli/command\"\n+\t\"github.com/docker/cli/cli/trust\"\n+\t\"github.com/docker/distribution/reference\"\n+\t\"github.com/docker/docker/api/types\"\n+\t\"github.com/docker/docker/registry\"\n \t\"github.com/spf13/cobra\"\n )\n \n func newRevokeCommand(dockerCli command.Cli) *cobra.Command {\n \tcmd := &cobra.Command{\n-\t\tUse:   \"revoke [OPTIONS]\",\n+\t\tUse:   \"revoke [OPTIONS] IMAGE[:TAG]\",\n \t\tShort: \"Remove trust for an image\",\n-\t\tArgs:  cli.NoArgs,\n-\t\tRunE:  command.ShowHelp(dockerCli.Err()),\n+\t\tArgs:  cli.ExactArgs(1),\n+\t\tRunE: func(cmd *cobra.Command, args []string) error {\n+\t\t\treturn revokeTrust(dockerCli, args[0])\n+\t\t},\n \t}\n \treturn cmd\n }\n+\n+func askConfirm(input io.Reader) bool {\n+\tvar res string\n+\tif _, err := fmt.Fscanln(input, &res); err != nil {\n+\t\treturn false\n+\t}\n+\tif strings.EqualFold(res, \"y\") || strings.EqualFold(res, \"yes\") {\n+\t\treturn true\n+\t}\n+\treturn false\n+}\n+\n+func revokeTrust(cli command.Cli, remote string) error {\n+\tref, repoInfo, authConfig, err := getImageReferencesAndAuth(cli, remote)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tswitch ref.(type) {\n+\tcase reference.Digested, reference.Canonical:\n+\t\treturn fmt.Errorf(\"cannot remove signature for digest\")\n+\tcase reference.NamedTagged:\n+\n+\t\tif err := revokeSingleSig(cli, ref.(reference.NamedTagged), repoInfo, *authConfig); err != nil {\n+\t\t\treturn fmt.Errorf(\"could not remove signature for %s: %s\", remote, err)\n+\t\t}\n+\t\tfmt.Fprintf(cli.Out(), \"Successfully deleted signature for %s\\n\", remote)\n+\t\treturn nil\n+\tdefault:\n+\t\tin := os.Stdin\n+\t\tfmt.Fprintf(\n+\t\t\tcli.Out(),\n+\t\t\t\"Please confirm you would like to delete all signature data for %s? (y/n)\\n\",\n+\t\t\tremote,\n+\t\t)\n+\t\t// TODO: Also add force (-y) flag\n+\t\tdeleteRemote := askConfirm(in)\n+\t\tif !deleteRemote {\n+\t\t\tfmt.Fprintf(cli.Out(), \"\\nAborting action.\\n\")\n+\t\t\treturn nil\n+\t\t}\n+\t\tif err := revokeAllSigs(cli, ref, repoInfo, *authConfig); err != nil {\n+\t\t\treturn fmt.Errorf(\"could not remove all signatures for %s: %s\", remote, err)\n+\t\t}\n+\n+\t\tfmt.Fprintf(cli.Out(), \"Successfully deleted all signature data for %s\\n\", remote)\n+\t\treturn nil\n+\t}\n+}\n+\n+func revokeSingleSig(cli command.Cli, ref reference.NamedTagged, repoInfo *registry.RepositoryInfo, authConfig types.AuthConfig) error {\n+\ttag := ref.Tag()\n+\t// TODO(riyazdf): can we allow for a memory changelist?\n+\tnotaryRepo, err := trust.GetNotaryRepository(cli, repoInfo, authConfig, \"push\", \"pull\")\n+\tif err != nil {\n+\t\treturn trust.NotaryError(ref.Name(), err)\n+\t}\n+\n+\t// Figure out which roles this is published to and which keys we have on-disk\n+\ttargetSigs, err := notaryRepo.GetAllTargetMetadataByName(tag)","path":"cli/command/trust/revoke.go","position":93,"original_position":93,"commit_id":"73e6db814cf77a83ceca5dee27d8ebde2a8fe02d","original_commit_id":"73e6db814cf77a83ceca5dee27d8ebde2a8fe02d","user":{"login":"riyazdf","id":1865981,"avatar_url":"https://avatars3.githubusercontent.com/u/1865981?v=4","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":"instead of doing this, we should use `GetSignableRoles` - this will do the key-matching against what the user has locally. ","created_at":"2017-08-10T21:58:07Z","updated_at":"2017-08-10T22:04:21Z","html_url":"https://github.com/riyazdf/cli/pull/34#discussion_r132578638","pull_request_url":"https://api.github.com/repos/riyazdf/cli/pulls/34","_links":{"self":{"href":"https://api.github.com/repos/riyazdf/cli/pulls/comments/132578638"},"html":{"href":"https://github.com/riyazdf/cli/pull/34#discussion_r132578638"},"pull_request":{"href":"https://api.github.com/repos/riyazdf/cli/pulls/34"}}},"pull_request":{"url":"https://api.github.com/repos/riyazdf/cli/pulls/34","id":134753675,"html_url":"https://github.com/riyazdf/cli/pull/34","diff_url":"https://github.com/riyazdf/cli/pull/34.diff","patch_url":"https://github.com/riyazdf/cli/pull/34.patch","issue_url":"https://api.github.com/repos/riyazdf/cli/issues/34","number":34,"state":"open","locked":false,"title":"[WIP] trust revoke","user":{"login":"ashfall","id":1138873,"avatar_url":"https://avatars2.githubusercontent.com/u/1138873?v=4","gravatar_id":"","url":"https://api.github.com/users/ashfall","html_url":"https://github.com/ashfall","followers_url":"https://api.github.com/users/ashfall/followers","following_url":"https://api.github.com/users/ashfall/following{/other_user}","gists_url":"https://api.github.com/users/ashfall/gists{/gist_id}","starred_url":"https://api.github.com/users/ashfall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashfall/subscriptions","organizations_url":"https://api.github.com/users/ashfall/orgs","repos_url":"https://api.github.com/users/ashfall/repos","events_url":"https://api.github.com/users/ashfall/events{/privacy}","received_events_url":"https://api.github.com/users/ashfall/received_events","type":"User","site_admin":false},"body":"Picking up where #30 left off. There are a bunch of TODOs in the code that I can address (either in this PR , or as separate tasks).\r\n\r\nUnit tests incoming. Here's example use:\r\n```\r\n $ ./build/docker-darwin-amd64 trust revoke ashfall/hw:v1\r\nEnter passphrase for repository key with ID 82985c9:\r\nSuccessfully deleted signature\r\n```\r\n\r\nand:\r\n\r\n```\r\n$ ./build/docker-darwin-amd64 trust revoke ashfall/hw\r\nPlease confirm you would like to delete all signature data for: docker.io/ashfall/hw (y/n)\r\ny\r\nSuccessfully deleted all signature data\r\n```","created_at":"2017-08-08T20:40:36Z","updated_at":"2017-08-10T22:04:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7761860673084a81a72034bf2595b9fb4963678f","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/riyazdf/cli/pulls/34/commits","review_comments_url":"https://api.github.com/repos/riyazdf/cli/pulls/34/comments","review_comment_url":"https://api.github.com/repos/riyazdf/cli/pulls/comments{/number}","comments_url":"https://api.github.com/repos/riyazdf/cli/issues/34/comments","statuses_url":"https://api.github.com/repos/riyazdf/cli/statuses/73e6db814cf77a83ceca5dee27d8ebde2a8fe02d","head":{"label":"ashfall:trust-revoke-1","ref":"trust-revoke-1","sha":"73e6db814cf77a83ceca5dee27d8ebde2a8fe02d","user":{"login":"ashfall","id":1138873,"avatar_url":"https://avatars2.githubusercontent.com/u/1138873?v=4","gravatar_id":"","url":"https://api.github.com/users/ashfall","html_url":"https://github.com/ashfall","followers_url":"https://api.github.com/users/ashfall/followers","following_url":"https://api.github.com/users/ashfall/following{/other_user}","gists_url":"https://api.github.com/users/ashfall/gists{/gist_id}","starred_url":"https://api.github.com/users/ashfall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashfall/subscriptions","organizations_url":"https://api.github.com/users/ashfall/orgs","repos_url":"https://api.github.com/users/ashfall/repos","events_url":"https://api.github.com/users/ashfall/events{/privacy}","received_events_url":"https://api.github.com/users/ashfall/received_events","type":"User","site_admin":false},"repo":{"id":97765983,"name":"cli","full_name":"ashfall/cli","owner":{"login":"ashfall","id":1138873,"avatar_url":"https://avatars2.githubusercontent.com/u/1138873?v=4","gravatar_id":"","url":"https://api.github.com/users/ashfall","html_url":"https://github.com/ashfall","followers_url":"https://api.github.com/users/ashfall/followers","following_url":"https://api.github.com/users/ashfall/following{/other_user}","gists_url":"https://api.github.com/users/ashfall/gists{/gist_id}","starred_url":"https://api.github.com/users/ashfall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashfall/subscriptions","organizations_url":"https://api.github.com/users/ashfall/orgs","repos_url":"https://api.github.com/users/ashfall/repos","events_url":"https://api.github.com/users/ashfall/events{/privacy}","received_events_url":"https://api.github.com/users/ashfall/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ashfall/cli","description":"The Docker CLI","fork":true,"url":"https://api.github.com/repos/ashfall/cli","forks_url":"https://api.github.com/repos/ashfall/cli/forks","keys_url":"https://api.github.com/repos/ashfall/cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ashfall/cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ashfall/cli/teams","hooks_url":"https://api.github.com/repos/ashfall/cli/hooks","issue_events_url":"https://api.github.com/repos/ashfall/cli/issues/events{/number}","events_url":"https://api.github.com/repos/ashfall/cli/events","assignees_url":"https://api.github.com/repos/ashfall/cli/assignees{/user}","branches_url":"https://api.github.com/repos/ashfall/cli/branches{/branch}","tags_url":"https://api.github.com/repos/ashfall/cli/tags","blobs_url":"https://api.github.com/repos/ashfall/cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ashfall/cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ashfall/cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/ashfall/cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ashfall/cli/statuses/{sha}","languages_url":"https://api.github.com/repos/ashfall/cli/languages","stargazers_url":"https://api.github.com/repos/ashfall/cli/stargazers","contributors_url":"https://api.github.com/repos/ashfall/cli/contributors","subscribers_url":"https://api.github.com/repos/ashfall/cli/subscribers","subscription_url":"https://api.github.com/repos/ashfall/cli/subscription","commits_url":"https://api.github.com/repos/ashfall/cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/ashfall/cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/ashfall/cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/ashfall/cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/ashfall/cli/contents/{+path}","compare_url":"https://api.github.com/repos/ashfall/cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ashfall/cli/merges","archive_url":"https://api.github.com/repos/ashfall/cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ashfall/cli/downloads","issues_url":"https://api.github.com/repos/ashfall/cli/issues{/number}","pulls_url":"https://api.github.com/repos/ashfall/cli/pulls{/number}","milestones_url":"https://api.github.com/repos/ashfall/cli/milestones{/number}","notifications_url":"https://api.github.com/repos/ashfall/cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ashfall/cli/labels{/name}","releases_url":"https://api.github.com/repos/ashfall/cli/releases{/id}","deployments_url":"https://api.github.com/repos/ashfall/cli/deployments","created_at":"2017-07-19T22:18:43Z","updated_at":"2017-07-19T22:18:46Z","pushed_at":"2017-08-10T21:53:06Z","git_url":"git://github.com/ashfall/cli.git","ssh_url":"git@github.com:ashfall/cli.git","clone_url":"https://github.com/ashfall/cli.git","svn_url":"https://github.com/ashfall/cli","homepage":null,"size":12301,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"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":"riyazdf:master","ref":"master","sha":"05c43ea9fe739bd4637563fe09f19aab5b65a1ce","user":{"login":"riyazdf","id":1865981,"avatar_url":"https://avatars3.githubusercontent.com/u/1865981?v=4","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},"repo":{"id":97764796,"name":"cli","full_name":"riyazdf/cli","owner":{"login":"riyazdf","id":1865981,"avatar_url":"https://avatars3.githubusercontent.com/u/1865981?v=4","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},"private":false,"html_url":"https://github.com/riyazdf/cli","description":"The Docker CLI","fork":true,"url":"https://api.github.com/repos/riyazdf/cli","forks_url":"https://api.github.com/repos/riyazdf/cli/forks","keys_url":"https://api.github.com/repos/riyazdf/cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/riyazdf/cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/riyazdf/cli/teams","hooks_url":"https://api.github.com/repos/riyazdf/cli/hooks","issue_events_url":"https://api.github.com/repos/riyazdf/cli/issues/events{/number}","events_url":"https://api.github.com/repos/riyazdf/cli/events","assignees_url":"https://api.github.com/repos/riyazdf/cli/assignees{/user}","branches_url":"https://api.github.com/repos/riyazdf/cli/branches{/branch}","tags_url":"https://api.github.com/repos/riyazdf/cli/tags","blobs_url":"https://api.github.com/repos/riyazdf/cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/riyazdf/cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/riyazdf/cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/riyazdf/cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/riyazdf/cli/statuses/{sha}","languages_url":"https://api.github.com/repos/riyazdf/cli/languages","stargazers_url":"https://api.github.com/repos/riyazdf/cli/stargazers","contributors_url":"https://api.github.com/repos/riyazdf/cli/contributors","subscribers_url":"https://api.github.com/repos/riyazdf/cli/subscribers","subscription_url":"https://api.github.com/repos/riyazdf/cli/subscription","commits_url":"https://api.github.com/repos/riyazdf/cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/riyazdf/cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/riyazdf/cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/riyazdf/cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/riyazdf/cli/contents/{+path}","compare_url":"https://api.github.com/repos/riyazdf/cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/riyazdf/cli/merges","archive_url":"https://api.github.com/repos/riyazdf/cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/riyazdf/cli/downloads","issues_url":"https://api.github.com/repos/riyazdf/cli/issues{/number}","pulls_url":"https://api.github.com/repos/riyazdf/cli/pulls{/number}","milestones_url":"https://api.github.com/repos/riyazdf/cli/milestones{/number}","notifications_url":"https://api.github.com/repos/riyazdf/cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/riyazdf/cli/labels{/name}","releases_url":"https://api.github.com/repos/riyazdf/cli/releases{/id}","deployments_url":"https://api.github.com/repos/riyazdf/cli/deployments","created_at":"2017-07-19T21:59:18Z","updated_at":"2017-07-19T22:17:26Z","pushed_at":"2017-08-10T21:53:07Z","git_url":"git://github.com/riyazdf/cli.git","ssh_url":"git@github.com:riyazdf/cli.git","clone_url":"https://github.com/riyazdf/cli.git","svn_url":"https://github.com/riyazdf/cli","homepage":null,"size":12324,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":12,"forks":2,"open_issues":12,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/riyazdf/cli/pulls/34"},"html":{"href":"https://github.com/riyazdf/cli/pull/34"},"issue":{"href":"https://api.github.com/repos/riyazdf/cli/issues/34"},"comments":{"href":"https://api.github.com/repos/riyazdf/cli/issues/34/comments"},"review_comments":{"href":"https://api.github.com/repos/riyazdf/cli/pulls/34/comments"},"review_comment":{"href":"https://api.github.com/repos/riyazdf/cli/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/riyazdf/cli/pulls/34/commits"},"statuses":{"href":"https://api.github.com/repos/riyazdf/cli/statuses/73e6db814cf77a83ceca5dee27d8ebde2a8fe02d"}}}}
{"actor":{"display_login":"riyazdf"}}