Example #1
0
def Retrieve(server, digest):
    # TODO(dberris): Migrate this to return a file-like object, so that we can do
    # incremental decoding and decompression, instead of attempting to load data
    # in memory for processing.
    url = server + '/_ah/api/isolateservice/v1/retrieve'
    body = {
        'namespace': {
            'namespace': 'default-gzip'
        },
        'digest': digest,
    }

    isolate_info = request.RequestJson(url, 'POST', body)

    if 'url' in isolate_info:
        # TODO(dberris): If this is a URL for a file in Google Cloud Storage, we
        # should use the file interface instead.
        return zlib.decompress(request.Request(isolate_info['url'], 'GET'))

    if 'content' in isolate_info:
        # TODO(dberris): If the data is inline in the response, then we should use
        # an adapter (like io.StringIO).
        return zlib.decompress(base64.b64decode(isolate_info['content']))

    raise NotImplementedError(
        'Isolate information for %s is in an unknown format: %s' %
        (digest, json.dumps(isolate_info)))
Example #2
0
def CommitRange(repository_url, first_git_hash, last_git_hash):
    """Fetches the commits in between first and last, including the latter.

  Args:
    repository_url: The git url of the repository.
    first_git_hash: The git hash of the earliest commit in the range.
    last_git_hash: The git hash of the latest commit in the range.

  Returns:
    A list of dictionaries, one for each commit after the first commit up to
    and including the last commit. For each commit, its dictionary will
    contain information about the author and the comitter and the commit itself.
    See gitiles_service_test.py for an example. The list is in order from newest
    to oldest.

  Raises:
    NotFoundError: The repository or a commit was not found in Gitiles.
    httplib.HTTPException: A network or HTTP error occurred.
  """
    commits = []
    while last_git_hash:
        url = '%s/+log/%s..%s?format=JSON' % (repository_url, first_git_hash,
                                              last_git_hash)
        use_cache = IsHash(first_git_hash) and IsHash(last_git_hash)
        response = request.RequestJson(url,
                                       use_cache=use_cache,
                                       use_auth=True,
                                       scope=gerrit_service.GERRIT_SCOPE)
        commits += response['log']
        last_git_hash = response.get('next')
    return commits
def Put(bucket, parameters):
    body = {
        'bucket': bucket,
        'parameters_json': json.dumps(parameters, separators=(',', ':')),
    }
    return request.RequestJson(API_BASE_URL + 'builds',
                               method='PUT',
                               body=body)
Example #4
0
def Put(bucket, tags, parameters, pubsub_callback=None):
  body = {
      'bucket': bucket,
      'tags': tags,
      'parameters_json': json.dumps(parameters, separators=(',', ':')),
  }
  if pubsub_callback:
    body['pubsub_callback'] = pubsub_callback
  return request.RequestJson(API_BASE_URL + 'builds', method='PUT', body=body)
Example #5
0
def _Request(endpoint, params):
    """Sends a request to an endpoint and returns JSON data."""
    assert datastore_hooks.IsUnalteredQueryPermitted()

    return request.RequestJson(endpoint,
                               method='POST',
                               use_cache=False,
                               use_auth=True,
                               **params)
Example #6
0
    def New(self, body):
        """Creates a new task.

    The task will be enqueued in the tasks list and will be executed at the
    earliest opportunity by a bot that has at least the dimensions as described
    in the task request.
    """
        url = '%s/%s/tasks/new' % (self._server, _API_PATH)
        return request.RequestJson(url, method='POST', body=body)
Example #7
0
    def New(self, body):
        """Creates a new task.

    The task will be enqueued in the tasks list and will be executed at the
    earliest opportunity by a bot that has at least the dimensions as described
    in the task request.
    """
        return request.RequestJson(API_BASE_URL + 'tasks/new',
                                   method='POST',
                                   body=body)
Example #8
0
def GetNumbering(number, numbering_identifier, numbering_type, project, repo):
    params = {
        'number': number,
        'numbering_identifier': numbering_identifier,
        'numbering_type': numbering_type,
        'project': project,
        'repo': repo
    }

    return request.RequestJson(_URL + 'get_numbering', 'GET', **params)
def GetNumbering(number, numbering_identifier, numbering_type, project, repo):
    url = 'https://cr-rev.appspot.com/_ah/api/crrev/v1/get_numbering'
    params = {
        'number': number,
        'numbering_identifier': numbering_identifier,
        'numbering_type': numbering_type,
        'project': project,
        'repo': repo
    }

    return request.RequestJson(url, 'GET', **params)
Example #10
0
def _Request(endpoint, params):
    """Sends a request to an endpoint and returns JSON data."""
    assert datastore_hooks.IsUnalteredQueryPermitted()

    try:
        return request.RequestJson(endpoint,
                                   method='POST',
                                   use_cache=False,
                                   use_auth=True,
                                   **params)
    except request.RequestError as e:
        return json.loads(e.content)
Example #11
0
    def List(self,
             cursor=None,
             dimensions=None,
             is_dead=None,
             limit=None,
             quarantined=None):
        """Provides list of known bots. Deleted bots will not be listed."""
        if dimensions:
            dimensions = tuple(':'.join(dimension)
                               for dimension in dimensions.iteritems())

        return request.RequestJson(API_BASE_URL + 'bots/list',
                                   cursor=cursor,
                                   dimensions=dimensions,
                                   is_dead=is_dead,
                                   limit=limit,
                                   quarantined=quarantined)
Example #12
0
    def List(self,
             cursor=None,
             dimensions=None,
             is_dead=None,
             limit=None,
             quarantined=None):
        """Provides list of known bots. Deleted bots will not be listed."""
        if dimensions:
            dimensions = tuple(':'.join(dimension)
                               for dimension in dimensions.iteritems())

        url = '%s/%s/bots/list' % (self._server, _API_PATH)
        return request.RequestJson(url,
                                   cursor=cursor,
                                   dimensions=dimensions,
                                   is_dead=is_dead,
                                   limit=limit,
                                   quarantined=quarantined)
Example #13
0
def Retrieve(digest):
  url = 'https://isolateserver.appspot.com/_ah/api/isolateservice/v1/retrieve'
  body = {
      'namespace': {'namespace': 'default-gzip'},
      'digest': digest,
  }

  isolate_info = request.RequestJson(url, 'POST', body)

  if 'url' in isolate_info:
    return zlib.decompress(request.Request(isolate_info['url'], 'GET'))

  if 'content' in isolate_info:
    return zlib.decompress(base64.b64decode(isolate_info['content']))

  raise NotImplementedError(
      'Isolate information for %s is in an unknown format: %s' %
      (digest, json.dumps(isolate_info)))
Example #14
0
def CommitInfo(repository_url, git_hash):
    """Fetches information about a commit.

  Args:
    repository_url: The url of the git repository.
    git_hash: The git hash of the commit.

  Returns:
    A dictionary containing the author, message, time, file changes, and other
    information. See gitiles_service_test.py for an example.

  Raises:
    NotFoundError: The repository or commit was not found in Gitiles.
    httplib.HTTPException: A network or HTTP error occurred.
  """
    # TODO: Update the docstrings in this file.
    url = '%s/+/%s?format=JSON' % (repository_url, git_hash)
    return request.RequestJson(url,
                               use_cache=_IsHash(git_hash),
                               use_auth=False)
Example #15
0
 def _Request(self, path, **kwargs):
     url = '%s/%s/bot/%s/%s' % (self._server, _API_PATH, self._bot_id, path)
     return request.RequestJson(url, **kwargs)
Example #16
0
def GetChange(server_url, change_id, fields=None):
    url = '%s/changes/%s' % (server_url, change_id)
    return request.RequestJson(url, o=fields)
Example #17
0
def GetCommit(git_sha):
    return request.RequestJson(_URL + 'commit/%s' % git_sha, 'GET', None)
Example #18
0
 def testRequestJsonWithPrefix(self):
     self._request.return_value = ({'status': '200'}, ')]}\'\n"response"')
     response = request.RequestJson('https://example.com')
     self._request.assert_called_once_with('https://example.com',
                                           method='GET')
     self.assertEqual(response, 'response')
Example #19
0
def GetChange(server_url, change_id, fields=None):
    url = '%s/changes/%s' % (server_url, change_id)
    return request.RequestJson(url,
                               use_auth=True,
                               scope=GERRIT_SCOPE,
                               o=fields)
Example #20
0
 def _Request(self, path, **kwargs):
     return request.RequestJson(
         API_BASE_URL + 'task/%s/%s' % (self._task_id, path), **kwargs)
def GetJobStatus(job_id):
    """Gets the details of a job via buildbucket's API."""
    return request.RequestJson(API_BASE_URL + 'builds/%s' % (job_id))
Example #22
0
def GetChange(server_url, change_id, fields=None):
    url = '%s/changes/%s' % (server_url, change_id)
    # TODO: Re-add auth after https://crbug.com/892756 is fixed.
    return request.RequestJson(url, use_auth=False, o=fields)