{"action":"created","comment":{"url":"https://api.github.com/repos/18F/e-manifest/pulls/comments/50757067","id":50757067,"diff_hunk":"@@ -1,21 +1,38 @@\n class Api::V0::SignaturesController < ApiController\n   def create\n     manifest = find_manifest(params[:manifest_id])\n-    sign_request = read_body_as_json\n+    signature_request = prep_signature_request(manifest)\n \n-    manifest_content = manifest[:content].to_json\n-    sign_request[:manifest_content] = manifest_content\n-    system_session_token = session[:system_session_token]\n-    sign_request[\"token\"] = system_session_token\n+    cdx_start = Time.now\n+    cdx_response = CDX::Manifest.new(signature_request).sign\n+    cdx_stop = Time.now\n+    Rails.logger.debug(ANSI.blue{ \"  CDX signature time: #{sprintf('%#g', (cdx_stop - cdx_start))} seconds\" })\n \n-    response = CDX::Manifest.new(sign_request).sign\n+    status = update_manifest(cdx_response, signature_request, manifest)\n \n-    if (response.key?(:document_id))\n-      manifest[:document_id] = response[:document_id]\n-      manifest[:activity_id] = sign_request[\"activity_id\"]\n-      manifest.save!\n+    render(json: cdx_response.to_json, status: status) unless performed?\n+  end\n+\n+  private\n+\n+  def prep_signature_request(manifest)\n+    signature_request = read_body_as_json(symbolize_names: true)\n+    signature_request[:manifest_content] = manifest[:content].to_json\n+    if signature_request[:token]\n+      signature_request[:token] = Base64.strict_decode64(signature_request[:token])\n     end\n+    signature_request\n+  end\n \n-    render json: response.to_json unless performed?\n+  def update_manifest(cdx_response, signature_request, manifest)\n+    if cdx_response.key?(:document_id)\n+      manifest.document_id = cdx_response[:document_id]\n+      manifest.activity_id = signature_request[:activity_id]\n+      manifest.save!\n+      status = 200\n+    else\n+      status = 422","path":"app/controllers/api/v0/signatures_controller.rb","position":45,"original_position":45,"commit_id":"437222f25dfc89fbf1f4353d1243ca8239d0ce9f","original_commit_id":"0b0b201061015a4c828b221a783c39b3f3efec00","user":{"login":"pkarman","id":1205061,"avatar_url":"https://avatars.githubusercontent.com/u/1205061?v=3","gravatar_id":"","url":"https://api.github.com/users/pkarman","html_url":"https://github.com/pkarman","followers_url":"https://api.github.com/users/pkarman/followers","following_url":"https://api.github.com/users/pkarman/following{/other_user}","gists_url":"https://api.github.com/users/pkarman/gists{/gist_id}","starred_url":"https://api.github.com/users/pkarman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pkarman/subscriptions","organizations_url":"https://api.github.com/users/pkarman/orgs","repos_url":"https://api.github.com/users/pkarman/repos","events_url":"https://api.github.com/users/pkarman/events{/privacy}","received_events_url":"https://api.github.com/users/pkarman/received_events","type":"User","site_admin":false},"body":"do an explicit `return 200` within the if/else block? I was trying to train myself not to do that! :) If that's what you mean, yes I would be happy to.","created_at":"2016-01-25T21:14:35Z","updated_at":"2016-01-25T21:14:35Z","html_url":"https://github.com/18F/e-manifest/pull/101#discussion_r50757067","pull_request_url":"https://api.github.com/repos/18F/e-manifest/pulls/101","_links":{"self":{"href":"https://api.github.com/repos/18F/e-manifest/pulls/comments/50757067"},"html":{"href":"https://github.com/18F/e-manifest/pull/101#discussion_r50757067"},"pull_request":{"href":"https://api.github.com/repos/18F/e-manifest/pulls/101"}}},"pull_request":{"url":"https://api.github.com/repos/18F/e-manifest/pulls/101","id":56943442,"html_url":"https://github.com/18F/e-manifest/pull/101","diff_url":"https://github.com/18F/e-manifest/pull/101.diff","patch_url":"https://github.com/18F/e-manifest/pull/101.patch","issue_url":"https://api.github.com/repos/18F/e-manifest/issues/101","number":101,"state":"open","locked":false,"title":"load test","user":{"login":"pkarman","id":1205061,"avatar_url":"https://avatars.githubusercontent.com/u/1205061?v=3","gravatar_id":"","url":"https://api.github.com/users/pkarman","html_url":"https://github.com/pkarman","followers_url":"https://api.github.com/users/pkarman/followers","following_url":"https://api.github.com/users/pkarman/following{/other_user}","gists_url":"https://api.github.com/users/pkarman/gists{/gist_id}","starred_url":"https://api.github.com/users/pkarman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pkarman/subscriptions","organizations_url":"https://api.github.com/users/pkarman/orgs","repos_url":"https://api.github.com/users/pkarman/repos","events_url":"https://api.github.com/users/pkarman/events{/privacy}","received_events_url":"https://api.github.com/users/pkarman/received_events","type":"User","site_admin":false},"body":"Trello: https://trello.com/c/qFQhX4Fh\r\n\r\nIn addition to load testing, this PR also contains some enhancements to the CDX model logging and some fixes to signature creation.","created_at":"2016-01-22T21:22:56Z","updated_at":"2016-01-25T21:14:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"86568ac382ce74be34d164802ee301a2b2460628","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/18F/e-manifest/pulls/101/commits","review_comments_url":"https://api.github.com/repos/18F/e-manifest/pulls/101/comments","review_comment_url":"https://api.github.com/repos/18F/e-manifest/pulls/comments{/number}","comments_url":"https://api.github.com/repos/18F/e-manifest/issues/101/comments","statuses_url":"https://api.github.com/repos/18F/e-manifest/statuses/437222f25dfc89fbf1f4353d1243ca8239d0ce9f","head":{"label":"18F:tourbus-load-test","ref":"tourbus-load-test","sha":"437222f25dfc89fbf1f4353d1243ca8239d0ce9f","user":{"login":"18F","id":6233994,"avatar_url":"https://avatars.githubusercontent.com/u/6233994?v=3","gravatar_id":"","url":"https://api.github.com/users/18F","html_url":"https://github.com/18F","followers_url":"https://api.github.com/users/18F/followers","following_url":"https://api.github.com/users/18F/following{/other_user}","gists_url":"https://api.github.com/users/18F/gists{/gist_id}","starred_url":"https://api.github.com/users/18F/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/18F/subscriptions","organizations_url":"https://api.github.com/users/18F/orgs","repos_url":"https://api.github.com/users/18F/repos","events_url":"https://api.github.com/users/18F/events{/privacy}","received_events_url":"https://api.github.com/users/18F/received_events","type":"Organization","site_admin":false},"repo":{"id":38887537,"name":"e-manifest","full_name":"18F/e-manifest","owner":{"login":"18F","id":6233994,"avatar_url":"https://avatars.githubusercontent.com/u/6233994?v=3","gravatar_id":"","url":"https://api.github.com/users/18F","html_url":"https://github.com/18F","followers_url":"https://api.github.com/users/18F/followers","following_url":"https://api.github.com/users/18F/following{/other_user}","gists_url":"https://api.github.com/users/18F/gists{/gist_id}","starred_url":"https://api.github.com/users/18F/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/18F/subscriptions","organizations_url":"https://api.github.com/users/18F/orgs","repos_url":"https://api.github.com/users/18F/repos","events_url":"https://api.github.com/users/18F/events{/privacy}","received_events_url":"https://api.github.com/users/18F/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/18F/e-manifest","description":"The EPA e-Manifest project","fork":false,"url":"https://api.github.com/repos/18F/e-manifest","forks_url":"https://api.github.com/repos/18F/e-manifest/forks","keys_url":"https://api.github.com/repos/18F/e-manifest/keys{/key_id}","collaborators_url":"https://api.github.com/repos/18F/e-manifest/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/18F/e-manifest/teams","hooks_url":"https://api.github.com/repos/18F/e-manifest/hooks","issue_events_url":"https://api.github.com/repos/18F/e-manifest/issues/events{/number}","events_url":"https://api.github.com/repos/18F/e-manifest/events","assignees_url":"https://api.github.com/repos/18F/e-manifest/assignees{/user}","branches_url":"https://api.github.com/repos/18F/e-manifest/branches{/branch}","tags_url":"https://api.github.com/repos/18F/e-manifest/tags","blobs_url":"https://api.github.com/repos/18F/e-manifest/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/18F/e-manifest/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/18F/e-manifest/git/refs{/sha}","trees_url":"https://api.github.com/repos/18F/e-manifest/git/trees{/sha}","statuses_url":"https://api.github.com/repos/18F/e-manifest/statuses/{sha}","languages_url":"https://api.github.com/repos/18F/e-manifest/languages","stargazers_url":"https://api.github.com/repos/18F/e-manifest/stargazers","contributors_url":"https://api.github.com/repos/18F/e-manifest/contributors","subscribers_url":"https://api.github.com/repos/18F/e-manifest/subscribers","subscription_url":"https://api.github.com/repos/18F/e-manifest/subscription","commits_url":"https://api.github.com/repos/18F/e-manifest/commits{/sha}","git_commits_url":"https://api.github.com/repos/18F/e-manifest/git/commits{/sha}","comments_url":"https://api.github.com/repos/18F/e-manifest/comments{/number}","issue_comment_url":"https://api.github.com/repos/18F/e-manifest/issues/comments{/number}","contents_url":"https://api.github.com/repos/18F/e-manifest/contents/{+path}","compare_url":"https://api.github.com/repos/18F/e-manifest/compare/{base}...{head}","merges_url":"https://api.github.com/repos/18F/e-manifest/merges","archive_url":"https://api.github.com/repos/18F/e-manifest/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/18F/e-manifest/downloads","issues_url":"https://api.github.com/repos/18F/e-manifest/issues{/number}","pulls_url":"https://api.github.com/repos/18F/e-manifest/pulls{/number}","milestones_url":"https://api.github.com/repos/18F/e-manifest/milestones{/number}","notifications_url":"https://api.github.com/repos/18F/e-manifest/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/18F/e-manifest/labels{/name}","releases_url":"https://api.github.com/repos/18F/e-manifest/releases{/id}","deployments_url":"https://api.github.com/repos/18F/e-manifest/deployments","created_at":"2015-07-10T15:26:47Z","updated_at":"2016-01-16T18:32:11Z","pushed_at":"2016-01-25T21:13:28Z","git_url":"git://github.com/18F/e-manifest.git","ssh_url":"git@github.com:18F/e-manifest.git","clone_url":"https://github.com/18F/e-manifest.git","svn_url":"https://github.com/18F/e-manifest","homepage":"","size":22742,"stargazers_count":5,"watchers_count":5,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":5,"forks":4,"open_issues":5,"watchers":5,"default_branch":"master"}},"base":{"label":"18F:master","ref":"master","sha":"8637c09573334da44c67aae3fcb7dfc5da5608cd","user":{"login":"18F","id":6233994,"avatar_url":"https://avatars.githubusercontent.com/u/6233994?v=3","gravatar_id":"","url":"https://api.github.com/users/18F","html_url":"https://github.com/18F","followers_url":"https://api.github.com/users/18F/followers","following_url":"https://api.github.com/users/18F/following{/other_user}","gists_url":"https://api.github.com/users/18F/gists{/gist_id}","starred_url":"https://api.github.com/users/18F/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/18F/subscriptions","organizations_url":"https://api.github.com/users/18F/orgs","repos_url":"https://api.github.com/users/18F/repos","events_url":"https://api.github.com/users/18F/events{/privacy}","received_events_url":"https://api.github.com/users/18F/received_events","type":"Organization","site_admin":false},"repo":{"id":38887537,"name":"e-manifest","full_name":"18F/e-manifest","owner":{"login":"18F","id":6233994,"avatar_url":"https://avatars.githubusercontent.com/u/6233994?v=3","gravatar_id":"","url":"https://api.github.com/users/18F","html_url":"https://github.com/18F","followers_url":"https://api.github.com/users/18F/followers","following_url":"https://api.github.com/users/18F/following{/other_user}","gists_url":"https://api.github.com/users/18F/gists{/gist_id}","starred_url":"https://api.github.com/users/18F/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/18F/subscriptions","organizations_url":"https://api.github.com/users/18F/orgs","repos_url":"https://api.github.com/users/18F/repos","events_url":"https://api.github.com/users/18F/events{/privacy}","received_events_url":"https://api.github.com/users/18F/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/18F/e-manifest","description":"The EPA e-Manifest project","fork":false,"url":"https://api.github.com/repos/18F/e-manifest","forks_url":"https://api.github.com/repos/18F/e-manifest/forks","keys_url":"https://api.github.com/repos/18F/e-manifest/keys{/key_id}","collaborators_url":"https://api.github.com/repos/18F/e-manifest/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/18F/e-manifest/teams","hooks_url":"https://api.github.com/repos/18F/e-manifest/hooks","issue_events_url":"https://api.github.com/repos/18F/e-manifest/issues/events{/number}","events_url":"https://api.github.com/repos/18F/e-manifest/events","assignees_url":"https://api.github.com/repos/18F/e-manifest/assignees{/user}","branches_url":"https://api.github.com/repos/18F/e-manifest/branches{/branch}","tags_url":"https://api.github.com/repos/18F/e-manifest/tags","blobs_url":"https://api.github.com/repos/18F/e-manifest/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/18F/e-manifest/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/18F/e-manifest/git/refs{/sha}","trees_url":"https://api.github.com/repos/18F/e-manifest/git/trees{/sha}","statuses_url":"https://api.github.com/repos/18F/e-manifest/statuses/{sha}","languages_url":"https://api.github.com/repos/18F/e-manifest/languages","stargazers_url":"https://api.github.com/repos/18F/e-manifest/stargazers","contributors_url":"https://api.github.com/repos/18F/e-manifest/contributors","subscribers_url":"https://api.github.com/repos/18F/e-manifest/subscribers","subscription_url":"https://api.github.com/repos/18F/e-manifest/subscription","commits_url":"https://api.github.com/repos/18F/e-manifest/commits{/sha}","git_commits_url":"https://api.github.com/repos/18F/e-manifest/git/commits{/sha}","comments_url":"https://api.github.com/repos/18F/e-manifest/comments{/number}","issue_comment_url":"https://api.github.com/repos/18F/e-manifest/issues/comments{/number}","contents_url":"https://api.github.com/repos/18F/e-manifest/contents/{+path}","compare_url":"https://api.github.com/repos/18F/e-manifest/compare/{base}...{head}","merges_url":"https://api.github.com/repos/18F/e-manifest/merges","archive_url":"https://api.github.com/repos/18F/e-manifest/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/18F/e-manifest/downloads","issues_url":"https://api.github.com/repos/18F/e-manifest/issues{/number}","pulls_url":"https://api.github.com/repos/18F/e-manifest/pulls{/number}","milestones_url":"https://api.github.com/repos/18F/e-manifest/milestones{/number}","notifications_url":"https://api.github.com/repos/18F/e-manifest/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/18F/e-manifest/labels{/name}","releases_url":"https://api.github.com/repos/18F/e-manifest/releases{/id}","deployments_url":"https://api.github.com/repos/18F/e-manifest/deployments","created_at":"2015-07-10T15:26:47Z","updated_at":"2016-01-16T18:32:11Z","pushed_at":"2016-01-25T21:13:28Z","git_url":"git://github.com/18F/e-manifest.git","ssh_url":"git@github.com:18F/e-manifest.git","clone_url":"https://github.com/18F/e-manifest.git","svn_url":"https://github.com/18F/e-manifest","homepage":"","size":22742,"stargazers_count":5,"watchers_count":5,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":5,"forks":4,"open_issues":5,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/18F/e-manifest/pulls/101"},"html":{"href":"https://github.com/18F/e-manifest/pull/101"},"issue":{"href":"https://api.github.com/repos/18F/e-manifest/issues/101"},"comments":{"href":"https://api.github.com/repos/18F/e-manifest/issues/101/comments"},"review_comments":{"href":"https://api.github.com/repos/18F/e-manifest/pulls/101/comments"},"review_comment":{"href":"https://api.github.com/repos/18F/e-manifest/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/18F/e-manifest/pulls/101/commits"},"statuses":{"href":"https://api.github.com/repos/18F/e-manifest/statuses/437222f25dfc89fbf1f4353d1243ca8239d0ce9f"}}}}