hosteday-python 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. hosteday/__init__.py +111 -0
  2. hosteday/_version.py +3 -0
  3. hosteday/auth/__init__.py +34 -0
  4. hosteday/auth/hosteday_auth.py +444 -0
  5. hosteday/auth/hosteday_auth_storage.py +130 -0
  6. hosteday/auth/hosteday_session.py +184 -0
  7. hosteday/auth/hosteday_token_provider.py +82 -0
  8. hosteday/auth/hosteday_user.py +223 -0
  9. hosteday/cli/__init__.py +5 -0
  10. hosteday/cli/setup.py +163 -0
  11. hosteday/config/__init__.py +15 -0
  12. hosteday/config/hosteday_config.py +576 -0
  13. hosteday/config/hosteday_option_keys.py +60 -0
  14. hosteday/config/hosteday_url_resolver.py +255 -0
  15. hosteday/connectivity/__init__.py +5 -0
  16. hosteday/connectivity/hosteday_connectivity.py +147 -0
  17. hosteday/exceptions.py +233 -0
  18. hosteday/features/__init__.py +5 -0
  19. hosteday/features/hosteday_features.py +78 -0
  20. hosteday/hosteday.py +346 -0
  21. hosteday/hosteday_client.py +579 -0
  22. hosteday/http/__init__.py +18 -0
  23. hosteday/http/hosteday_http_client.py +340 -0
  24. hosteday/http/hosteday_response_reader.py +171 -0
  25. hosteday/http/query_builder.py +204 -0
  26. hosteday/jobs/__init__.py +9 -0
  27. hosteday/jobs/hosteday_job_response.py +76 -0
  28. hosteday/jobs/hosteday_jobs_client.py +109 -0
  29. hosteday/notifications/__init__.py +13 -0
  30. hosteday/notifications/hosteday_notification_client.py +290 -0
  31. hosteday/notifications/hosteday_notification_response.py +79 -0
  32. hosteday/py.typed +1 -0
  33. hosteday/reactive/__init__.py +5 -0
  34. hosteday/reactive/observable_state.py +67 -0
  35. hosteday/realtime/__init__.py +31 -0
  36. hosteday/realtime/connection_state.py +14 -0
  37. hosteday/realtime/hosteday_channel.py +258 -0
  38. hosteday/realtime/hosteday_channel_auth.py +163 -0
  39. hosteday/realtime/hosteday_channel_type.py +68 -0
  40. hosteday/realtime/hosteday_realtime_client.py +790 -0
  41. hosteday/realtime/hosteday_realtime_event.py +130 -0
  42. hosteday/web/__init__.py +5 -0
  43. hosteday/web/server.py +637 -0
  44. hosteday_python/__init__.py +6 -0
  45. hosteday_python/py.typed +1 -0
  46. hosteday_python-0.1.0.dist-info/METADATA +205 -0
  47. hosteday_python-0.1.0.dist-info/RECORD +50 -0
  48. hosteday_python-0.1.0.dist-info/WHEEL +4 -0
  49. hosteday_python-0.1.0.dist-info/entry_points.txt +2 -0
  50. hosteday_python-0.1.0.dist-info/licenses/LICENSE +21 -0
hosteday/cli/setup.py ADDED
@@ -0,0 +1,163 @@
1
+ """``hosteday-setup`` CLI tool for fetching project manifests from HosteDay Control Plane."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+ import os
8
+ import sys
9
+ from collections.abc import Mapping, Sequence
10
+ from pathlib import Path
11
+ from typing import Any
12
+
13
+ import httpx
14
+
15
+ DEFAULT_CONTROL_PLANE_URL = "https://dash.hosteday.com"
16
+
17
+
18
+ def fetch_manifest(
19
+ *,
20
+ project: str,
21
+ token: str,
22
+ control_plane_url: str = DEFAULT_CONTROL_PLANE_URL,
23
+ client: httpx.Client | None = None,
24
+ ) -> dict[str, Any]:
25
+ """Fetches a project's runtime configuration manifest from HosteDay Control Plane."""
26
+ clean_project = project.strip()
27
+ clean_token = token.strip()
28
+ if not clean_project:
29
+ raise ValueError("Project slug (--project) cannot be empty.")
30
+ if not clean_token:
31
+ raise ValueError("Setup token (--token) cannot be empty.")
32
+
33
+ endpoint = f"{control_plane_url.rstrip('/')}/api/cli/manifest"
34
+ headers = {
35
+ "Accept": "application/json",
36
+ "Authorization": f"Bearer {clean_token}",
37
+ }
38
+
39
+ if client is not None:
40
+ response = client.get(endpoint, params={"project": clean_project}, headers=headers)
41
+ else:
42
+ with httpx.Client(timeout=30.0) as temp_client:
43
+ response = temp_client.get(
44
+ endpoint, params={"project": clean_project}, headers=headers
45
+ )
46
+
47
+ if response.status_code < 200 or response.status_code >= 300:
48
+ raise RuntimeError(
49
+ f"Control Plane returned HTTP {response.status_code}: {response.text}"
50
+ )
51
+
52
+ decoded: Any = response.json()
53
+ if isinstance(decoded, Mapping):
54
+ if isinstance(decoded.get("data"), Mapping):
55
+ return dict(decoded["data"])
56
+ return dict(decoded)
57
+
58
+ raise RuntimeError("Control Plane returned an unexpected manifest format.")
59
+
60
+
61
+ def render_env(manifest: Mapping[str, Any], *, prefix: str = "HOSTEDAY_") -> str:
62
+ """Renders a HosteDay manifest dictionary as a ``.env`` file."""
63
+ lines: list[str] = [
64
+ "# Generated by hosteday-setup — do NOT commit secrets to public repositories.",
65
+ ]
66
+ for key, value in manifest.items():
67
+ if value is None:
68
+ continue
69
+ env_key = f"{prefix}{str(key).upper()}"
70
+ if isinstance(value, (dict, list)):
71
+ serialized = json.dumps(value, separators=(",", ":"))
72
+ elif isinstance(value, bool):
73
+ serialized = "true" if value else "false"
74
+ else:
75
+ serialized = str(value)
76
+ lines.append(f"{env_key}={serialized}")
77
+ return "\n".join(lines) + "\n"
78
+
79
+
80
+ def write_config(
81
+ manifest: Mapping[str, Any],
82
+ *,
83
+ output: str | Path,
84
+ fmt: str = "json",
85
+ ) -> Path:
86
+ """Writes the manifest to disk in ``json`` or ``env`` format with ``0o600`` permissions."""
87
+ target = Path(output)
88
+ target.parent.mkdir(parents=True, exist_ok=True)
89
+
90
+ if fmt == "json":
91
+ content = json.dumps(dict(manifest), indent=2, ensure_ascii=False) + "\n"
92
+ elif fmt == "env":
93
+ content = render_env(manifest)
94
+ else:
95
+ raise ValueError(f"Unsupported format '{fmt}'. Expected 'json' or 'env'.")
96
+
97
+ target.write_text(content, encoding="utf-8")
98
+ try:
99
+ os.chmod(target, 0o600)
100
+ except OSError:
101
+ pass
102
+ return target
103
+
104
+
105
+ def build_parser() -> argparse.ArgumentParser:
106
+ parser = argparse.ArgumentParser(
107
+ prog="hosteday-setup",
108
+ description="Fetch HosteDay project configuration from dash.hosteday.com.",
109
+ )
110
+ parser.add_argument(
111
+ "--project",
112
+ default=os.environ.get("HOSTEDAY_PROJECT", ""),
113
+ help="HosteDay project slug (or HOSTEDAY_PROJECT env var).",
114
+ )
115
+ parser.add_argument(
116
+ "--token",
117
+ default=os.environ.get("HOSTEDAY_SETUP_TOKEN", ""),
118
+ help="Control Plane setup token (or HOSTEDAY_SETUP_TOKEN env var).",
119
+ )
120
+ parser.add_argument(
121
+ "--format",
122
+ choices=("json", "env"),
123
+ default="json",
124
+ dest="fmt",
125
+ help="Output format: 'json' (default) or 'env'.",
126
+ )
127
+ parser.add_argument(
128
+ "--output",
129
+ default=None,
130
+ help="Output file path (default: hosteday_config.json or .env).",
131
+ )
132
+ parser.add_argument(
133
+ "--control-plane-url",
134
+ default=DEFAULT_CONTROL_PLANE_URL,
135
+ help="Override Control Plane base URL (default: https://dash.hosteday.com).",
136
+ )
137
+ return parser
138
+
139
+
140
+ def main(argv: Sequence[str] | None = None) -> int:
141
+ parser = build_parser()
142
+ args = parser.parse_args(argv)
143
+
144
+ output_path = args.output or ("hosteday_config.json" if args.fmt == "json" else ".env")
145
+
146
+ try:
147
+ manifest = fetch_manifest(
148
+ project=args.project,
149
+ token=args.token,
150
+ control_plane_url=args.control_plane_url,
151
+ )
152
+ written = write_config(manifest, output=output_path, fmt=args.fmt)
153
+ except Exception as exc:
154
+ print(f"Error: {exc}", file=sys.stderr)
155
+ return 1
156
+
157
+ print(f"HosteDay configuration written to {written} (mode 0600).")
158
+ print("Reminder: add this file to .gitignore so project API keys are never committed.")
159
+ return 0
160
+
161
+
162
+ if __name__ == "__main__":
163
+ raise SystemExit(main())
@@ -0,0 +1,15 @@
1
+ """Configuration, option keys, and URL policy for the HosteDay SDK."""
2
+
3
+ from hosteday.config.hosteday_config import HostedayConfig
4
+ from hosteday.config.hosteday_option_keys import HostedayOptionKeys
5
+ from hosteday.config.hosteday_url_resolver import (
6
+ HostedayStaticPages,
7
+ HostedayUrlResolver,
8
+ )
9
+
10
+ __all__ = [
11
+ "HostedayConfig",
12
+ "HostedayOptionKeys",
13
+ "HostedayStaticPages",
14
+ "HostedayUrlResolver",
15
+ ]