{"action":"created","comment":{"url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/pulls/comments/71900091","id":71900091,"diff_hunk":"@@ -0,0 +1,140 @@\n+import base64\n+import logging\n+import json\n+import time\n+\n+from baseplate import (\n+    Baseplate,\n+    make_metrics_client,\n+)\n+from baseplate.crypto import (\n+    ExpiredSignatureError,\n+    IncorrectSignatureError,\n+    MessageSigner,\n+    UnreadableSignatureError,\n+)\n+from baseplate.integration.pyramid import BaseplateConfigurator\n+from enum import Enum\n+from pyramid.config import Configurator\n+\n+from reddit_service_ads_tracking import config\n+from reddit_service_ads_tracking.lib import (\n+    events,\n+    response,\n+    urls,\n+)\n+\n+\n+logger = logging.getLogger(__name__)\n+\n+\n+class ClickProcessNotes(Enum):\n+    VALID = \"VALID\"\n+    EXPIRED_SIGNATURE = \"EXPIRED_SIGNATURE\"\n+    INVALID_SIGNATURE = \"INVALID_SIGNATURE\"\n+    BAD_DATA = \"BAD_DATA\"\n+\n+\n+class TrackingService(object):\n+    def __init__(self, config, signer, event_queue):\n+        self.config = config\n+        self.signer = signer\n+        self.event_queue = event_queue\n+\n+    def is_healthy(self, request):\n+        return {\n+            \"status\": \"healthy\",\n+        }\n+\n+    def track_conversion(self, request):\n+        pass\n+\n+    def track_impression(self, request):\n+        pass\n+\n+    def track_click(self, request):\n+        url = request.GET.get(\"url\", \"\").encode(\"utf-8\")\n+        b64_data = request.GET.get(\"data\", \"\").encode(\"utf-8\")\n+        observed_mac = request.GET.get(\"hmac\", \"\").encode(\"utf-8\")\n+\n+        if (not url or\n+                not b64_data or\n+                not observed_mac):\n+            return response.abort(request, 400,\n+                                  \"missing required query parameters\")\n+\n+        result, process_notes = None, ClickProcessNotes.VALID\n+        expired_on = None\n+\n+        try:\n+            self.signer.validate_signature(\n+                \"|\".join([url, b64_data]), observed_mac)\n+\n+            request.metrics.counter(\"click.signature.success\").increment()\n+        except ExpiredSignatureError as e:\n+            request.metrics.counter(\"click.signature.expired\").increment()\n+            process_notes = ClickProcessNotes.EXPIRED_SIGNATURE\n+            expired_on = e.expiration\n+        except (UnreadableSignatureError, IncorrectSignatureError):\n+            request.metrics.counter(\"click.signature.error\").increment()\n+            process_notes = ClickProcessNotes.INVALID_SIGNATURE\n+            result = response.abort(request, 403)\n+\n+        data = {}\n+\n+        try:\n+            json_string = base64.urlsafe_b64decode(b64_data)\n+            data = json.loads(json_string)\n+        except (TypeError, ValueError) as e:\n+            request.metrics.counter(\"click.data.parse_error\").increment()\n+            process_notes = ClickProcessNotes.BAD_DATA\n+            result = response.abort(request, 400,\n+                                    \"unable to parse `data`: %s\" % e.message)\n+\n+        destination = urls.fix_query_encoding(url)\n+\n+        self.event_queue.click_event(\n+            url=destination,\n+            process_notes=process_notes,\n+            request=request,\n+            expired_on=expired_on,\n+            **data\n+        )\n+\n+        if result:\n+            return result\n+\n+        return response.redirect(destination)\n+\n+\n+def make_wsgi_app(app_config):\n+    cfg = config.parse_config(app_config)\n+\n+    signer = MessageSigner(cfg.ads_tracking.click_secret)\n+    event_queue = events.EventQueue(\"production\")\n+\n+    metrics_client = make_metrics_client(app_config)\n+\n+    baseplate = Baseplate()\n+    baseplate.configure_logging()\n+    baseplate.configure_metrics(metrics_client)\n+\n+    configurator = Configurator(settings=app_config)\n+\n+    baseplate_configurator = BaseplateConfigurator(baseplate)\n+    configurator.include(baseplate_configurator.includeme)\n+\n+    controller = TrackingService(\n+        config=cfg,\n+        signer=signer,\n+        event_queue=event_queue,","path":"reddit_service_ads_tracking/__init__.py","position":130,"original_position":130,"commit_id":"a20598fac48032f19a1248187c3b80b0e297afb1","original_commit_id":"a20598fac48032f19a1248187c3b80b0e297afb1","user":{"login":"spladug","id":338853,"avatar_url":"https://avatars.githubusercontent.com/u/338853?v=3","gravatar_id":"","url":"https://api.github.com/users/spladug","html_url":"https://github.com/spladug","followers_url":"https://api.github.com/users/spladug/followers","following_url":"https://api.github.com/users/spladug/following{/other_user}","gists_url":"https://api.github.com/users/spladug/gists{/gist_id}","starred_url":"https://api.github.com/users/spladug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spladug/subscriptions","organizations_url":"https://api.github.com/users/spladug/orgs","repos_url":"https://api.github.com/users/spladug/repos","events_url":"https://api.github.com/users/spladug/events{/privacy}","received_events_url":"https://api.github.com/users/spladug/received_events","type":"User","site_admin":false},"body":"Andrew cleverly suggested that the event queues could get `add_to_context` support, so they have that now. So you can do something like\r\n\r\n```python\r\n    baseplate.add_to_context(\"events_production\", EventQueue(\"production\"))\r\n    baseplate.add_to_context(\"events_test\", EventQueue(\"test\"))\r\n```\r\n\r\nand `events_production` and `events_test` will show up on your `request` object now.","created_at":"2016-07-22T15:44:18Z","updated_at":"2016-07-22T15:44:18Z","html_url":"https://github.com/reddit/reddit-service-ads-tracking/pull/1#discussion_r71900091","pull_request_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/pulls/comments/71900091"},"html":{"href":"https://github.com/reddit/reddit-service-ads-tracking/pull/1#discussion_r71900091"},"pull_request":{"href":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/pulls/1","id":78406532,"html_url":"https://github.com/reddit/reddit-service-ads-tracking/pull/1","diff_url":"https://github.com/reddit/reddit-service-ads-tracking/pull/1.diff","patch_url":"https://github.com/reddit/reddit-service-ads-tracking/pull/1.patch","issue_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/issues/1","number":1,"state":"open","locked":false,"title":"Hello world","user":{"login":"dwick","id":823747,"avatar_url":"https://avatars.githubusercontent.com/u/823747?v=3","gravatar_id":"","url":"https://api.github.com/users/dwick","html_url":"https://github.com/dwick","followers_url":"https://api.github.com/users/dwick/followers","following_url":"https://api.github.com/users/dwick/following{/other_user}","gists_url":"https://api.github.com/users/dwick/gists{/gist_id}","starred_url":"https://api.github.com/users/dwick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dwick/subscriptions","organizations_url":"https://api.github.com/users/dwick/orgs","repos_url":"https://api.github.com/users/dwick/repos","events_url":"https://api.github.com/users/dwick/events{/privacy}","received_events_url":"https://api.github.com/users/dwick/received_events","type":"User","site_admin":false},"body":"👓 @spladug \r\n\r\nre: https://reddit.atlassian.net/browse/ADS-644?focusedCommentId=49605&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-49605","created_at":"2016-07-21T23:57:18Z","updated_at":"2016-07-22T15:44:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"871e9b88b6f5d07ac2118fae58e8ffe02d472b1b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/pulls/1/commits","review_comments_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/pulls/1/comments","review_comment_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/pulls/comments{/number}","comments_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/issues/1/comments","statuses_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/statuses/a20598fac48032f19a1248187c3b80b0e297afb1","head":{"label":"dwick:hello-world","ref":"hello-world","sha":"a20598fac48032f19a1248187c3b80b0e297afb1","user":{"login":"dwick","id":823747,"avatar_url":"https://avatars.githubusercontent.com/u/823747?v=3","gravatar_id":"","url":"https://api.github.com/users/dwick","html_url":"https://github.com/dwick","followers_url":"https://api.github.com/users/dwick/followers","following_url":"https://api.github.com/users/dwick/following{/other_user}","gists_url":"https://api.github.com/users/dwick/gists{/gist_id}","starred_url":"https://api.github.com/users/dwick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dwick/subscriptions","organizations_url":"https://api.github.com/users/dwick/orgs","repos_url":"https://api.github.com/users/dwick/repos","events_url":"https://api.github.com/users/dwick/events{/privacy}","received_events_url":"https://api.github.com/users/dwick/received_events","type":"User","site_admin":false},"repo":{"id":63909633,"name":"reddit-service-ads-tracking","full_name":"dwick/reddit-service-ads-tracking","owner":{"login":"dwick","id":823747,"avatar_url":"https://avatars.githubusercontent.com/u/823747?v=3","gravatar_id":"","url":"https://api.github.com/users/dwick","html_url":"https://github.com/dwick","followers_url":"https://api.github.com/users/dwick/followers","following_url":"https://api.github.com/users/dwick/following{/other_user}","gists_url":"https://api.github.com/users/dwick/gists{/gist_id}","starred_url":"https://api.github.com/users/dwick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dwick/subscriptions","organizations_url":"https://api.github.com/users/dwick/orgs","repos_url":"https://api.github.com/users/dwick/repos","events_url":"https://api.github.com/users/dwick/events{/privacy}","received_events_url":"https://api.github.com/users/dwick/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dwick/reddit-service-ads-tracking","description":null,"fork":true,"url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking","forks_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/forks","keys_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/teams","hooks_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/hooks","issue_events_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/issues/events{/number}","events_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/events","assignees_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/assignees{/user}","branches_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/branches{/branch}","tags_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/tags","blobs_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/git/refs{/sha}","trees_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/statuses/{sha}","languages_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/languages","stargazers_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/stargazers","contributors_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/contributors","subscribers_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/subscribers","subscription_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/subscription","commits_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/commits{/sha}","git_commits_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/git/commits{/sha}","comments_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/comments{/number}","issue_comment_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/issues/comments{/number}","contents_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/contents/{+path}","compare_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/merges","archive_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/downloads","issues_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/issues{/number}","pulls_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/pulls{/number}","milestones_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/milestones{/number}","notifications_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/labels{/name}","releases_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/releases{/id}","deployments_url":"https://api.github.com/repos/dwick/reddit-service-ads-tracking/deployments","created_at":"2016-07-21T23:51:46Z","updated_at":"2016-07-21T23:51:20Z","pushed_at":"2016-07-21T23:55:44Z","git_url":"git://github.com/dwick/reddit-service-ads-tracking.git","ssh_url":"git@github.com:dwick/reddit-service-ads-tracking.git","clone_url":"https://github.com/dwick/reddit-service-ads-tracking.git","svn_url":"https://github.com/dwick/reddit-service-ads-tracking","homepage":null,"size":19,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"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":"reddit:master","ref":"master","sha":"c605247c18932d4f825e3e7836524504ded3856e","user":{"login":"reddit","id":14248,"avatar_url":"https://avatars.githubusercontent.com/u/14248?v=3","gravatar_id":"","url":"https://api.github.com/users/reddit","html_url":"https://github.com/reddit","followers_url":"https://api.github.com/users/reddit/followers","following_url":"https://api.github.com/users/reddit/following{/other_user}","gists_url":"https://api.github.com/users/reddit/gists{/gist_id}","starred_url":"https://api.github.com/users/reddit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reddit/subscriptions","organizations_url":"https://api.github.com/users/reddit/orgs","repos_url":"https://api.github.com/users/reddit/repos","events_url":"https://api.github.com/users/reddit/events{/privacy}","received_events_url":"https://api.github.com/users/reddit/received_events","type":"Organization","site_admin":false},"repo":{"id":60384648,"name":"reddit-service-ads-tracking","full_name":"reddit/reddit-service-ads-tracking","owner":{"login":"reddit","id":14248,"avatar_url":"https://avatars.githubusercontent.com/u/14248?v=3","gravatar_id":"","url":"https://api.github.com/users/reddit","html_url":"https://github.com/reddit","followers_url":"https://api.github.com/users/reddit/followers","following_url":"https://api.github.com/users/reddit/following{/other_user}","gists_url":"https://api.github.com/users/reddit/gists{/gist_id}","starred_url":"https://api.github.com/users/reddit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reddit/subscriptions","organizations_url":"https://api.github.com/users/reddit/orgs","repos_url":"https://api.github.com/users/reddit/repos","events_url":"https://api.github.com/users/reddit/events{/privacy}","received_events_url":"https://api.github.com/users/reddit/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/reddit/reddit-service-ads-tracking","description":"","fork":false,"url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking","forks_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/forks","keys_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/keys{/key_id}","collaborators_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/teams","hooks_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/hooks","issue_events_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/issues/events{/number}","events_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/events","assignees_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/assignees{/user}","branches_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/branches{/branch}","tags_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/tags","blobs_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/git/refs{/sha}","trees_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/git/trees{/sha}","statuses_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/statuses/{sha}","languages_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/languages","stargazers_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/stargazers","contributors_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/contributors","subscribers_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/subscribers","subscription_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/subscription","commits_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/commits{/sha}","git_commits_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/git/commits{/sha}","comments_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/comments{/number}","issue_comment_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/issues/comments{/number}","contents_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/contents/{+path}","compare_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/compare/{base}...{head}","merges_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/merges","archive_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/downloads","issues_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/issues{/number}","pulls_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/pulls{/number}","milestones_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/milestones{/number}","notifications_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/labels{/name}","releases_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/releases{/id}","deployments_url":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/deployments","created_at":"2016-06-04T00:01:55Z","updated_at":"2016-07-21T23:51:20Z","pushed_at":"2016-07-21T23:57:18Z","git_url":"git://github.com/reddit/reddit-service-ads-tracking.git","ssh_url":"git@github.com:reddit/reddit-service-ads-tracking.git","clone_url":"https://github.com/reddit/reddit-service-ads-tracking.git","svn_url":"https://github.com/reddit/reddit-service-ads-tracking","homepage":null,"size":20,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/pulls/1"},"html":{"href":"https://github.com/reddit/reddit-service-ads-tracking/pull/1"},"issue":{"href":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/issues/1"},"comments":{"href":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/reddit/reddit-service-ads-tracking/statuses/a20598fac48032f19a1248187c3b80b0e297afb1"}}}}
{"actor":{"display_login":"spladug"}}