-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
75 lines (58 loc) · 2.33 KB
/
Copy pathmain.py
File metadata and controls
75 lines (58 loc) · 2.33 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import sys
import time
from workspace_client import WorkspaceClient
from analyzer import LogAnalyzer
import config
def run_scan():
"""Routine scan: fetch all monitored logs and analyze each category."""
print("--- Routine Security Scan ---\n")
workspace = WorkspaceClient()
analyzer = LogAnalyzer()
for app in config.APPLICATIONS_TO_MONITOR:
print(f"── {app.upper()} ──")
logs = workspace.fetch_logs(app)
if not logs:
print(f" No recent logs found.\n")
continue
print(f" Fetched {len(logs)} events.")
result = analyzer.analyze_logs(app, logs)
print(f"\n{result}")
print("-" * 40 + "\n")
time.sleep(2)
print("Scan complete.")
def main():
# Check prerequisites
if not os.path.exists(config.OAUTH_CLIENT_FILE) and not os.path.exists(config.TOKEN_FILE):
print(f"ERROR: No OAuth credentials found.")
print(f" Download your OAuth Client ID JSON from GCP Console")
print(f" and save it as '{config.OAUTH_CLIENT_FILE}' in this directory.")
print(f" Or run ./setup.sh for guided setup.")
sys.exit(1)
if not config.GEMINI_API_KEY:
print(f"ERROR: GEMINI_API_KEY not set. Check your .env file.")
sys.exit(1)
# Direct launch via flag
if "--investigate" in sys.argv or "-i" in sys.argv:
from investigate import run_investigation_cli
run_investigation_cli()
return
if "--scan" in sys.argv or "-s" in sys.argv:
run_scan()
return
# Interactive mode selection
print("╔══════════════════════════════════════════════╗")
print("║ Google Workspace AI Security Analyzer ║")
print("╚══════════════════════════════════════════════╝")
print()
print(" 1) Routine Scan — scan all logs for anomalies")
print(" 2) Investigate — interactive AI investigation")
print()
choice = input("Select mode (1/2): ").strip()
if choice == "2":
from investigate import run_investigation_cli
run_investigation_cli()
else:
run_scan()
if __name__ == "__main__":
main()