Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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"):
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)
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)
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 = ''
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()
def get_vision_service():
credentials = GoogleCredentials.get_application_default()
return discovery.build('vision', 'v1', credentials=credentials,
discoveryServiceUrl=DISCOVERY_URL)
# [END get_vision_service]
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)
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,
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)
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