costvine-startup 0.1.78__tar.gz
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.
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: costvine-startup
|
|
3
|
+
Version: 0.1.78
|
|
4
|
+
Summary: Costvine server function startup routines
|
|
5
|
+
Author: John D. Underhill
|
|
6
|
+
Author-email: junderhill@qisproject.com
|
|
7
|
+
Requires-Python: >=3.12,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
12
|
+
Requires-Dist: firebase-admin
|
|
13
|
+
Requires-Dist: google-cloud-firestore
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
Costvine server function startup routines
|
|
17
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Costvine server function startup routines
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any, Dict, cast
|
|
5
|
+
|
|
6
|
+
import firebase_admin
|
|
7
|
+
from firebase_admin import App, auth, firestore
|
|
8
|
+
from google.cloud.firestore import Client
|
|
9
|
+
|
|
10
|
+
GlobalConfig = Dict[str, Any]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class StartupConfig:
|
|
15
|
+
global_config: GlobalConfig
|
|
16
|
+
app: App
|
|
17
|
+
auth: Any # firebase_admin.auth module (acts as the Auth client)
|
|
18
|
+
firestore: Client
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _get_app() -> App:
|
|
22
|
+
try:
|
|
23
|
+
return firebase_admin.get_app()
|
|
24
|
+
except ValueError:
|
|
25
|
+
return firebase_admin.initialize_app()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def startup(app_config: GlobalConfig) -> StartupConfig:
|
|
29
|
+
app = _get_app()
|
|
30
|
+
cfg = StartupConfig(
|
|
31
|
+
global_config=app_config,
|
|
32
|
+
app=app,
|
|
33
|
+
auth=auth,
|
|
34
|
+
firestore=firestore.client(app, app_config.get("database")),
|
|
35
|
+
)
|
|
36
|
+
print("startup-server/startup: Initialized for database:", cfg.global_config.get("database"))
|
|
37
|
+
return cfg
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _load_config() -> GlobalConfig:
|
|
41
|
+
config_path = os.path.abspath("config.json")
|
|
42
|
+
|
|
43
|
+
try:
|
|
44
|
+
with open(config_path, encoding="utf-8") as f:
|
|
45
|
+
raw = f.read()
|
|
46
|
+
except OSError as e:
|
|
47
|
+
raise RuntimeError(f"Failed to read config file at {config_path}: {e}") from e
|
|
48
|
+
|
|
49
|
+
try:
|
|
50
|
+
config = json.loads(raw)
|
|
51
|
+
except json.JSONDecodeError as e:
|
|
52
|
+
raise RuntimeError(f"Failed to parse config file at {config_path}: {e}") from e
|
|
53
|
+
|
|
54
|
+
if not isinstance(config, dict):
|
|
55
|
+
raise RuntimeError(f"Failed to parse config file at {config_path}: expected a JSON object")
|
|
56
|
+
|
|
57
|
+
return cast(GlobalConfig, config)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
startup_config: StartupConfig = startup(_load_config())
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "costvine-startup"
|
|
3
|
+
version = "0.1.78"
|
|
4
|
+
description = "Costvine server function startup routines"
|
|
5
|
+
authors = ["John D. Underhill <junderhill@qisproject.com>"]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
|
|
8
|
+
[tool.costvine.scripts]
|
|
9
|
+
pretty = "pretty"
|
|
10
|
+
format = "format"
|
|
11
|
+
lint = "lint"
|
|
12
|
+
types = "types"
|
|
13
|
+
tests = "tests"
|
|
14
|
+
check = "check"
|
|
15
|
+
"distribute" = "distribute-pypi"
|
|
16
|
+
|
|
17
|
+
[tool.poetry.dependencies]
|
|
18
|
+
python = "^3.12"
|
|
19
|
+
firebase-admin = "*"
|
|
20
|
+
google-cloud-firestore = "*"
|
|
21
|
+
|
|
22
|
+
[tool.poetry.group.dev.dependencies]
|
|
23
|
+
pip = "*"
|
|
24
|
+
mypy = "*"
|
|
25
|
+
pylint = "*"
|
|
26
|
+
black = "*"
|
|
27
|
+
|
|
28
|
+
[build-system]
|
|
29
|
+
requires = ["poetry-core"]
|
|
30
|
+
build-backend = "poetry.core.masonry.api"
|