How to use the oauth2client.client.GoogleCredentials function in oauth2client

To help you get started, we’ve selected a few oauth2client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kubeflow / kubeflow / testing / test_deploy.py View on Github external
def teardown_minikube(args):
  """Delete the VM used for minikube."""

  credentials = GoogleCredentials.get_application_default()
  gce = discovery.build("compute", "v1", credentials=credentials)
  instances = gce.instances()

  request = instances.delete(
      project=args.project, zone=args.zone, instance=args.vm_name)

  response = request.execute()

  op_id = response.get("name")
  final_op = vm_util.wait_for_operation(gce, args.project, args.zone, op_id)

  logging.info("Final result for delete operation: %s", final_op)
  if final_op.get("status") != "DONE":
    raise ValueError("Delete operation has status %s", final_op.get("status"))

  if final_op.get("error"):
github googleapis / oauth2client / tests / test_client.py View on Github external
def test_to_from_json_service_account_scoped(self):
        credentials_file = datafile(
            os.path.join('gcloud', client._WELL_KNOWN_CREDENTIALS_FILE))
        creds1 = client.GoogleCredentials.from_stream(credentials_file)
        creds1 = creds1.create_scoped(['dummy_scope'])
        # Convert to and then back from json.
        creds2 = client.GoogleCredentials.from_json(creds1.to_json())

        creds1_vals = creds1.__dict__
        creds1_vals.pop('_signer')
        creds2_vals = creds2.__dict__
        creds2_vals.pop('_signer')
        self.assertEqual(creds1_vals, creds2_vals)
github googleapis / oauth2client / scripts / run_system_tests.py View on Github external
def run_user_json():
    with open(USER_KEY_PATH, 'r') as file_object:
        client_credentials = json.load(file_object)

    credentials = client.GoogleCredentials(
        access_token=None,
        client_id=client_credentials['client_id'],
        client_secret=client_credentials['client_secret'],
        refresh_token=client_credentials['refresh_token'],
        token_expiry=None,
        token_uri=oauth2client.GOOGLE_TOKEN_URI,
        user_agent='Python client library',
    )

    _check_user_info(credentials, USER_KEY_EMAIL)
github cloud-ark / caastle / server / server_plugins / gcloud / coe / gke_single_container.py View on Github external
def __init__(self):
        credentials = GoogleCredentials.get_application_default()
        self.gke_service = discovery.build('container', 'v1',
                                           credentials=credentials)
        self.compute_service = discovery.build('compute', 'v1',
                                               credentials=credentials,
                                               cache_discovery=False)
        self.docker_handler = docker_lib.DockerLib()

        self.app_yaml_def = ''
github aiven / pghoard / pghoard / rohmu / object_storage / google.py View on Github external
def get_credentials(credential_file=None, credentials=None):
    if credential_file:
        return GoogleCredentials.from_stream(credential_file)

    if credentials and credentials["type"] == "service_account":
        return ServiceAccountCredentials_from_dict(credentials)

    if credentials and credentials["type"] == "authorized_user":
        return GoogleCredentials(
            access_token=None,
            client_id=credentials["client_id"],
            client_secret=credentials["client_secret"],
            refresh_token=credentials["refresh_token"],
            token_expiry=None,
            token_uri=GOOGLE_TOKEN_URI,
            user_agent="pghoard")

    return GoogleCredentials.get_application_default()
github GoogleCloudPlatform / cloud-vision / python / landmark_detection / detect_landmark.py View on Github external
def get_vision_service():
    credentials = GoogleCredentials.get_application_default()
    return discovery.build('vision', 'v1', credentials=credentials,
                           discoveryServiceUrl=DISCOVERY_URL)
# [END get_vision_service]
github GoogleCloudPlatform / cloud-pubsub-samples-python / gce-cmdline-publisher / traffic_pubsub_generator.py View on Github external
def create_pubsub_client():
    """Build the pubsub client."""
    credentials = GoogleCredentials.get_application_default()
    if credentials.create_scoped_required():
        credentials = credentials.create_scoped(PUBSUB_SCOPES)
    return discovery.build('pubsub', 'v1beta2', credentials=credentials)
github googlearchive / bigquery-samples-python / python / samples / load_data_by_post.py View on Github external
def main():
    credentials = GoogleCredentials.get_application_default()
    http = credentials.authorize(httplib2.Http())
    projectId = raw_input('Enter the project ID: ')
    datasetId = raw_input('Enter a dataset ID: ')
    tableId = raw_input('Enter a table name to load the data to: ')
    schema_path = raw_input(
            'Enter the path to the schema file for the table: ')

    with open(schema_path, 'r') as schema_file:
        schema = schema_file.read()

    data_path = raw_input('Enter the path to the data file: ')

    with open(data_path, 'r') as data_file:
        data = data_file.read()

    resp, content = make_post(http,
github 0x0ece / oscars2016 / python-pubsub / pslib / __init__.py View on Github external
def create_pubsub_client(http=None):
    credentials = oauth2client.GoogleCredentials.get_application_default()
    if credentials.create_scoped_required():
        credentials = credentials.create_scoped(PUBSUB_SCOPES)
    if not http:
        http = httplib2.Http()
    credentials.authorize(http)

    return discovery.build('pubsub', 'v1', http=http)
github lukwam / gcp-tools / lib / google.py View on Github external
credentials = self.auth_stored_credentials(
                client_secrets_file=client_secrets_file,
                scopes=self.scopes
            )

        elif service_account_file:
            credentials = ServiceAccountCredentials.from_json_keyfile_name(
                service_account_file,
                scopes=self.scopes,
            )
            if sub_account:
                credentials = credentials.create_delegated(sub_account)

        else:
            # get application-default credentials from gcloud
            credentials = GoogleCredentials.get_application_default()

        self.credentials = credentials
        self.http = credentials.authorize(httplib2.Http())


        #
        # build the various services that we'll need
        #

        # admin directory
        self.admin = build('admin', 'directory_v1', credentials=credentials)

        # build a cloud billing API service
        self.billing = build('cloudbilling', 'v1', credentials=credentials)

        # build a compute API service