File size: 1,403 Bytes
e9456a0
 
 
 
 
 
 
 
 
 
 
c4bca54
 
e9456a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c4bca54
 
 
 
e9456a0
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

class Settings:
    GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
    GCP_PROJECT_ID = os.getenv("GCP_PROJECT_ID")
    GCP_LOCATION = os.getenv("GCP_LOCATION", "us-central1")
    GCP_CREDENTIALS_JSON = os.getenv("GCP_CREDENTIALS_JSON")
    HF_TOKEN = os.getenv("HF_TOKEN")
    GCP_BUCKET_NAME = os.getenv("GCP_BUCKET_NAME")

    @classmethod
    def setup_auth(cls):
        """Sets up Google Application Credentials if JSON is provided in env."""
        if cls.GCP_CREDENTIALS_JSON:
            print("🔐 Found GCP Credentials Secret. Setting up auth...")
            creds_path = "gcp_credentials.json"
            with open(creds_path, "w") as f:
                f.write(cls.GCP_CREDENTIALS_JSON)
            os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = creds_path

    @classmethod
    def validate(cls):
        """Validates critical environment variables."""
        if not cls.GOOGLE_API_KEY:
            raise ValueError("GOOGLE_API_KEY is missing from environment variables.")
        if not cls.HF_TOKEN:
             print("⚠️ HF_TOKEN is missing. Audio generation may fail.")
        if not cls.GCP_BUCKET_NAME:
             print("⚠️ GCP_BUCKET_NAME is missing. Cloud persistence will be disabled.")

# Run setup and validation immediately on import
Settings.setup_auth()
Settings.validate()