mirror of
https://forgejo.altau.su/lego/lego-monitoring.git
synced 2026-03-10 04:41:10 +00:00
stub service
This commit is contained in:
parent
19984b43f4
commit
f158bc3778
6 changed files with 92 additions and 52 deletions
|
|
@ -1,6 +1,19 @@
|
|||
import argparse
|
||||
import time
|
||||
|
||||
from .core.config import load_config
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="lego-monitoring",
|
||||
description="Lego-monitoring service",
|
||||
)
|
||||
parser.add_argument('-c', '--config', required=True)
|
||||
|
||||
config_path = parser.parse_args().config
|
||||
config = load_config(config_path)
|
||||
|
||||
while True:
|
||||
print("service running...")
|
||||
print(f"service running... opt 1 is {config.non_secret_config_option}, opt 2 is secret, but if you really wanna know, it's {config.config_option}", flush=True)
|
||||
time.sleep(300)
|
||||
|
|
|
|||
32
src/lego_monitoring/core/config.py
Normal file
32
src/lego_monitoring/core/config.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import json
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
from alt_utils import NestedDeserializableDataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Config(NestedDeserializableDataclass):
|
||||
non_secret_config_option: str
|
||||
config_option: Optional[str]
|
||||
|
||||
def load_config(filepath: str) -> Config:
|
||||
with open(filepath) as f:
|
||||
cfg_dict = json.load(f)
|
||||
|
||||
# load secrets from paths
|
||||
new_cfg_dict = {}
|
||||
for k in cfg_dict:
|
||||
if k.endswith('_secret_path'):
|
||||
actual_opt_key = k[:-12]
|
||||
secret_path = cfg_dict[k]
|
||||
if secret_path is None:
|
||||
new_cfg_dict[actual_opt_key] = None
|
||||
else:
|
||||
with open(secret_path) as sf:
|
||||
new_cfg_dict[actual_opt_key] = sf.read().rstrip()
|
||||
else:
|
||||
new_cfg_dict[k] = cfg_dict[k]
|
||||
|
||||
cfg = Config.from_dict(new_cfg_dict)
|
||||
return cfg
|
||||
Loading…
Add table
Add a link
Reference in a new issue