mirror of
https://github.com/end-4/dots-hyprland.git
synced 2026-06-15 03:04:31 +10:00
31 lines
926 B
Python
Executable File
31 lines
926 B
Python
Executable File
#!/usr/bin/env python3
|
|
import sys
|
|
import json
|
|
import google.auth.transport.requests
|
|
import google.oauth2.service_account
|
|
|
|
def get_token(json_str):
|
|
try:
|
|
# Load the string into a dictionary
|
|
info = json.loads(json_str)
|
|
|
|
# Initialize credentials
|
|
creds = google.oauth2.service_account.Credentials.from_service_account_info(info)
|
|
scoped_creds = creds.with_scopes(['https://www.googleapis.com/auth/cloud-platform'])
|
|
|
|
# Refresh to get the access token
|
|
request = google.auth.transport.requests.Request()
|
|
scoped_creds.refresh(request)
|
|
|
|
print(scoped_creds.token)
|
|
except Exception as e:
|
|
sys.stderr.write(f"Error: {str(e)}\n")
|
|
sys.exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) < 2:
|
|
sys.stderr.write("Usage: python3 get_token.py '<json_string>'\n")
|
|
sys.exit(1)
|
|
|
|
get_token(sys.argv[1])
|