|
| 1 | +import socket |
| 2 | +from dataclasses import dataclass, fields |
| 3 | +from typing import Optional |
| 4 | + |
| 5 | +from recceiver.processors import ConfigAdapter |
| 6 | + |
| 7 | +RECCEIVERID_DEFAULT = socket.gethostname() |
| 8 | +DEFAULT_QUERY_LIMIT = 10_000 |
| 9 | + |
| 10 | + |
| 11 | +@dataclass |
| 12 | +class CFConfig: |
| 13 | + """Configuration options for the CF Processor.""" |
| 14 | + |
| 15 | + alias_enabled: bool = False |
| 16 | + record_type_enabled: bool = False |
| 17 | + environment_variables: str = "" |
| 18 | + info_tags: str = "" |
| 19 | + ioc_connection_info: bool = True |
| 20 | + record_description_enabled: bool = False |
| 21 | + clean_on_start: bool = True |
| 22 | + clean_on_stop: bool = True |
| 23 | + username: str = "cfstore" |
| 24 | + env_owner_variable: str = "ENGINEER" |
| 25 | + recceiver_id: str = RECCEIVERID_DEFAULT |
| 26 | + timezone: Optional[str] = None |
| 27 | + cf_query_limit: int = DEFAULT_QUERY_LIMIT |
| 28 | + base_url: Optional[str] = None |
| 29 | + cf_username: Optional[str] = None |
| 30 | + cf_password: Optional[str] = None |
| 31 | + verify_ssl: Optional[bool] = None |
| 32 | + push_max_retries: int = 10 |
| 33 | + push_always_retry: bool = True |
| 34 | + |
| 35 | + @classmethod |
| 36 | + def loads(cls, conf: ConfigAdapter) -> "CFConfig": |
| 37 | + """Load configuration from a ConfigAdapter instance.""" |
| 38 | + return CFConfig( |
| 39 | + alias_enabled=conf.getboolean("alias", False), |
| 40 | + record_type_enabled=conf.getboolean("recordType", False), |
| 41 | + environment_variables=conf.get("environment_vars", ""), |
| 42 | + info_tags=conf.get("infotags", ""), |
| 43 | + ioc_connection_info=conf.getboolean("iocConnectionInfo", True), |
| 44 | + record_description_enabled=conf.getboolean("recordDesc", False), |
| 45 | + clean_on_start=conf.getboolean("cleanOnStart", True), |
| 46 | + clean_on_stop=conf.getboolean("cleanOnStop", True), |
| 47 | + username=conf.get("username", "cfstore"), |
| 48 | + recceiver_id=conf.get("recceiverId", RECCEIVERID_DEFAULT), |
| 49 | + timezone=conf.get("timezone", ""), |
| 50 | + cf_query_limit=conf.get("findSizeLimit", DEFAULT_QUERY_LIMIT), |
| 51 | + base_url=conf.get("baseUrl"), |
| 52 | + cf_username=conf.get("cfUsername"), |
| 53 | + cf_password=conf.get("cfPassword"), |
| 54 | + verify_ssl=conf.getboolean("verifySSL"), |
| 55 | + push_max_retries=conf.getint("pushMaxRetries", 10), |
| 56 | + push_always_retry=conf.getboolean("pushAlwaysRetry", True), |
| 57 | + ) |
| 58 | + |
| 59 | + def __repr__(self) -> str: |
| 60 | + parts = [] |
| 61 | + for f in fields(self): |
| 62 | + value = getattr(self, f.name) |
| 63 | + if f.name == "cf_password": |
| 64 | + value = "***" if value else None |
| 65 | + parts.append(f"{f.name}={value!r}") |
| 66 | + return f"CFConfig({', '.join(parts)})" |
0 commit comments