| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import base64 | 5 import base64 |
| 6 import json | 6 import json |
| 7 import logging | 7 import logging |
| 8 | 8 |
| 9 from common import constants | 9 from common import constants |
| 10 from common.base_handler import BaseHandler | 10 from common.base_handler import BaseHandler |
| 11 from common.base_handler import Permission | 11 from common.base_handler import Permission |
| 12 from crash import fracas_crash_pipeline | 12 from crash import fracas_crash_pipeline |
| 13 from model.crash.crash_config import CrashConfig | |
| 14 | |
| 15 | |
| 16 FRACAS_ANALYSIS_QUEUE = 'fracas-crash-queue' | |
| 17 | 13 |
| 18 | 14 |
| 19 class FracasCrash(BaseHandler): | 15 class FracasCrash(BaseHandler): |
| 20 PERMISSION_LEVEL = Permission.ANYONE | 16 PERMISSION_LEVEL = Permission.ADMIN |
| 21 | 17 |
| 22 def HandlePost(self): | 18 def HandlePost(self): |
| 23 """Handles push delivery from Pub/Sub for crash data. | 19 """Handles push delivery from Pub/Sub for crash data. |
| 24 | 20 |
| 25 The crash data should be in the following json format: | 21 The crash data should be in the following json format: |
| 26 { | 22 { |
| 27 'channel': 'canary', | 23 'channel': 'canary', |
| 28 'platform': 'win', | 24 'platform': 'win', |
| 29 'signature': 'namesapce1:namespace2:class_name:func_name', | 25 'signature': 'namesapce1:namespace2:class_name:func_name', |
| 30 'stack_trace': 'frame1\nframe2\nframe3', | 26 'stack_trace': 'frame1\nframe2\nframe3', |
| 31 'chrome_version': '50.0.2500.0', | 27 'chrome_version': '50.0.2500.0', |
| 32 'versions_to_cpm': { | 28 'versions_to_cpm': { |
| 33 '50.0.2500.0': 1.2, | 29 '50.0.2500.0': 1.2, |
| 34 '50.0.2499.0': 1.0, | 30 '50.0.2499.0': 1.0, |
| 35 }, | 31 }, |
| 36 } | 32 } |
| 37 """ | 33 """ |
| 38 token = self.request.get('token', '').strip() | |
| 39 crash_config = CrashConfig.Get() | |
| 40 if token != crash_config.fracas.get('crash_data_push_token'): | |
| 41 logging.warning('Unauthorized access.') | |
| 42 return self.CreateError( | |
| 43 'Unauthorized access: invalid token "%s"' % token, 403) | |
| 44 | |
| 45 received_message = json.loads(self.request.body) | 34 received_message = json.loads(self.request.body) |
| 46 pubsub_message = received_message['message'] | 35 pubsub_message = received_message['message'] |
| 47 crash_data = json.loads(base64.b64decode(pubsub_message['data'])) | 36 crash_data = json.loads(base64.b64decode(pubsub_message['data'])) |
| 48 | 37 |
| 49 logging.info('Processing message %s from subscription %s.', | 38 logging.info('Processing message %s from subscription %s.', |
| 50 pubsub_message['message_id'], received_message['subscription']) | 39 pubsub_message['message_id'], received_message['subscription']) |
| 51 | 40 |
| 52 fracas_crash_pipeline.ScheduleNewAnalysisForCrash( | 41 try: |
| 53 crash_data['channel'], crash_data['platform'], crash_data['signature'], | 42 fracas_crash_pipeline.ScheduleNewAnalysisForCrash( |
| 54 crash_data['stack_trace'], crash_data['chrome_version'], | 43 crash_data['channel'], crash_data['platform'], |
| 55 crash_data['versions_to_cpm'], | 44 crash_data['signature'], crash_data['stack_trace'], |
| 56 queue_name=constants.CRASH_ANALYSIS_FRACAS_QUEUE) | 45 crash_data['chrome_version'], crash_data['versions_to_cpm'], |
| 46 queue_name=constants.CRASH_ANALYSIS_FRACAS_QUEUE) |
| 47 except KeyError: # pragma: no cover. |
| 48 # TODO: save exception in datastore and create a page to show them. |
| 49 logging.exception('Failed to process fracas message') |
| OLD | NEW |