43 lines
932 B
Python
Executable File
43 lines
932 B
Python
Executable File
#!/usr/bin/env python
|
|
import importlib
|
|
import importlib.util
|
|
import os
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
import yaml
|
|
|
|
from rproxy.sockets import start_reverse_proxy
|
|
from rproxy.config import Config
|
|
|
|
|
|
def usage() -> str:
|
|
example = (
|
|
Path(importlib.util.find_spec("rproxy").origin).parent
|
|
/ "resources"
|
|
/ "example.config.yaml"
|
|
)
|
|
return (
|
|
f"Reverse proxy server.\n\nusage: {prog} config\n"
|
|
f"example: {prog} ./my-config.yaml\n\n"
|
|
f"See example config file at {example}"
|
|
)
|
|
|
|
|
|
try:
|
|
with open(sys.argv[1]) as f:
|
|
config = Config(**yaml.safe_load(f))
|
|
print(config)
|
|
except (FileNotFoundError, IndexError) as e:
|
|
prog = os.path.basename(sys.argv[0])
|
|
print(
|
|
f"Error: missing config file argument. {e}.\n{usage()}",
|
|
file=sys.stderr,
|
|
)
|
|
sys.exit(1)
|
|
|
|
try:
|
|
start_reverse_proxy(config)
|
|
except KeyboardInterrupt:
|
|
sys.exit(0)
|