Skip to content

Instantly share code, notes, and snippets.

@mpaloni
Last active March 20, 2025 13:14
Show Gist options
  • Save mpaloni/4c4d90b49d63957fcf1ecb5c6f8c0edd to your computer and use it in GitHub Desktop.
Save mpaloni/4c4d90b49d63957fcf1ecb5c6f8c0edd to your computer and use it in GitHub Desktop.
gcloud cli
gcloud config configurations create my-profile
gcloud config set account [email protected]
gcloud config configurations list
gcloud config configurations activate my-profile
gcloud auth application-default login
from google.cloud import bigquery
# Authenticate with the service account JSON key
client = bigquery.Client.from_service_account_json("./service-account.json")
# Define the query
query = """
SELECT
table_catalog AS project_id,
table_schema AS dataset_name,
table_name
FROM `project.dataset.INFORMATION_SCHEMA.TABLES`
ORDER BY dataset_name, table_name;
"""
# Run the query
query_job = client.query(query,location="europe-north1")
results = query_job.result()
# Print the results
for row in results:
print(row)
# Check metadata
import requests
metadata_url = "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/email"
headers = {"Metadata-Flavor": "Google"}
response = requests.get(metadata_url, headers=headers)
print(f"Service Account Email: {response.text}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment