-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_credentials.py
More file actions
71 lines (53 loc) · 2.17 KB
/
extract_credentials.py
File metadata and controls
71 lines (53 loc) · 2.17 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
#!/usr/bin/env python3
"""
One-time setup: extract WEBHOOK_URL and AUTH_KEY from your Outerbounds config
and write them to .env for use in curl / scripts.
Prerequisites:
- pip install outerbounds requests
- Already configured via one of:
outerbounds configure <config-string> (human user, from UI)
outerbounds service-principal-configure ... (machine user, in CI)
Usage:
python extract_credentials.py # default profile
METAFLOW_PROFILE=yellow python extract_credentials.py # named profile
"""
import json
import os
import sys
from pathlib import Path
def load_config():
profile = os.environ.get("METAFLOW_PROFILE", "")
suffix = f"_{profile}" if profile else ""
config_file = Path.home() / ".metaflowconfig" / f"config{suffix}.json"
if not config_file.exists():
print(f"Error: {config_file} not found.\n")
print("Configure Outerbounds first:")
print(" outerbounds configure <config-string> # from UI")
print(" or")
print(" outerbounds service-principal-configure --name ... --deployment-domain ...")
sys.exit(1)
print(f"Reading config from {config_file} ...")
cfg = json.loads(config_file.read_text())
# Bootstrap configs need to resolve the full config from the platform API
config_url = cfg.get("OBP_METAFLOW_CONFIG_URL")
if config_url:
import requests
token = cfg["METAFLOW_SERVICE_AUTH_KEY"]
resp = requests.get(config_url, headers={"x-api-key": token})
resp.raise_for_status()
cfg = resp.json().get("config", cfg)
return cfg
def main():
cfg = load_config()
webhook_url = cfg.get("METAFLOW_ARGO_EVENTS_WEBHOOK_URL", "")
auth_key = cfg.get("METAFLOW_SERVICE_AUTH_KEY", "")
if not webhook_url or not auth_key:
print("Error: could not find WEBHOOK_URL or AUTH_KEY in config")
sys.exit(1)
env_path = Path(__file__).parent / ".env"
env_path.write_text(f"WEBHOOK_URL={webhook_url}\nAUTH_KEY={auth_key}\n")
print(f"\nWritten to {env_path}:")
print(f" WEBHOOK_URL={webhook_url}")
print(f" AUTH_KEY={auth_key[:40]}...")
if __name__ == "__main__":
main()