outlook-oauth-hack/config.py

29 lines
879 B
Python
Raw Normal View History

2024-04-05 18:13:16 -04:00
from pathlib import Path
import tomllib
2024-04-05 18:47:33 -04:00
from types import SimpleNamespace
import sys
2024-04-05 18:13:16 -04:00
2024-04-05 18:47:33 -04:00
def get_config(profile):
with open(Path.home() / ".o365-auth-config.toml", "rb") as f:
toplevel_data = tomllib.load(f)
2024-04-05 18:13:16 -04:00
2024-04-05 18:49:50 -04:00
default_data = toplevel_data["default"]
config_data = default_data | toplevel_data.get(profile, {})
2024-04-05 18:47:33 -04:00
cache_path = Path.home() / ".cache/o365-oauth" / profile
cache_path.mkdir(parents=True, exist_ok=True)
return SimpleNamespace(
ClientId = config_data["ClientId"],
ClientSecret = config_data["ClientSecret"],
Scopes = config_data["Scopes"],
2024-04-05 21:34:10 -04:00
CacheFile = cache_path / "cache.json",
2024-04-05 20:16:31 -04:00
Authority = config_data["Authority"] or None,
2024-04-05 21:34:10 -04:00
)
2024-04-05 20:34:20 -04:00
if __name__ == "__main__":
if len(sys.argv) < 3:
sys.exit(f"Usage: {sys.argv[0]} <profile> <key>")
print(get_config(sys.argv[1]).__dict__[sys.argv[2]])