Skip to content

rs_server_edrs/edrs_client.md

<< Back to index

Module used to connect to EDRS stations using EDRSConnector.

load_station_config(config_path, station_name)

Load connection parameters for a specific station from YAML config.

Source code in docs/rs-server/services/edrs/rs_server_edrs/edrs_client.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def load_station_config(config_path: str | Path, station_name: str) -> dict:
    """Load connection parameters for a specific station from YAML config."""
    with open(config_path, encoding="utf-8") as f:
        config = yaml.safe_load(f)

    # Handle case where stations are provided as a YAML string under one key
    stations_data = config.get("stations")
    if isinstance(stations_data, str):
        stations = yaml.safe_load(stations_data)
    else:
        stations = stations_data

    if not stations or station_name not in stations:
        raise ValueError(f"Station '{station_name}' not found in configuration file: {config_path}")

    station = stations[station_name]
    auth = station.get("authentication", {})
    service = station.get("service", {})
    # Map configuration to EDRSConnector expected args
    connection_params = {
        "host": service.get("url"),
        "port": service.get("port"),
        "login": auth.get("username"),
        "password": auth.get("password"),
        "ca_cert": auth.get("ca_crt"),
        "client_cert": auth.get("client_crt"),
        "client_key": auth.get("client_key"),
    }

    # Validate required fields
    missing = [k for k, v in connection_params.items() if v is None]
    if missing:
        raise ValueError(f"Missing required fields in config for '{station_name}': {', '.join(missing)}")
    return connection_params