Spaces:
Sleeping
Sleeping
manage json secret
Browse files
config.py
CHANGED
@@ -29,59 +29,44 @@ print("DEBUG: Handling BigQuery credentials...")
|
|
29 |
if os.environ.get("BIGQUERY_KEY_PATH"):
|
30 |
bigquery_key = os.environ.get("BIGQUERY_KEY_PATH")
|
31 |
print(f"DEBUG: BIGQUERY_KEY_PATH is set, length: {len(bigquery_key)} characters")
|
32 |
-
print(f"DEBUG: First 20 chars: {bigquery_key[:20]}...")
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
# Verify the file exists
|
55 |
-
if os.path.exists(credentials_path):
|
56 |
-
print(f"DEBUG: Confirmed credentials file exists at {credentials_path}")
|
57 |
with open(credentials_path, "r") as f:
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
print(f"
|
62 |
-
|
63 |
-
|
64 |
-
print("
|
65 |
-
|
66 |
-
|
67 |
-
print(f"DEBUG: BIGQUERY_KEY_PATH points to existing file: {bigquery_key}")
|
68 |
-
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = bigquery_key
|
69 |
-
else:
|
70 |
-
print(f"WARNING: BIGQUERY_KEY_PATH is set but does not contain JSON and is not a valid file path: {bigquery_key}")
|
71 |
else:
|
72 |
print("WARNING: BIGQUERY_KEY_PATH environment variable is not set")
|
73 |
|
74 |
-
# BigQuery configurationo
|
75 |
-
BIGQUERY_KEY_PATH = bigquery_key
|
76 |
-
PROJECT_ID = os.environ.get("PROJECT_ID")
|
77 |
-
DATASET_ID = os.environ.get("DATASET_ID")
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
print("DEBUG: GOOGLE_APPLICATION_CREDENTIALS file exists")
|
84 |
-
else:
|
85 |
-
print("ERROR: GOOGLE_APPLICATION_CREDENTIALS file does not exist")
|
86 |
else:
|
87 |
-
print("WARNING:
|
|
|
|
29 |
if os.environ.get("BIGQUERY_KEY_PATH"):
|
30 |
bigquery_key = os.environ.get("BIGQUERY_KEY_PATH")
|
31 |
print(f"DEBUG: BIGQUERY_KEY_PATH is set, length: {len(bigquery_key)} characters")
|
|
|
32 |
|
33 |
+
# Create a temporary credentials file from the environment variable
|
34 |
+
credentials_path = "/tmp/bigquery_credentials.json"
|
35 |
+
|
36 |
+
try:
|
37 |
+
# Try to directly write the content to a file without JSON parsing
|
38 |
+
with open(credentials_path, "w") as f:
|
39 |
+
f.write(bigquery_key)
|
40 |
+
|
41 |
+
print(f"DEBUG: Wrote credentials to {credentials_path}")
|
42 |
+
|
43 |
+
|
44 |
+
os.environ["BIGQUERY_KEY_PATH"] = credentials_path
|
45 |
+
print(f"DEBUG: Set BIGQUERY_KEY_PATH to {credentials_path}")
|
46 |
+
|
47 |
+
# Verify the file exists
|
48 |
+
if os.path.exists(credentials_path):
|
49 |
+
print(f"DEBUG: Confirmed credentials file exists at {credentials_path}")
|
50 |
+
# Try to validate the JSON by reading it back
|
51 |
+
try:
|
|
|
|
|
|
|
|
|
52 |
with open(credentials_path, "r") as f:
|
53 |
+
json.load(f)
|
54 |
+
print("DEBUG: Credentials file contains valid JSON")
|
55 |
+
except json.JSONDecodeError as e:
|
56 |
+
print(f"WARNING: Credentials file contains invalid JSON: {str(e)}")
|
57 |
+
print("This might cause issues with BigQuery authentication")
|
58 |
+
else:
|
59 |
+
print(f"ERROR: Failed to create credentials file at {credentials_path}")
|
60 |
+
except Exception as e:
|
61 |
+
print(f"ERROR: Failed to process BigQuery credentials: {str(e)}")
|
|
|
|
|
|
|
|
|
62 |
else:
|
63 |
print("WARNING: BIGQUERY_KEY_PATH environment variable is not set")
|
64 |
|
|
|
|
|
|
|
|
|
65 |
|
66 |
+
|
67 |
+
# Final check for credentials
|
68 |
+
if os.path.exists(os.environ.get("BIGQUERY_KEY_PATH", "")):
|
69 |
+
print(f"DEBUG: BIGQUERY_KEY_PATH file exists at: {os.environ.get('BIGQUERY_KEY_PATH')}")
|
|
|
|
|
|
|
70 |
else:
|
71 |
+
print(f"WARNING: BIGQUERY_KEY_PATH file does not exist at: {os.environ.get('BIGQUERY_KEY_PATH')}")
|
72 |
+
|