{"action":"created","comment":{"url":"https://api.github.com/repos/letsencrypt/boulder/pulls/comments/67534689","id":67534689,"diff_hunk":"@@ -0,0 +1,122 @@\n+package main\n+\n+import (\n+\t\"encoding/json\"\n+\t\"flag\"\n+\t\"fmt\"\n+\t\"io/ioutil\"\n+\t\"os\"\n+\t\"strings\"\n+\n+\t\"gopkg.in/gorp.v1\"\n+\n+\t\"github.com/jmhodges/clock\"\n+\t\"github.com/letsencrypt/boulder/cmd\"\n+\tblog \"github.com/letsencrypt/boulder/log\"\n+\t\"github.com/letsencrypt/boulder/sa\"\n+)\n+\n+type contactExporter struct {\n+\tlog   blog.Logger\n+\tdbMap *gorp.DbMap\n+\tclk   clock.Clock\n+}\n+\n+func (c contactExporter) findContacts() ([]string, error) {\n+\tvar contactsJSON []string\n+\tvar contacts []string\n+\n+\t_, err := c.dbMap.Select(\n+\t\t&contactsJSON,\n+\t\t`\n+\t\t\tSELECT DISTINCT (contact) AS active_contact\n+\t\t\tFROM registrations\n+\t\t\tWHERE contact != 'null' AND\n+\t\t\t\tid IN (\n+\t\t\t\t\tSELECT registrationID\n+\t\t\t\t\tFROM certificates\n+\t\t\t\t\tWHERE expires >= :expireCutoff\n+\t\t\t\t)\n+\t\t\t;\n+\t\t\t`,\n+\t\tmap[string]interface{}{\n+\t\t\t\"expireCutoff\": c.clk.Now(),\n+\t\t})\n+\tif err != nil {\n+\t\tc.log.AuditErr(fmt.Sprintf(\"contact-exporter: Error finding contacts: %s\", err))\n+\t\treturn nil, err\n+\t}\n+\n+\tfor _, contactRaw := range contactsJSON {\n+\t\tvar contactList []string\n+\t\terr := json.Unmarshal([]byte(contactRaw), &contactList)\n+\t\tif err != nil {\n+\t\t\tc.log.AuditErr(\n+\t\t\t\tfmt.Sprintf(\"contact-exporter: couldn't unmarshal contact JSON %#v: %s\\n\",\n+\t\t\t\t\tcontactRaw, err))\n+\t\t\tcontinue\n+\t\t}\n+\t\tfor _, entry := range contactList {\n+\t\t\t// Only include email addresses\n+\t\t\tif strings.HasPrefix(entry, \"mailto:\") {\n+\t\t\t\tcontacts = append(contacts, strings.TrimPrefix(entry, \"mailto:\"))\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\treturn contacts, nil\n+}\n+\n+func writeContacts(contacts []string, outFile string) error {\n+\tdata := []byte(strings.Join(contacts, \"\\n\"))\n+\n+\tif outFile != \"\" {\n+\t\treturn ioutil.WriteFile(outFile, data, 0644)\n+\t} else {\n+\t\tfmt.Printf(\"%s\", data)","path":"cmd/contact-exporter/main.go","position":76,"original_position":76,"commit_id":"d3031ea3cc79e846dab8a20eb76cc9a8fc3c8c0b","original_commit_id":"d3031ea3cc79e846dab8a20eb76cc9a8fc3c8c0b","user":{"login":"jsha","id":220205,"avatar_url":"https://avatars.githubusercontent.com/u/220205?v=3","gravatar_id":"","url":"https://api.github.com/users/jsha","html_url":"https://github.com/jsha","followers_url":"https://api.github.com/users/jsha/followers","following_url":"https://api.github.com/users/jsha/following{/other_user}","gists_url":"https://api.github.com/users/jsha/gists{/gist_id}","starred_url":"https://api.github.com/users/jsha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsha/subscriptions","organizations_url":"https://api.github.com/users/jsha/orgs","repos_url":"https://api.github.com/users/jsha/repos","events_url":"https://api.github.com/users/jsha/events{/privacy}","received_events_url":"https://api.github.com/users/jsha/received_events","type":"User","site_admin":false},"body":"Actually you might want to add the final newline as `strings.Join(...) + \"\\n\"` so both modes include it.","created_at":"2016-06-17T16:04:22Z","updated_at":"2016-06-17T16:04:22Z","html_url":"https://github.com/letsencrypt/boulder/pull/1939#discussion_r67534689","pull_request_url":"https://api.github.com/repos/letsencrypt/boulder/pulls/1939","_links":{"self":{"href":"https://api.github.com/repos/letsencrypt/boulder/pulls/comments/67534689"},"html":{"href":"https://github.com/letsencrypt/boulder/pull/1939#discussion_r67534689"},"pull_request":{"href":"https://api.github.com/repos/letsencrypt/boulder/pulls/1939"}}},"pull_request":{"url":"https://api.github.com/repos/letsencrypt/boulder/pulls/1939","id":74264093,"html_url":"https://github.com/letsencrypt/boulder/pull/1939","diff_url":"https://github.com/letsencrypt/boulder/pull/1939.diff","patch_url":"https://github.com/letsencrypt/boulder/pull/1939.patch","issue_url":"https://api.github.com/repos/letsencrypt/boulder/issues/1939","number":1939,"state":"open","locked":false,"title":"Add `contact-exporter` command","user":{"login":"ccppuu","id":292650,"avatar_url":"https://avatars.githubusercontent.com/u/292650?v=3","gravatar_id":"","url":"https://api.github.com/users/ccppuu","html_url":"https://github.com/ccppuu","followers_url":"https://api.github.com/users/ccppuu/followers","following_url":"https://api.github.com/users/ccppuu/following{/other_user}","gists_url":"https://api.github.com/users/ccppuu/gists{/gist_id}","starred_url":"https://api.github.com/users/ccppuu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ccppuu/subscriptions","organizations_url":"https://api.github.com/users/ccppuu/orgs","repos_url":"https://api.github.com/users/ccppuu/repos","events_url":"https://api.github.com/users/ccppuu/events{/privacy}","received_events_url":"https://api.github.com/users/ccppuu/received_events","type":"User","site_admin":false},"body":"For #1928 a `notify-mailer` command [was added](https://github.com/letsencrypt/boulder/pull/1936) to facilitate sending notification emails to a list of email addresses.\r\n\r\nThe other half of this use-case is generating the list of emails given to `notify-mailer` as input. This pull request adds a `contact-exporter` command that allows the operator to dump all of the contact email addresses from boulder into a text file or `stdout`.\r\n\r\nOnly contacts with at least one non-expired certificate will be exported. Similarly, only contacts that are a `mailto:` email address (e.g. not contacts with just a phone number) will be exported. \r\n\r\nA new read-only database user (`contact_exporter`) is created with `select` permissions on the two required tables (`certificates` and `registrations`) for use with the exporter tool.\r\n\r\nFuture work:\r\n* Support exporting registration IDs instead of email addresses\r\n","created_at":"2016-06-17T15:48:03Z","updated_at":"2016-06-17T16:04:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b2388df681f55bf2e6dd940850ae9d9147a6ee31","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/letsencrypt/boulder/pulls/1939/commits","review_comments_url":"https://api.github.com/repos/letsencrypt/boulder/pulls/1939/comments","review_comment_url":"https://api.github.com/repos/letsencrypt/boulder/pulls/comments{/number}","comments_url":"https://api.github.com/repos/letsencrypt/boulder/issues/1939/comments","statuses_url":"https://api.github.com/repos/letsencrypt/boulder/statuses/d3031ea3cc79e846dab8a20eb76cc9a8fc3c8c0b","head":{"label":"letsencrypt:cpu-contact-exporter","ref":"cpu-contact-exporter","sha":"d3031ea3cc79e846dab8a20eb76cc9a8fc3c8c0b","user":{"login":"letsencrypt","id":9289019,"avatar_url":"https://avatars.githubusercontent.com/u/9289019?v=3","gravatar_id":"","url":"https://api.github.com/users/letsencrypt","html_url":"https://github.com/letsencrypt","followers_url":"https://api.github.com/users/letsencrypt/followers","following_url":"https://api.github.com/users/letsencrypt/following{/other_user}","gists_url":"https://api.github.com/users/letsencrypt/gists{/gist_id}","starred_url":"https://api.github.com/users/letsencrypt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/letsencrypt/subscriptions","organizations_url":"https://api.github.com/users/letsencrypt/orgs","repos_url":"https://api.github.com/users/letsencrypt/repos","events_url":"https://api.github.com/users/letsencrypt/events{/privacy}","received_events_url":"https://api.github.com/users/letsencrypt/received_events","type":"Organization","site_admin":false},"repo":{"id":28283593,"name":"boulder","full_name":"letsencrypt/boulder","owner":{"login":"letsencrypt","id":9289019,"avatar_url":"https://avatars.githubusercontent.com/u/9289019?v=3","gravatar_id":"","url":"https://api.github.com/users/letsencrypt","html_url":"https://github.com/letsencrypt","followers_url":"https://api.github.com/users/letsencrypt/followers","following_url":"https://api.github.com/users/letsencrypt/following{/other_user}","gists_url":"https://api.github.com/users/letsencrypt/gists{/gist_id}","starred_url":"https://api.github.com/users/letsencrypt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/letsencrypt/subscriptions","organizations_url":"https://api.github.com/users/letsencrypt/orgs","repos_url":"https://api.github.com/users/letsencrypt/repos","events_url":"https://api.github.com/users/letsencrypt/events{/privacy}","received_events_url":"https://api.github.com/users/letsencrypt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/letsencrypt/boulder","description":"An ACME-based CA, written in Go.","fork":false,"url":"https://api.github.com/repos/letsencrypt/boulder","forks_url":"https://api.github.com/repos/letsencrypt/boulder/forks","keys_url":"https://api.github.com/repos/letsencrypt/boulder/keys{/key_id}","collaborators_url":"https://api.github.com/repos/letsencrypt/boulder/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/letsencrypt/boulder/teams","hooks_url":"https://api.github.com/repos/letsencrypt/boulder/hooks","issue_events_url":"https://api.github.com/repos/letsencrypt/boulder/issues/events{/number}","events_url":"https://api.github.com/repos/letsencrypt/boulder/events","assignees_url":"https://api.github.com/repos/letsencrypt/boulder/assignees{/user}","branches_url":"https://api.github.com/repos/letsencrypt/boulder/branches{/branch}","tags_url":"https://api.github.com/repos/letsencrypt/boulder/tags","blobs_url":"https://api.github.com/repos/letsencrypt/boulder/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/letsencrypt/boulder/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/letsencrypt/boulder/git/refs{/sha}","trees_url":"https://api.github.com/repos/letsencrypt/boulder/git/trees{/sha}","statuses_url":"https://api.github.com/repos/letsencrypt/boulder/statuses/{sha}","languages_url":"https://api.github.com/repos/letsencrypt/boulder/languages","stargazers_url":"https://api.github.com/repos/letsencrypt/boulder/stargazers","contributors_url":"https://api.github.com/repos/letsencrypt/boulder/contributors","subscribers_url":"https://api.github.com/repos/letsencrypt/boulder/subscribers","subscription_url":"https://api.github.com/repos/letsencrypt/boulder/subscription","commits_url":"https://api.github.com/repos/letsencrypt/boulder/commits{/sha}","git_commits_url":"https://api.github.com/repos/letsencrypt/boulder/git/commits{/sha}","comments_url":"https://api.github.com/repos/letsencrypt/boulder/comments{/number}","issue_comment_url":"https://api.github.com/repos/letsencrypt/boulder/issues/comments{/number}","contents_url":"https://api.github.com/repos/letsencrypt/boulder/contents/{+path}","compare_url":"https://api.github.com/repos/letsencrypt/boulder/compare/{base}...{head}","merges_url":"https://api.github.com/repos/letsencrypt/boulder/merges","archive_url":"https://api.github.com/repos/letsencrypt/boulder/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/letsencrypt/boulder/downloads","issues_url":"https://api.github.com/repos/letsencrypt/boulder/issues{/number}","pulls_url":"https://api.github.com/repos/letsencrypt/boulder/pulls{/number}","milestones_url":"https://api.github.com/repos/letsencrypt/boulder/milestones{/number}","notifications_url":"https://api.github.com/repos/letsencrypt/boulder/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/letsencrypt/boulder/labels{/name}","releases_url":"https://api.github.com/repos/letsencrypt/boulder/releases{/id}","deployments_url":"https://api.github.com/repos/letsencrypt/boulder/deployments","created_at":"2014-12-21T00:29:54Z","updated_at":"2016-06-17T00:40:30Z","pushed_at":"2016-06-17T15:48:03Z","git_url":"git://github.com/letsencrypt/boulder.git","ssh_url":"git@github.com:letsencrypt/boulder.git","clone_url":"https://github.com/letsencrypt/boulder.git","svn_url":"https://github.com/letsencrypt/boulder","homepage":null,"size":22006,"stargazers_count":1246,"watchers_count":1246,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":155,"mirror_url":null,"open_issues_count":171,"forks":155,"open_issues":171,"watchers":1246,"default_branch":"master"}},"base":{"label":"letsencrypt:master","ref":"master","sha":"6bd97b2a6b28d84e342e2725dfbf4c981950d4d9","user":{"login":"letsencrypt","id":9289019,"avatar_url":"https://avatars.githubusercontent.com/u/9289019?v=3","gravatar_id":"","url":"https://api.github.com/users/letsencrypt","html_url":"https://github.com/letsencrypt","followers_url":"https://api.github.com/users/letsencrypt/followers","following_url":"https://api.github.com/users/letsencrypt/following{/other_user}","gists_url":"https://api.github.com/users/letsencrypt/gists{/gist_id}","starred_url":"https://api.github.com/users/letsencrypt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/letsencrypt/subscriptions","organizations_url":"https://api.github.com/users/letsencrypt/orgs","repos_url":"https://api.github.com/users/letsencrypt/repos","events_url":"https://api.github.com/users/letsencrypt/events{/privacy}","received_events_url":"https://api.github.com/users/letsencrypt/received_events","type":"Organization","site_admin":false},"repo":{"id":28283593,"name":"boulder","full_name":"letsencrypt/boulder","owner":{"login":"letsencrypt","id":9289019,"avatar_url":"https://avatars.githubusercontent.com/u/9289019?v=3","gravatar_id":"","url":"https://api.github.com/users/letsencrypt","html_url":"https://github.com/letsencrypt","followers_url":"https://api.github.com/users/letsencrypt/followers","following_url":"https://api.github.com/users/letsencrypt/following{/other_user}","gists_url":"https://api.github.com/users/letsencrypt/gists{/gist_id}","starred_url":"https://api.github.com/users/letsencrypt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/letsencrypt/subscriptions","organizations_url":"https://api.github.com/users/letsencrypt/orgs","repos_url":"https://api.github.com/users/letsencrypt/repos","events_url":"https://api.github.com/users/letsencrypt/events{/privacy}","received_events_url":"https://api.github.com/users/letsencrypt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/letsencrypt/boulder","description":"An ACME-based CA, written in Go.","fork":false,"url":"https://api.github.com/repos/letsencrypt/boulder","forks_url":"https://api.github.com/repos/letsencrypt/boulder/forks","keys_url":"https://api.github.com/repos/letsencrypt/boulder/keys{/key_id}","collaborators_url":"https://api.github.com/repos/letsencrypt/boulder/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/letsencrypt/boulder/teams","hooks_url":"https://api.github.com/repos/letsencrypt/boulder/hooks","issue_events_url":"https://api.github.com/repos/letsencrypt/boulder/issues/events{/number}","events_url":"https://api.github.com/repos/letsencrypt/boulder/events","assignees_url":"https://api.github.com/repos/letsencrypt/boulder/assignees{/user}","branches_url":"https://api.github.com/repos/letsencrypt/boulder/branches{/branch}","tags_url":"https://api.github.com/repos/letsencrypt/boulder/tags","blobs_url":"https://api.github.com/repos/letsencrypt/boulder/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/letsencrypt/boulder/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/letsencrypt/boulder/git/refs{/sha}","trees_url":"https://api.github.com/repos/letsencrypt/boulder/git/trees{/sha}","statuses_url":"https://api.github.com/repos/letsencrypt/boulder/statuses/{sha}","languages_url":"https://api.github.com/repos/letsencrypt/boulder/languages","stargazers_url":"https://api.github.com/repos/letsencrypt/boulder/stargazers","contributors_url":"https://api.github.com/repos/letsencrypt/boulder/contributors","subscribers_url":"https://api.github.com/repos/letsencrypt/boulder/subscribers","subscription_url":"https://api.github.com/repos/letsencrypt/boulder/subscription","commits_url":"https://api.github.com/repos/letsencrypt/boulder/commits{/sha}","git_commits_url":"https://api.github.com/repos/letsencrypt/boulder/git/commits{/sha}","comments_url":"https://api.github.com/repos/letsencrypt/boulder/comments{/number}","issue_comment_url":"https://api.github.com/repos/letsencrypt/boulder/issues/comments{/number}","contents_url":"https://api.github.com/repos/letsencrypt/boulder/contents/{+path}","compare_url":"https://api.github.com/repos/letsencrypt/boulder/compare/{base}...{head}","merges_url":"https://api.github.com/repos/letsencrypt/boulder/merges","archive_url":"https://api.github.com/repos/letsencrypt/boulder/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/letsencrypt/boulder/downloads","issues_url":"https://api.github.com/repos/letsencrypt/boulder/issues{/number}","pulls_url":"https://api.github.com/repos/letsencrypt/boulder/pulls{/number}","milestones_url":"https://api.github.com/repos/letsencrypt/boulder/milestones{/number}","notifications_url":"https://api.github.com/repos/letsencrypt/boulder/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/letsencrypt/boulder/labels{/name}","releases_url":"https://api.github.com/repos/letsencrypt/boulder/releases{/id}","deployments_url":"https://api.github.com/repos/letsencrypt/boulder/deployments","created_at":"2014-12-21T00:29:54Z","updated_at":"2016-06-17T00:40:30Z","pushed_at":"2016-06-17T15:48:03Z","git_url":"git://github.com/letsencrypt/boulder.git","ssh_url":"git@github.com:letsencrypt/boulder.git","clone_url":"https://github.com/letsencrypt/boulder.git","svn_url":"https://github.com/letsencrypt/boulder","homepage":null,"size":22006,"stargazers_count":1246,"watchers_count":1246,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":155,"mirror_url":null,"open_issues_count":171,"forks":155,"open_issues":171,"watchers":1246,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/letsencrypt/boulder/pulls/1939"},"html":{"href":"https://github.com/letsencrypt/boulder/pull/1939"},"issue":{"href":"https://api.github.com/repos/letsencrypt/boulder/issues/1939"},"comments":{"href":"https://api.github.com/repos/letsencrypt/boulder/issues/1939/comments"},"review_comments":{"href":"https://api.github.com/repos/letsencrypt/boulder/pulls/1939/comments"},"review_comment":{"href":"https://api.github.com/repos/letsencrypt/boulder/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/letsencrypt/boulder/pulls/1939/commits"},"statuses":{"href":"https://api.github.com/repos/letsencrypt/boulder/statuses/d3031ea3cc79e846dab8a20eb76cc9a8fc3c8c0b"}}}}
{"actor":{"display_login":"jsha"}}