Beispiel #1
0
def main(argv):
    parser = GetParser()
    opts = parser.parse_args(argv)
    opts.Freeze()
    creds = androidbuild.LoadCredentials(opts.json_key_file)
    ab_client = androidbuild.GetApiClient(creds)
    return opts.func(ab_client, opts)
  def testGetApiClient(self):
    """Checks that the correct calls are used to connect the API client."""
    creds = mock.Mock()
    with mock.patch.object(httplib2, 'Http') as mock_http, \
        mock.patch.object(apiclient.discovery, 'build') as mock_build:

      # Create the ab_client.
      ab_client = androidbuild.GetApiClient(creds)

      # Check that creds were used to authorize the Http server.
      mock_http.assert_called_once_with()
      creds.authorize.assert_called_once_with(mock_http.return_value)
      mock_build.assert_called_once_with(
          'androidbuildinternal', 'v2beta1',
          http=creds.authorize.return_value)
      self.assertEqual(ab_client, mock_build.return_value)
Beispiel #3
0
def OpenBuildApiProxy(json_key_file):
    """Open an Android Internal Build API Apiary proxy.

  Will NOT error out if authentication fails until the first real request is
  made.

  Args:
    json_key_file: A Json key file to authenticate with. Retrieved from the
                   Google Developer Console associated with the account to
                   be used for the requests.

  Returns:
    Proxy object used to make requests against the API.
  """
    # Load the private key associated with the Google service account.
    creds = androidbuild.LoadCredentials(json_credentials_path=json_key_file)
    return androidbuild.GetApiClient(creds)