{"action":"created","comment":{"url":"https://api.github.com/repos/cloudflare/cfssl/pulls/comments/46358063","id":46358063,"diff_hunk":"@@ -0,0 +1,209 @@\n+package pg\n+\n+import (\n+\t\"database/sql\"\n+\t\"errors\"\n+\t\"fmt\"\n+\t\"time\"\n+\n+\t\"github.com/cloudflare/cfssl/certdb\"\n+\tcferr \"github.com/cloudflare/cfssl/errors\"\n+\t\"github.com/kisielk/sqlstruct\"\n+)\n+\n+const (\n+\tinsertSQL = `\n+INSERT INTO certificates (serial, ca_label, status, reason, expiry, revoked_at, pem)\n+\tVALUES ($1, $2, $3, $4, $5, $6, $7);`\n+\n+\tselectSQL = `\n+SELECT %s FROM certificates\n+\tWHERE (serial = $1);`\n+\n+\tselectAllSQL = `\n+SELECT %s FROM certificates;`\n+\n+\tselectAllUnexpiredSQL = `\n+SELECT %s FROM certificates\n+WHERE current_timestamp < expiry;`\n+\n+\tupdateRevokeSQL = `\n+UPDATE certificates\n+\tSET status='revoked', revoked_at=current_timestamp, reason=$1\n+\tWHERE (serial = $2)`\n+\n+\tinsertOCSPSQL = `\n+INSERT INTO ocsp_responses (serial, body, expiry)\n+    VALUES ($1, $2, $3);`\n+\n+\tupdateOCSPSQL = `\n+UPDATE ocsp_responses\n+    SET expiry=$3, body=$2\n+\tWHERE (serial = $1);`\n+\n+\tselectAllUnexpiredOCSPSQL = `\n+SELECT %s FROM ocsp_responses\n+WHERE current_timestamp < expiry;`\n+\n+\tselectOCSPSQL = `\n+SELECT %s FROM ocsp_responses\n+    WHERE (serial = $1);`\n+)\n+\n+func wrapCertStoreError(err error) error {\n+\tif err != nil {\n+\t\treturn cferr.Wrap(cferr.CertStoreError, cferr.Unknown, err)\n+\t}\n+\treturn nil\n+}\n+\n+// InsertCertificate puts a certdb.CertificateRecord into db\n+func InsertCertificate(db *sql.DB, cr *certdb.CertificateRecord) error {\n+\tres, err := db.Exec(\n+\t\tinsertSQL,\n+\t\tcr.Serial,\n+\t\tcr.CALabel,\n+\t\tcr.Status,\n+\t\tcr.Reason,\n+\t\tcr.Expiry,\n+\t\tcr.RevokedAt,\n+\t\tcr.PEM,\n+\t)\n+\tif err != nil {\n+\t\treturn wrapCertStoreError(err)\n+\t}\n+\n+\tnumRowsAffected, _ := res.RowsAffected()\n+\n+\tif numRowsAffected != 1 {\n+\t\treturn wrapCertStoreError(errors.New(\"Either zero or more than 1 rows are affected\"))","path":"certdb/pg/pg.go","position":79,"original_position":79,"commit_id":"4e75acdf981906369a9ef1e225d6cebd27bfdaf4","original_commit_id":"4e75acdf981906369a9ef1e225d6cebd27bfdaf4","user":{"login":"kisom","id":175578,"avatar_url":"https://avatars.githubusercontent.com/u/175578?v=3","gravatar_id":"","url":"https://api.github.com/users/kisom","html_url":"https://github.com/kisom","followers_url":"https://api.github.com/users/kisom/followers","following_url":"https://api.github.com/users/kisom/following{/other_user}","gists_url":"https://api.github.com/users/kisom/gists{/gist_id}","starred_url":"https://api.github.com/users/kisom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kisom/subscriptions","organizations_url":"https://api.github.com/users/kisom/orgs","repos_url":"https://api.github.com/users/kisom/repos","events_url":"https://api.github.com/users/kisom/events{/privacy}","received_events_url":"https://api.github.com/users/kisom/received_events","type":"User","site_admin":false},"body":"I think this error should say how many rows were affected (or have a `log.Error` statement indicating how many rows were affected). golint normally complains that errors should begin with a lowercase letter, so that might be worth fixing here.","created_at":"2015-12-01T23:47:44Z","updated_at":"2015-12-01T23:47:44Z","html_url":"https://github.com/cloudflare/cfssl/pull/433#discussion_r46358063","pull_request_url":"https://api.github.com/repos/cloudflare/cfssl/pulls/433","_links":{"self":{"href":"https://api.github.com/repos/cloudflare/cfssl/pulls/comments/46358063"},"html":{"href":"https://github.com/cloudflare/cfssl/pull/433#discussion_r46358063"},"pull_request":{"href":"https://api.github.com/repos/cloudflare/cfssl/pulls/433"}}},"pull_request":{"url":"https://api.github.com/repos/cloudflare/cfssl/pulls/433","id":51764883,"html_url":"https://github.com/cloudflare/cfssl/pull/433","diff_url":"https://github.com/cloudflare/cfssl/pull/433.diff","patch_url":"https://github.com/cloudflare/cfssl/pull/433.patch","issue_url":"https://api.github.com/repos/cloudflare/cfssl/issues/433","number":433,"state":"open","locked":false,"title":"Zi/certdb","user":{"login":"lziest","id":1222706,"avatar_url":"https://avatars.githubusercontent.com/u/1222706?v=3","gravatar_id":"","url":"https://api.github.com/users/lziest","html_url":"https://github.com/lziest","followers_url":"https://api.github.com/users/lziest/followers","following_url":"https://api.github.com/users/lziest/following{/other_user}","gists_url":"https://api.github.com/users/lziest/gists{/gist_id}","starred_url":"https://api.github.com/users/lziest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lziest/subscriptions","organizations_url":"https://api.github.com/users/lziest/orgs","repos_url":"https://api.github.com/users/lziest/repos","events_url":"https://api.github.com/users/lziest/events{/privacy}","received_events_url":"https://api.github.com/users/lziest/received_events","type":"User","site_admin":false},"body":"An initial attempt to get a db persistence abstraction for certificate and ocsp responses.","created_at":"2015-11-25T08:33:54Z","updated_at":"2015-12-01T23:47:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ab067b6067bb634472c16cd4f2829d0de6569df9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cloudflare/cfssl/pulls/433/commits","review_comments_url":"https://api.github.com/repos/cloudflare/cfssl/pulls/433/comments","review_comment_url":"https://api.github.com/repos/cloudflare/cfssl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cloudflare/cfssl/issues/433/comments","statuses_url":"https://api.github.com/repos/cloudflare/cfssl/statuses/4e75acdf981906369a9ef1e225d6cebd27bfdaf4","head":{"label":"cloudflare:zi/certdb","ref":"zi/certdb","sha":"4e75acdf981906369a9ef1e225d6cebd27bfdaf4","user":{"login":"cloudflare","id":314135,"avatar_url":"https://avatars.githubusercontent.com/u/314135?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudflare","html_url":"https://github.com/cloudflare","followers_url":"https://api.github.com/users/cloudflare/followers","following_url":"https://api.github.com/users/cloudflare/following{/other_user}","gists_url":"https://api.github.com/users/cloudflare/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudflare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudflare/subscriptions","organizations_url":"https://api.github.com/users/cloudflare/orgs","repos_url":"https://api.github.com/users/cloudflare/repos","events_url":"https://api.github.com/users/cloudflare/events{/privacy}","received_events_url":"https://api.github.com/users/cloudflare/received_events","type":"Organization","site_admin":false},"repo":{"id":21591001,"name":"cfssl","full_name":"cloudflare/cfssl","owner":{"login":"cloudflare","id":314135,"avatar_url":"https://avatars.githubusercontent.com/u/314135?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudflare","html_url":"https://github.com/cloudflare","followers_url":"https://api.github.com/users/cloudflare/followers","following_url":"https://api.github.com/users/cloudflare/following{/other_user}","gists_url":"https://api.github.com/users/cloudflare/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudflare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudflare/subscriptions","organizations_url":"https://api.github.com/users/cloudflare/orgs","repos_url":"https://api.github.com/users/cloudflare/repos","events_url":"https://api.github.com/users/cloudflare/events{/privacy}","received_events_url":"https://api.github.com/users/cloudflare/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudflare/cfssl","description":"CFSSL: CloudFlare's PKI toolkit","fork":false,"url":"https://api.github.com/repos/cloudflare/cfssl","forks_url":"https://api.github.com/repos/cloudflare/cfssl/forks","keys_url":"https://api.github.com/repos/cloudflare/cfssl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudflare/cfssl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudflare/cfssl/teams","hooks_url":"https://api.github.com/repos/cloudflare/cfssl/hooks","issue_events_url":"https://api.github.com/repos/cloudflare/cfssl/issues/events{/number}","events_url":"https://api.github.com/repos/cloudflare/cfssl/events","assignees_url":"https://api.github.com/repos/cloudflare/cfssl/assignees{/user}","branches_url":"https://api.github.com/repos/cloudflare/cfssl/branches{/branch}","tags_url":"https://api.github.com/repos/cloudflare/cfssl/tags","blobs_url":"https://api.github.com/repos/cloudflare/cfssl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudflare/cfssl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudflare/cfssl/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudflare/cfssl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudflare/cfssl/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudflare/cfssl/languages","stargazers_url":"https://api.github.com/repos/cloudflare/cfssl/stargazers","contributors_url":"https://api.github.com/repos/cloudflare/cfssl/contributors","subscribers_url":"https://api.github.com/repos/cloudflare/cfssl/subscribers","subscription_url":"https://api.github.com/repos/cloudflare/cfssl/subscription","commits_url":"https://api.github.com/repos/cloudflare/cfssl/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudflare/cfssl/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudflare/cfssl/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudflare/cfssl/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudflare/cfssl/contents/{+path}","compare_url":"https://api.github.com/repos/cloudflare/cfssl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudflare/cfssl/merges","archive_url":"https://api.github.com/repos/cloudflare/cfssl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudflare/cfssl/downloads","issues_url":"https://api.github.com/repos/cloudflare/cfssl/issues{/number}","pulls_url":"https://api.github.com/repos/cloudflare/cfssl/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudflare/cfssl/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudflare/cfssl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudflare/cfssl/labels{/name}","releases_url":"https://api.github.com/repos/cloudflare/cfssl/releases{/id}","created_at":"2014-07-07T23:49:12Z","updated_at":"2015-12-01T22:19:34Z","pushed_at":"2015-12-01T20:13:58Z","git_url":"git://github.com/cloudflare/cfssl.git","ssh_url":"git@github.com:cloudflare/cfssl.git","clone_url":"https://github.com/cloudflare/cfssl.git","svn_url":"https://github.com/cloudflare/cfssl","homepage":"https://cfssl.org/","size":2703,"stargazers_count":927,"watchers_count":927,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":108,"mirror_url":null,"open_issues_count":59,"forks":108,"open_issues":59,"watchers":927,"default_branch":"master"}},"base":{"label":"cloudflare:master","ref":"master","sha":"755f4128c7c69bad69117e44ffa028c1847a0608","user":{"login":"cloudflare","id":314135,"avatar_url":"https://avatars.githubusercontent.com/u/314135?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudflare","html_url":"https://github.com/cloudflare","followers_url":"https://api.github.com/users/cloudflare/followers","following_url":"https://api.github.com/users/cloudflare/following{/other_user}","gists_url":"https://api.github.com/users/cloudflare/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudflare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudflare/subscriptions","organizations_url":"https://api.github.com/users/cloudflare/orgs","repos_url":"https://api.github.com/users/cloudflare/repos","events_url":"https://api.github.com/users/cloudflare/events{/privacy}","received_events_url":"https://api.github.com/users/cloudflare/received_events","type":"Organization","site_admin":false},"repo":{"id":21591001,"name":"cfssl","full_name":"cloudflare/cfssl","owner":{"login":"cloudflare","id":314135,"avatar_url":"https://avatars.githubusercontent.com/u/314135?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudflare","html_url":"https://github.com/cloudflare","followers_url":"https://api.github.com/users/cloudflare/followers","following_url":"https://api.github.com/users/cloudflare/following{/other_user}","gists_url":"https://api.github.com/users/cloudflare/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudflare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudflare/subscriptions","organizations_url":"https://api.github.com/users/cloudflare/orgs","repos_url":"https://api.github.com/users/cloudflare/repos","events_url":"https://api.github.com/users/cloudflare/events{/privacy}","received_events_url":"https://api.github.com/users/cloudflare/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudflare/cfssl","description":"CFSSL: CloudFlare's PKI toolkit","fork":false,"url":"https://api.github.com/repos/cloudflare/cfssl","forks_url":"https://api.github.com/repos/cloudflare/cfssl/forks","keys_url":"https://api.github.com/repos/cloudflare/cfssl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudflare/cfssl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudflare/cfssl/teams","hooks_url":"https://api.github.com/repos/cloudflare/cfssl/hooks","issue_events_url":"https://api.github.com/repos/cloudflare/cfssl/issues/events{/number}","events_url":"https://api.github.com/repos/cloudflare/cfssl/events","assignees_url":"https://api.github.com/repos/cloudflare/cfssl/assignees{/user}","branches_url":"https://api.github.com/repos/cloudflare/cfssl/branches{/branch}","tags_url":"https://api.github.com/repos/cloudflare/cfssl/tags","blobs_url":"https://api.github.com/repos/cloudflare/cfssl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudflare/cfssl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudflare/cfssl/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudflare/cfssl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudflare/cfssl/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudflare/cfssl/languages","stargazers_url":"https://api.github.com/repos/cloudflare/cfssl/stargazers","contributors_url":"https://api.github.com/repos/cloudflare/cfssl/contributors","subscribers_url":"https://api.github.com/repos/cloudflare/cfssl/subscribers","subscription_url":"https://api.github.com/repos/cloudflare/cfssl/subscription","commits_url":"https://api.github.com/repos/cloudflare/cfssl/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudflare/cfssl/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudflare/cfssl/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudflare/cfssl/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudflare/cfssl/contents/{+path}","compare_url":"https://api.github.com/repos/cloudflare/cfssl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudflare/cfssl/merges","archive_url":"https://api.github.com/repos/cloudflare/cfssl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudflare/cfssl/downloads","issues_url":"https://api.github.com/repos/cloudflare/cfssl/issues{/number}","pulls_url":"https://api.github.com/repos/cloudflare/cfssl/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudflare/cfssl/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudflare/cfssl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudflare/cfssl/labels{/name}","releases_url":"https://api.github.com/repos/cloudflare/cfssl/releases{/id}","created_at":"2014-07-07T23:49:12Z","updated_at":"2015-12-01T22:19:34Z","pushed_at":"2015-12-01T20:13:58Z","git_url":"git://github.com/cloudflare/cfssl.git","ssh_url":"git@github.com:cloudflare/cfssl.git","clone_url":"https://github.com/cloudflare/cfssl.git","svn_url":"https://github.com/cloudflare/cfssl","homepage":"https://cfssl.org/","size":2703,"stargazers_count":927,"watchers_count":927,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":108,"mirror_url":null,"open_issues_count":59,"forks":108,"open_issues":59,"watchers":927,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cloudflare/cfssl/pulls/433"},"html":{"href":"https://github.com/cloudflare/cfssl/pull/433"},"issue":{"href":"https://api.github.com/repos/cloudflare/cfssl/issues/433"},"comments":{"href":"https://api.github.com/repos/cloudflare/cfssl/issues/433/comments"},"review_comments":{"href":"https://api.github.com/repos/cloudflare/cfssl/pulls/433/comments"},"review_comment":{"href":"https://api.github.com/repos/cloudflare/cfssl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cloudflare/cfssl/pulls/433/commits"},"statuses":{"href":"https://api.github.com/repos/cloudflare/cfssl/statuses/4e75acdf981906369a9ef1e225d6cebd27bfdaf4"}}}}