Upload main.py
Browse files
main.py
CHANGED
|
@@ -18,19 +18,53 @@ logger = logging.getLogger(__name__)
|
|
| 18 |
|
| 19 |
app = FastAPI(title="SEO Multi-Agent System", version="1.0.0")
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Initialize agents
|
| 22 |
# Note: In a real deployment, credentials would be loaded from env vars or mounted secrets
|
| 23 |
technical_agent = TechnicalAuditorAgent()
|
| 24 |
content_agent = ContentOptimizationAgent()
|
| 25 |
competitor_agent = CompetitorIntelligenceAgent()
|
| 26 |
indexing_agent = BacklinkIndexingAgent(
|
| 27 |
-
gsc_credentials_path="
|
| 28 |
site_url="https://fixyfile.com"
|
| 29 |
)
|
| 30 |
analytics_agent = PerformanceAnalyticsAgent(
|
| 31 |
ga4_property_id="YOUR_GA4_ID", # Replace with actual if known
|
| 32 |
-
ga4_credentials_path="
|
| 33 |
-
gsc_credentials_path="
|
| 34 |
site_url="https://fixyfile.com"
|
| 35 |
)
|
| 36 |
# Orchestrator no longer needs Redis as we moved queue logic to Cloudflare D1
|
|
|
|
| 18 |
|
| 19 |
app = FastAPI(title="SEO Multi-Agent System", version="1.0.0")
|
| 20 |
|
| 21 |
+
def setup_credentials_from_env():
|
| 22 |
+
"""Security: Write env vars to files so agents can use them without committing secrets to repo"""
|
| 23 |
+
os.makedirs("/app/credentials", exist_ok=True)
|
| 24 |
+
|
| 25 |
+
# GSC
|
| 26 |
+
gsc_json = os.environ.get("GSC_CREDENTIALS")
|
| 27 |
+
if gsc_json:
|
| 28 |
+
print("Loading GSC credentials from Environment Variable")
|
| 29 |
+
with open("/app/credentials/gsc-credentials.json", "w") as f:
|
| 30 |
+
f.write(gsc_json)
|
| 31 |
+
|
| 32 |
+
# GA4
|
| 33 |
+
ga4_json = os.environ.get("GA4_CREDENTIALS")
|
| 34 |
+
if ga4_json:
|
| 35 |
+
print("Loading GA4 credentials from Environment Variable")
|
| 36 |
+
with open("/app/credentials/ga4-credentials.json", "w") as f:
|
| 37 |
+
f.write(ga4_json)
|
| 38 |
+
|
| 39 |
+
# Run setup immediately
|
| 40 |
+
setup_credentials_from_env()
|
| 41 |
+
|
| 42 |
+
def get_credential_path(filename):
|
| 43 |
+
"""Helper to find credentials in common paths"""
|
| 44 |
+
possible_paths = [
|
| 45 |
+
f"/app/credentials/{filename}",
|
| 46 |
+
f"/app/{filename}",
|
| 47 |
+
f"./{filename}",
|
| 48 |
+
filename
|
| 49 |
+
]
|
| 50 |
+
for path in possible_paths:
|
| 51 |
+
if os.path.exists(path):
|
| 52 |
+
return path
|
| 53 |
+
return f"/app/credentials/{filename}" # Default
|
| 54 |
+
|
| 55 |
# Initialize agents
|
| 56 |
# Note: In a real deployment, credentials would be loaded from env vars or mounted secrets
|
| 57 |
technical_agent = TechnicalAuditorAgent()
|
| 58 |
content_agent = ContentOptimizationAgent()
|
| 59 |
competitor_agent = CompetitorIntelligenceAgent()
|
| 60 |
indexing_agent = BacklinkIndexingAgent(
|
| 61 |
+
gsc_credentials_path=get_credential_path("gsc-credentials.json"),
|
| 62 |
site_url="https://fixyfile.com"
|
| 63 |
)
|
| 64 |
analytics_agent = PerformanceAnalyticsAgent(
|
| 65 |
ga4_property_id="YOUR_GA4_ID", # Replace with actual if known
|
| 66 |
+
ga4_credentials_path=get_credential_path("ga4-credentials.json"),
|
| 67 |
+
gsc_credentials_path=get_credential_path("gsc-credentials.json"),
|
| 68 |
site_url="https://fixyfile.com"
|
| 69 |
)
|
| 70 |
# Orchestrator no longer needs Redis as we moved queue logic to Cloudflare D1
|