def post(self, *args):
        """Returns alert data in response to API requests.

    Outputs:
      JSON results.
    """
        self._SetCorsHeadersIfAppropriate()
        try:
            api_auth.Authorize()
        except api_auth.NotLoggedInError as e:
            if not self._AllowAnonymous():
                self.WriteErrorMessage(e.message, 401)
                return
        except api_auth.OAuthError as e:
            self.WriteErrorMessage(e.message, 403)
            return
        # Allow oauth.Error to manifest as HTTP 500.

        try:
            results = self.AuthorizedPost(*args)
            self.response.out.write(json.dumps(results))
        except NotFoundError as e:
            self.WriteErrorMessage(e.message, 404)
        except BadRequestError as e:
            self.WriteErrorMessage(e.message, 400)
예제 #2
0
 def testPost_OAuthUser_ServiceAccount(self):
     self.SetCurrentUserOAuth(testing_common.SERVICE_ACCOUNT_USER)
     testing_common.SetIsInternalUser(testing_common.SERVICE_ACCOUNT_USER,
                                      True)
     with self.PatchEnviron('/api/fake'):
         api_auth.Authorize()
     self.assertTrue(self.mock_set_privileged_request.called)
예제 #3
0
    def post(self, *args):
        """Returns alert data in response to API requests.

    Outputs:
      JSON results.
    """
        self._SetCorsHeadersIfAppropriate()
        try:
            api_auth.Authorize()
        except api_auth.NotLoggedInError as e:
            if not self._AllowAnonymous():
                self.WriteErrorMessage(e.message, 401)
                return
        except api_auth.OAuthError as e:
            self.WriteErrorMessage(e.message, 403)
            return
        # Allow oauth.Error to manifest as HTTP 500.

        try:
            if utils.IsInternalUser():
                results = self.PrivilegedPost(*args)
            else:
                results = self.UnprivilegedPost(*args)
            self.response.out.write(json.dumps(results))
        except NotFoundError as e:
            self.WriteErrorMessage(e.message, 404)
        except ForbiddenError as e:
            self.WriteErrorMessage(e.message, 403)
        except (BadRequestError, KeyError, TypeError, ValueError) as e:
            self.WriteErrorMessage(e.message, 400)
예제 #4
0
    def post(self, *args):
        """Returns alert data in response to API requests.

    Outputs:
      JSON results.
    """
        self._SetCorsHeadersIfAppropriate()
        try:
            api_auth.Authorize()
        except api_auth.NotLoggedInError as e:
            self.WriteErrorMessage(e.message, 401)
            return
        except api_auth.OAuthError as e:
            self.WriteErrorMessage(e.message, 403)
            return

        try:
            results = self.AuthorizedPost(*args)
            self.response.out.write(json.dumps(results))
        except BadRequestError as e:
            self.WriteErrorMessage(e.message, 400)
예제 #5
0
 def testPost_OauthUser_Unauthorized(self):
     self.SetCurrentUserOAuth(testing_common.EXTERNAL_USER)
     with self.assertRaises(api_auth.OAuthError):
         with self.PatchEnviron('/api/fake'):
             api_auth.Authorize()
     self.assertFalse(self.mock_set_privileged_request.called)
예제 #6
0
 def testPost_OAuthUser_User_InChromeperfAccess(self):
     self.SetCurrentUserOAuth(testing_common.INTERNAL_USER)
     self.SetCurrentClientIdOAuth(api_auth.OAUTH_CLIENT_ID_WHITELIST[0])
     with self.PatchEnviron('/api/fake'):
         api_auth.Authorize()
     self.assertTrue(self.mock_set_privileged_request.called)
예제 #7
0
 def testPost_OAuthUser_ServiceAccount_NotInChromeperfAccess(self):
     self.SetCurrentUserOAuth(testing_common.SERVICE_ACCOUNT_USER)
     with self.PatchEnviron('/api/fake'):
         api_auth.Authorize()
     self.assertFalse(self.mock_set_privileged_request.called)
예제 #8
0
 def testPost_NoUser(self):
     self.SetCurrentUserOAuth(None)
     with self.assertRaises(api_auth.NotLoggedInError):
         with self.PatchEnviron('/api/fake'):
             api_auth.Authorize()
     self.assertFalse(self.mock_set_privileged_request.called)
예제 #9
0
 def _CheckIsLoggedIn(self):
   if utils.IsDevAppserver():
     return
   api_auth.Authorize()
예제 #10
0
    def post(self):
        """Validates data parameter and add task to queue to process points.

    The row data comes from a "data" parameter, which is a JSON encoding of a
    list of dictionaries, each of which represents one performance result
    (one point in a graph) and associated data.

      [
        {
          "master": "ChromiumPerf",
          "bot": "xp-release-dual-core",
          "test": "dromaeo/dom/modify",
          "revision": 123456789,
          "value": 24.66,
          "error": 2.33,
          "units": "ms",
          "supplemental_columns": {
            "d_median": 24234.12,
            "d_mean": 23.553,
            "r_webkit": 423340,
            ...
          },
          ...
        },
        ...
      ]

    In general, the required fields are "master", "bot", "test" (which together
    form the test path which identifies the series that this point belongs to),
    and "revision" and "value", which are the X and Y values for the point.

    This API also supports the Dashboard JSON v1.0 format (go/telemetry-json),
    the first producer of which is Telemetry. Telemetry provides lightweight
    serialization of values it produces, as JSON. If a dashboard JSON object is
    passed, it will be a single dict rather than a list, with the test,
    value, error, and units fields replaced by a chart_data field containing a
    Chart JSON dict (see design doc, and example below). Dashboard JSON v1.0 is
    processed by converting it into rows (which can be viewed as Dashboard JSON
    v0).

    {
      "master": "ChromiumPerf",
      <other row fields>,
      "chart_data": {
        "foo": {
          "bar": {
            "type": "scalar",
            "name": "foo.bar",
            "units": "ms",
            "value": 4.2,
          },
          "summary": {
            "type": "list_of_scalar_values",
            "name": "foo",
            "units": "ms",
            "values": [4.2, 5.7, 6.8],
            "std": 1.30512,
          },
      },
    }

    Request parameters:
      data: JSON encoding of a list of dictionaries.

    Outputs:
      Empty 200 response with if successful,
      200 response with warning message if optional data is invalid,
      403 response with error message if sender IP is not white-listed,
      400 response with error message if required data is invalid.
      500 with error message otherwise.
    """
        datastore_hooks.SetPrivilegedRequest()
        if not self._CheckIpAgainstWhitelist():
            try:
                api_auth.Authorize()
            except api_auth.ApiAuthException as error:
                logging.error('Auth error: %s', error)
                self.ReportError(
                    'IP address %s not in IP whitelist!' %
                    self.request.remote_addr, 403)
                return

        data_str = self.request.get('data')
        if not data_str:
            self.ReportError('Missing "data" parameter.', status=400)
            return

        self.AddData(data_str)