Skip to content

Commit

Permalink
refactor: further refine config object; errors
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <[email protected]>
  • Loading branch information
dbluhm committed Nov 26, 2023
1 parent b21aaa7 commit b299851
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions oid4vci/oid4vci/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
from aries_cloudagent.core.profile import InjectionContext


class ConfigError(ValueError):
"""Base class for configuration errors."""

def __init__(self, var: str, env: str):
"""Initialize a ConfigError."""
super().__init__(
f"Invalid {var} specified for OID4VCI server; use either "
f"oid4vci.{var} plugin config value or environment variable {env}"
)


@dataclass
class Config:
"""Configuration for OID4VCI Plugin."""
Expand All @@ -22,19 +33,10 @@ def from_context(cls, context: InjectionContext) -> "Config":
endpoint = plugin_settings.get("endpoint") or getenv("OID4VCI_ENDPOINT")

if not host:
raise ValueError(
"No host specified for OID4VCI server; use either oid4vci.host "
"plugin config value or environment variable OID4VCI_HOST"
)
raise ConfigError("host", "OID4VCI_HOST")
if not port:
raise ValueError(
"No port specified for OID4VCI server; use either oid4vci.port "
"plugin config value or environment variable OID4VCI_PORT"
)
raise ConfigError("port", "OID4VCI_PORT")
if not endpoint:
raise ValueError(
"No endpoint specified for OID4VCI server; use either oid4vci.endpoint "
"plugin config value or environment variable OID4VCI_ENDPOINT"
)
raise ConfigError("endpoint", "OID4VCI_ENDPOINT")

return cls(host, port, endpoint)

0 comments on commit b299851

Please sign in to comment.