class IntegrationConfig: """Config type for the integration utilities.""" broker = var(BrokerConfig) payproc = var(DummyPayProcConfig, required=False) store = var(DummyStoreConfig, required=False) wallet = var(DummyWalletConfig, required=False)
class WebConfig: enable = var(bool, default=False) allow_port_reallocation = var(bool, default=True, required=False) bind_address = var(str, default='localhost', required=False) bind_port = var(int, default=None, required=False)
class IntervalConfig: """Describes a time interval for a IntervalScheduler.""" weeks: int = var(required=False) days: int = var(required=False) hours: int = var(required=False) minutes: int = var(required=False) seconds: int = var(required=False)
class WatchConfig: """Describes some content to watch.""" name: str = var() type: str = var() args: List[str] = var(required=False) kwargs: Dict[str, Any] = var(required=False) schedule: ScheduleConfig = var()
class BrokerConfig: """Basic broker configuration.""" "allow listening port reallocation" allow_port_reallocation = var(bool, default=True, required=False) "start a new broker if true" start = var(bool, default=True) "broker listening host/interface" host = var(str, default='localhost', required=False) path = var(str, default=None, required=False) "broker listening port" port = var(int, default=1883, required=False)
class DummyStoreConfig: """Configuration type for the dummy Store component.""" @config class StoreWebConfig(WebConfig): bind_port = var(int, default=8080, required=False) web = var(StoreWebConfig, default=StoreWebConfig(), required=False)
class LogConfig: """Describes configuration for logging.""" dir: str = var(encoder=lambda x: x.to_posix(), decoder=Path) level: str = var(default="INFO", decoder=lambda x: x.upper()) rotation: str = var(default="00:00") retention: str = var(default="10 days") compression: str = var(default="zip") serialize: bool = var(default=True) record: bool = var(default=True) debug: bool = var(default=False)
class BrutConfig: """Contains observe configuration for the app.""" db: str = var() redis: str = var() store: str = var(encoder=lambda x: x.to_posix(), decoder=Path) log: LogConfig = var() watchers: WatcherConfig = var() watch: List[WatchConfig] = var() enqueue: ScheduleConfig = var()
class DummyWalletConfig: @config class WalletWebConfig(WebConfig): bind_port = var(int, default=8082, required=False) account = var(str, required=False) wallet = var(str, required=False) certificate = var(str, required=False) interactive = var(bool, default=False, required=False) url = var(str, required=False) web = var(WalletWebConfig, default=WalletWebConfig(), required=False)
def gen_var(att: attr.Attribute) -> attr.Attribute: t = att.type added_opts = {} # take the first not-None type if t is an Union type if getattr(t, '__origin__', None) is Union: for type_choice in t.__args__: # type: ignore # isinstance() cannot be used with typing.* if type_choice is not type(None): t = type_choice break else: raise ValueError(f'Cannot extrapolate valid type from {t!r}') # Setup a special encoder/decoder pair for Decimal type that # isn't supported directly by (py)YAML if t is Decimal: added_opts['encoder'] = lambda v: f'{v!s}' added_opts['decoder'] = lambda v: Decimal(v) # type: ignore if 'type' not in added_opts: added_opts['type'] = t # type: ignore return file_config.var(default=att.default, **added_opts)
class DummyPayProcConfig: """Configuration Type for the dummy PayProc component.""" DestinationConfig = msg2config(Destination) MerchantConfig = msg2config(Merchant) @config class PayProcWebConfig(WebConfig): bind_port = var(int, default=8081, required=False) supported_cryptos = var(List[str], unique=True, min=1) destinations = var(List[DestinationConfig], min=1) # type: ignore keyfile = var(str) certfile = var(str) merchant = var(MerchantConfig) web = var(PayProcWebConfig, default=PayProcWebConfig(), required=False)
class WatcherConfig: """Describes available watcher configuration.""" reddit: RedditConfig = var()
class RedditConfig: """Describes configuration necessary for watching reddit.""" client_id: str = var() client_secret: str = var() user_agent: str = var()
class ScheduleConfig: """Describes available schedules for an observe entry.""" crontab: str = var(required=False) interval: IntervalConfig = var(required=False) immediate: bool = var(default=False)
class PayProcWebConfig(WebConfig): bind_port = var(int, default=8081, required=False)
class StoreWebConfig(WebConfig): bind_port = var(int, default=8080, required=False)
class TestConfig: foo = var(str, default="Default", required=False) bar = var(str, default="Default", required=False)
class WalletWebConfig(WebConfig): bind_port = var(int, default=8082, required=False)
class ListCfg: foo = var(List[str], unique=True)