From 9f5b0fef64c454fd4e9be09b22acd039d904e8c1 Mon Sep 17 00:00:00 2001 From: mythilytm Date: Tue, 23 Jul 2024 18:45:43 -0400 Subject: [PATCH] replace with sheet id w/ better error handling --- .github/workflows/sheetsapi.yml | 2 +- update_matrix.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sheetsapi.yml b/.github/workflows/sheetsapi.yml index 674bcf5..6718481 100644 --- a/.github/workflows/sheetsapi.yml +++ b/.github/workflows/sheetsapi.yml @@ -22,7 +22,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client gspread + pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client gspread re - name: Update Google Sheets env: diff --git a/update_matrix.py b/update_matrix.py index 24eeae6..4d6c03a 100644 --- a/update_matrix.py +++ b/update_matrix.py @@ -2,6 +2,7 @@ import json import sys import gspread +import re from google.oauth2.service_account import Credentials from google.auth.exceptions import GoogleAuthError @@ -10,8 +11,12 @@ def main(): # Load credentials from the environment variable credentials_json = os.getenv('GOOGLE_SHEETS_CREDENTIALS') sheet_id = os.getenv('GOOGLE_SHEET_ID') - if not credentials_json or not sheet_id: - raise ValueError("No credentials found in environment variable.") + if not credentials_json: + raise ValueError("Credentials JSON not found in environment variable.") + if not sheet_id: + raise ValueError("Sheet ID not found in environment variable.") + if not re.match(r'^[a-zA-Z0-9-_]+$', sheet_id): + raise ValueError("Invalid Google Sheet ID.") credentials_data = json.loads(credentials_json) print("Credentials loaded successfully.")