{"action":"created","comment":{"url":"https://api.github.com/repos/getsentry/sentry/pulls/comments/59249313","id":59249313,"diff_hunk":"@@ -43,97 +43,154 @@ def parse_new_timestamp(value):\n     return rv.replace(tzinfo=pytz.utc)\n \n \n-def typevalidator(ty):\n-    def decorator(f):\n-        validators[ty] = f\n-        return f\n-    return decorator\n-\n-\n def validate_payload_for_type(payload, type):\n     payload = payload or {}\n-    func = validators.get(type)\n-    if func is None:\n+    ty = crumb_types.get(type)\n+    if ty is None:\n         raise InterfaceValidationError(\"Invalid breadcrumb type (%s).\" %\n                                        (type,))\n-    return func(payload)\n-\n-\n-@typevalidator('message')\n-def validate_message(payload):\n-    rv = {}\n-    for key in 'message', 'logger', 'level', 'classifier':\n-        value = payload.get(key)\n-        if value is None:\n-            continue\n-        rv[key] = trim(value, 1024)\n-    if 'message' not in rv:\n-        raise InterfaceValidationError(\"No message provided for \"\n-                                       \"'message' breadcrumb.\")\n-    return rv\n-\n-\n-@typevalidator('rpc')\n-def validate_rpc(payload):\n-    rv = {}\n-    for key in 'endpoint', 'params', 'classifier':\n-        value = payload.get(key)\n-        if value is not None:\n-            rv[key] = trim(value, 1024)\n-    if not rv.get('endpoint'):\n-        raise InterfaceValidationError(\"No endpoint provided for \"\n-                                       \"'rpc' breadcrumb.\")\n-    return rv\n-\n-\n-@typevalidator('http_request')\n-def validate_http_request(payload):\n-    rv = {}\n-    for key in 'statusCode', 'reason', 'method', 'url', 'headers', \\\n-               'response', 'classifier':\n-        value = payload.get(key)\n-        if value is not None:\n-            rv[key] = trim(value, 1024)\n-    if not rv.get('url'):\n-        raise InterfaceValidationError(\"No url provided for \"\n-                                       \"'http_request' breadcrumb.\")\n-    return rv\n-\n-\n-@typevalidator('query')\n-def validate_query(payload):\n-    rv = {}\n-    for key in 'query', 'params', 'classifier':\n-        value = payload.get(key)\n-        if value is not None:\n-            rv[key] = trim(value, 1024)\n-    if 'query' not in rv:\n-        raise InterfaceValidationError(\"Query not provided for 'query' \"\n-                                       \"breadcrumb.\")\n-    return rv\n-\n-\n-@typevalidator('ui_event')\n-def validate_event(payload):\n-    rv = {}\n-    for key in 'type', 'target', 'classifier':\n-        value = payload.get(key)\n-        if value is not None:\n-            rv[key] = trim(value, 1024)\n-    return rv\n+    return ty.validate_payload(payload)\n+\n+\n+def get_api_context_for_type(data, type, is_public=False):\n+    ty = crumb_types.get(type)\n+    if ty is None:\n+        raise InterfaceValidationError(\"Invalid breadcrumb type (%s).\" %\n+                                       (type,))\n+    return ty.get_api_context(data, type, is_public=is_public)\n+\n+\n+class CrumbType(type):\n+\n+    def __new__(cls, name, bases, d):\n+        rv = type.__new__(cls, name, bases, d)\n+        if d.get('type'):\n+            crumb_types[d['type']] = rv()\n+        return rv\n+\n+\n+class Crumb(object):\n+    __metaclass__ = CrumbType\n+    type = None\n+\n+    def validiate_payload(self, payload):\n+        return payload\n+\n+    def get_api_context(self, data, is_public=False):\n+        return data\n+\n \n+class MessageCrumb(Crumb):\n+    type = 'message'\n \n-@typevalidator('navigation')\n-def validate_navigation(payload):\n-    rv = {}\n-    for key in 'to', 'from':\n-        value = payload.get(key)\n-        if value is not None:\n+    def validate_payload(self, payload):\n+        rv = {}\n+        for key in 'message', 'logger', 'level', 'classifier':\n+            value = payload.get(key)\n+            if value is None:\n+                continue\n             rv[key] = trim(value, 1024)\n-    if 'to' not in rv:\n-        raise InterfaceValidationError(\"Location not provided for 'navigation' \"\n-                                       \"breadcrumb.\")\n-    return rv\n+        if 'message' not in rv:\n+            raise InterfaceValidationError(\"No message provided for \"\n+                                           \"'message' breadcrumb.\")\n+        return rv\n+\n+\n+class RpcCrumb(Crumb):\n+    type = 'rpc'\n+\n+    def validate_payload(self, payload):\n+        rv = {}\n+        for key in 'endpoint', 'params', 'classifier':\n+            value = payload.get(key)\n+            if value is not None:\n+                rv[key] = trim(value, 1024)\n+        if not rv.get('endpoint'):\n+            raise InterfaceValidationError(\"No endpoint provided for \"\n+                                           \"'rpc' breadcrumb.\")\n+        return rv\n+\n+\n+class HttpRequestCrumb(Crumb):\n+    type = 'http_request'\n+\n+    def validate_payload(self, payload):\n+        rv = {}\n+        for key in 'status_code', 'reason', 'method', 'url', 'headers', \\\n+                   'response', 'classifier':\n+            value = payload.get(key)\n+            if value is not None:\n+                rv[key] = trim(value, 1024)\n+        if not rv.get('url'):\n+            raise InterfaceValidationError(\"No url provided for \"\n+                                           \"'http_request' breadcrumb.\")\n+        return rv\n+\n+    def get_api_context(self, data, is_public=False):\n+        rv = dict(data)\n+        status_code = data.pop('status_code', None)","path":"src/sentry/interfaces/breadcrumbs.py","position":182,"original_position":182,"commit_id":"b96391d28684cc8f0eeccf7ab50aeb76a96a46d3","original_commit_id":"b96391d28684cc8f0eeccf7ab50aeb76a96a46d3","user":{"login":"dcramer","id":23610,"avatar_url":"https://avatars.githubusercontent.com/u/23610?v=3","gravatar_id":"","url":"https://api.github.com/users/dcramer","html_url":"https://github.com/dcramer","followers_url":"https://api.github.com/users/dcramer/followers","following_url":"https://api.github.com/users/dcramer/following{/other_user}","gists_url":"https://api.github.com/users/dcramer/gists{/gist_id}","starred_url":"https://api.github.com/users/dcramer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dcramer/subscriptions","organizations_url":"https://api.github.com/users/dcramer/orgs","repos_url":"https://api.github.com/users/dcramer/repos","events_url":"https://api.github.com/users/dcramer/events{/privacy}","received_events_url":"https://api.github.com/users/dcramer/received_events","type":"User","site_admin":false},"body":"are there any concerns with mutating the input here?","created_at":"2016-04-11T17:49:50Z","updated_at":"2016-04-11T17:49:50Z","html_url":"https://github.com/getsentry/sentry/pull/3016#discussion_r59249313","pull_request_url":"https://api.github.com/repos/getsentry/sentry/pulls/3016","_links":{"self":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/comments/59249313"},"html":{"href":"https://github.com/getsentry/sentry/pull/3016#discussion_r59249313"},"pull_request":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/3016"}}},"pull_request":{"url":"https://api.github.com/repos/getsentry/sentry/pulls/3016","id":65580146,"html_url":"https://github.com/getsentry/sentry/pull/3016","diff_url":"https://github.com/getsentry/sentry/pull/3016.diff","patch_url":"https://github.com/getsentry/sentry/pull/3016.patch","issue_url":"https://api.github.com/repos/getsentry/sentry/issues/3016","number":3016,"state":"open","locked":false,"title":"Added support for api context transformation for crumb types","user":{"login":"mitsuhiko","id":7396,"avatar_url":"https://avatars.githubusercontent.com/u/7396?v=3","gravatar_id":"","url":"https://api.github.com/users/mitsuhiko","html_url":"https://github.com/mitsuhiko","followers_url":"https://api.github.com/users/mitsuhiko/followers","following_url":"https://api.github.com/users/mitsuhiko/following{/other_user}","gists_url":"https://api.github.com/users/mitsuhiko/gists{/gist_id}","starred_url":"https://api.github.com/users/mitsuhiko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitsuhiko/subscriptions","organizations_url":"https://api.github.com/users/mitsuhiko/orgs","repos_url":"https://api.github.com/users/mitsuhiko/repos","events_url":"https://api.github.com/users/mitsuhiko/events{/privacy}","received_events_url":"https://api.github.com/users/mitsuhiko/received_events","type":"User","site_admin":false},"body":"@getsentry/api: i'm not super happy we transform this thing on the way\nout but we're doing it elsewhere too so maybe there is a reason for\ndoing it.","created_at":"2016-04-07T06:32:07Z","updated_at":"2016-04-11T17:49:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b32ec8291fb828cec0147ddd2ba368f1eb6c3de2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/getsentry/sentry/pulls/3016/commits","review_comments_url":"https://api.github.com/repos/getsentry/sentry/pulls/3016/comments","review_comment_url":"https://api.github.com/repos/getsentry/sentry/pulls/comments{/number}","comments_url":"https://api.github.com/repos/getsentry/sentry/issues/3016/comments","statuses_url":"https://api.github.com/repos/getsentry/sentry/statuses/b96391d28684cc8f0eeccf7ab50aeb76a96a46d3","head":{"label":"getsentry:feature/api-context-crumbs","ref":"feature/api-context-crumbs","sha":"b96391d28684cc8f0eeccf7ab50aeb76a96a46d3","user":{"login":"getsentry","id":1396951,"avatar_url":"https://avatars.githubusercontent.com/u/1396951?v=3","gravatar_id":"","url":"https://api.github.com/users/getsentry","html_url":"https://github.com/getsentry","followers_url":"https://api.github.com/users/getsentry/followers","following_url":"https://api.github.com/users/getsentry/following{/other_user}","gists_url":"https://api.github.com/users/getsentry/gists{/gist_id}","starred_url":"https://api.github.com/users/getsentry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getsentry/subscriptions","organizations_url":"https://api.github.com/users/getsentry/orgs","repos_url":"https://api.github.com/users/getsentry/repos","events_url":"https://api.github.com/users/getsentry/events{/privacy}","received_events_url":"https://api.github.com/users/getsentry/received_events","type":"Organization","site_admin":false},"repo":{"id":873328,"name":"sentry","full_name":"getsentry/sentry","owner":{"login":"getsentry","id":1396951,"avatar_url":"https://avatars.githubusercontent.com/u/1396951?v=3","gravatar_id":"","url":"https://api.github.com/users/getsentry","html_url":"https://github.com/getsentry","followers_url":"https://api.github.com/users/getsentry/followers","following_url":"https://api.github.com/users/getsentry/following{/other_user}","gists_url":"https://api.github.com/users/getsentry/gists{/gist_id}","starred_url":"https://api.github.com/users/getsentry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getsentry/subscriptions","organizations_url":"https://api.github.com/users/getsentry/orgs","repos_url":"https://api.github.com/users/getsentry/repos","events_url":"https://api.github.com/users/getsentry/events{/privacy}","received_events_url":"https://api.github.com/users/getsentry/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/getsentry/sentry","description":"Sentry is cross-platform crash reporting built with love","fork":false,"url":"https://api.github.com/repos/getsentry/sentry","forks_url":"https://api.github.com/repos/getsentry/sentry/forks","keys_url":"https://api.github.com/repos/getsentry/sentry/keys{/key_id}","collaborators_url":"https://api.github.com/repos/getsentry/sentry/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/getsentry/sentry/teams","hooks_url":"https://api.github.com/repos/getsentry/sentry/hooks","issue_events_url":"https://api.github.com/repos/getsentry/sentry/issues/events{/number}","events_url":"https://api.github.com/repos/getsentry/sentry/events","assignees_url":"https://api.github.com/repos/getsentry/sentry/assignees{/user}","branches_url":"https://api.github.com/repos/getsentry/sentry/branches{/branch}","tags_url":"https://api.github.com/repos/getsentry/sentry/tags","blobs_url":"https://api.github.com/repos/getsentry/sentry/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/getsentry/sentry/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/getsentry/sentry/git/refs{/sha}","trees_url":"https://api.github.com/repos/getsentry/sentry/git/trees{/sha}","statuses_url":"https://api.github.com/repos/getsentry/sentry/statuses/{sha}","languages_url":"https://api.github.com/repos/getsentry/sentry/languages","stargazers_url":"https://api.github.com/repos/getsentry/sentry/stargazers","contributors_url":"https://api.github.com/repos/getsentry/sentry/contributors","subscribers_url":"https://api.github.com/repos/getsentry/sentry/subscribers","subscription_url":"https://api.github.com/repos/getsentry/sentry/subscription","commits_url":"https://api.github.com/repos/getsentry/sentry/commits{/sha}","git_commits_url":"https://api.github.com/repos/getsentry/sentry/git/commits{/sha}","comments_url":"https://api.github.com/repos/getsentry/sentry/comments{/number}","issue_comment_url":"https://api.github.com/repos/getsentry/sentry/issues/comments{/number}","contents_url":"https://api.github.com/repos/getsentry/sentry/contents/{+path}","compare_url":"https://api.github.com/repos/getsentry/sentry/compare/{base}...{head}","merges_url":"https://api.github.com/repos/getsentry/sentry/merges","archive_url":"https://api.github.com/repos/getsentry/sentry/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/getsentry/sentry/downloads","issues_url":"https://api.github.com/repos/getsentry/sentry/issues{/number}","pulls_url":"https://api.github.com/repos/getsentry/sentry/pulls{/number}","milestones_url":"https://api.github.com/repos/getsentry/sentry/milestones{/number}","notifications_url":"https://api.github.com/repos/getsentry/sentry/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/getsentry/sentry/labels{/name}","releases_url":"https://api.github.com/repos/getsentry/sentry/releases{/id}","deployments_url":"https://api.github.com/repos/getsentry/sentry/deployments","created_at":"2010-08-30T22:06:41Z","updated_at":"2016-04-11T07:47:34Z","pushed_at":"2016-04-11T17:49:04Z","git_url":"git://github.com/getsentry/sentry.git","ssh_url":"git@github.com:getsentry/sentry.git","clone_url":"https://github.com/getsentry/sentry.git","svn_url":"https://github.com/getsentry/sentry","homepage":"https://getsentry.com","size":53791,"stargazers_count":8845,"watchers_count":8845,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1059,"mirror_url":null,"open_issues_count":268,"forks":1059,"open_issues":268,"watchers":8845,"default_branch":"master"}},"base":{"label":"getsentry:master","ref":"master","sha":"b16d0fb2950f48e0741061b7125bd4f2caab0208","user":{"login":"getsentry","id":1396951,"avatar_url":"https://avatars.githubusercontent.com/u/1396951?v=3","gravatar_id":"","url":"https://api.github.com/users/getsentry","html_url":"https://github.com/getsentry","followers_url":"https://api.github.com/users/getsentry/followers","following_url":"https://api.github.com/users/getsentry/following{/other_user}","gists_url":"https://api.github.com/users/getsentry/gists{/gist_id}","starred_url":"https://api.github.com/users/getsentry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getsentry/subscriptions","organizations_url":"https://api.github.com/users/getsentry/orgs","repos_url":"https://api.github.com/users/getsentry/repos","events_url":"https://api.github.com/users/getsentry/events{/privacy}","received_events_url":"https://api.github.com/users/getsentry/received_events","type":"Organization","site_admin":false},"repo":{"id":873328,"name":"sentry","full_name":"getsentry/sentry","owner":{"login":"getsentry","id":1396951,"avatar_url":"https://avatars.githubusercontent.com/u/1396951?v=3","gravatar_id":"","url":"https://api.github.com/users/getsentry","html_url":"https://github.com/getsentry","followers_url":"https://api.github.com/users/getsentry/followers","following_url":"https://api.github.com/users/getsentry/following{/other_user}","gists_url":"https://api.github.com/users/getsentry/gists{/gist_id}","starred_url":"https://api.github.com/users/getsentry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getsentry/subscriptions","organizations_url":"https://api.github.com/users/getsentry/orgs","repos_url":"https://api.github.com/users/getsentry/repos","events_url":"https://api.github.com/users/getsentry/events{/privacy}","received_events_url":"https://api.github.com/users/getsentry/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/getsentry/sentry","description":"Sentry is cross-platform crash reporting built with love","fork":false,"url":"https://api.github.com/repos/getsentry/sentry","forks_url":"https://api.github.com/repos/getsentry/sentry/forks","keys_url":"https://api.github.com/repos/getsentry/sentry/keys{/key_id}","collaborators_url":"https://api.github.com/repos/getsentry/sentry/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/getsentry/sentry/teams","hooks_url":"https://api.github.com/repos/getsentry/sentry/hooks","issue_events_url":"https://api.github.com/repos/getsentry/sentry/issues/events{/number}","events_url":"https://api.github.com/repos/getsentry/sentry/events","assignees_url":"https://api.github.com/repos/getsentry/sentry/assignees{/user}","branches_url":"https://api.github.com/repos/getsentry/sentry/branches{/branch}","tags_url":"https://api.github.com/repos/getsentry/sentry/tags","blobs_url":"https://api.github.com/repos/getsentry/sentry/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/getsentry/sentry/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/getsentry/sentry/git/refs{/sha}","trees_url":"https://api.github.com/repos/getsentry/sentry/git/trees{/sha}","statuses_url":"https://api.github.com/repos/getsentry/sentry/statuses/{sha}","languages_url":"https://api.github.com/repos/getsentry/sentry/languages","stargazers_url":"https://api.github.com/repos/getsentry/sentry/stargazers","contributors_url":"https://api.github.com/repos/getsentry/sentry/contributors","subscribers_url":"https://api.github.com/repos/getsentry/sentry/subscribers","subscription_url":"https://api.github.com/repos/getsentry/sentry/subscription","commits_url":"https://api.github.com/repos/getsentry/sentry/commits{/sha}","git_commits_url":"https://api.github.com/repos/getsentry/sentry/git/commits{/sha}","comments_url":"https://api.github.com/repos/getsentry/sentry/comments{/number}","issue_comment_url":"https://api.github.com/repos/getsentry/sentry/issues/comments{/number}","contents_url":"https://api.github.com/repos/getsentry/sentry/contents/{+path}","compare_url":"https://api.github.com/repos/getsentry/sentry/compare/{base}...{head}","merges_url":"https://api.github.com/repos/getsentry/sentry/merges","archive_url":"https://api.github.com/repos/getsentry/sentry/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/getsentry/sentry/downloads","issues_url":"https://api.github.com/repos/getsentry/sentry/issues{/number}","pulls_url":"https://api.github.com/repos/getsentry/sentry/pulls{/number}","milestones_url":"https://api.github.com/repos/getsentry/sentry/milestones{/number}","notifications_url":"https://api.github.com/repos/getsentry/sentry/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/getsentry/sentry/labels{/name}","releases_url":"https://api.github.com/repos/getsentry/sentry/releases{/id}","deployments_url":"https://api.github.com/repos/getsentry/sentry/deployments","created_at":"2010-08-30T22:06:41Z","updated_at":"2016-04-11T07:47:34Z","pushed_at":"2016-04-11T17:49:04Z","git_url":"git://github.com/getsentry/sentry.git","ssh_url":"git@github.com:getsentry/sentry.git","clone_url":"https://github.com/getsentry/sentry.git","svn_url":"https://github.com/getsentry/sentry","homepage":"https://getsentry.com","size":53791,"stargazers_count":8845,"watchers_count":8845,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1059,"mirror_url":null,"open_issues_count":268,"forks":1059,"open_issues":268,"watchers":8845,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/3016"},"html":{"href":"https://github.com/getsentry/sentry/pull/3016"},"issue":{"href":"https://api.github.com/repos/getsentry/sentry/issues/3016"},"comments":{"href":"https://api.github.com/repos/getsentry/sentry/issues/3016/comments"},"review_comments":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/3016/comments"},"review_comment":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/3016/commits"},"statuses":{"href":"https://api.github.com/repos/getsentry/sentry/statuses/b96391d28684cc8f0eeccf7ab50aeb76a96a46d3"}}}}