-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(pycloudlib): add more typehint on manager, secret, and confi…
…g modules (#1582) * refactor: add more typehints to manager module and config/secret subpackages * refactor: replace typing Optional with Union * docs(pycloudlib): adjust docstrings for manager, config, and secret modules * test(pycloudlib): add missing testcases for k8s configs and secrets * refactor: fix return type for create_secret function * refactor: fix incompatible types on function calls * docs: fix typo on pip install * test: handle unsupported config/secret adapter
- Loading branch information
Showing
19 changed files
with
600 additions
and
463 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,52 @@ | ||
"""This module contains base class for config adapter.""" | ||
|
||
from typing import Any | ||
from typing import NoReturn | ||
import typing as _t | ||
from abc import ABC | ||
from abc import abstractmethod | ||
|
||
|
||
class BaseConfig: | ||
class BaseConfig(ABC): | ||
"""Base class for config adapter. | ||
Must be sub-classed per implementation details. | ||
""" | ||
|
||
type = "config" | ||
@property | ||
def type(self) -> str: | ||
"""Name of the configuration type. | ||
def get(self, key: str, default: Any = "") -> NoReturn: | ||
This attribute always returns ``config``. | ||
""" | ||
return "config" | ||
|
||
@abstractmethod | ||
def get(self, key: str, default: _t.Any = "") -> _t.Any: | ||
"""Get specific config. | ||
Subclass **MUST** implement this method. | ||
""" | ||
raise NotImplementedError | ||
|
||
def set(self, key: str, value: Any) -> NoReturn: | ||
@abstractmethod | ||
def set(self, key: str, value: _t.Any) -> bool: | ||
"""Set specific config. | ||
Subclass **MUST** implement this method. | ||
""" | ||
raise NotImplementedError | ||
|
||
def all(self) -> NoReturn: # pragma: no cover | ||
"""Get all config (deprecated in favor of ``get_all``). | ||
|
||
Subclass **MUST** implement this method. | ||
""" | ||
def all(self) -> dict[str, _t.Any]: # noqa: A003 | ||
"""Get all config (deprecated in favor of ``get_all``).""" | ||
return self.get_all() | ||
|
||
def set_all(self, data: dict) -> NoReturn: | ||
@abstractmethod | ||
def set_all(self, data: dict[str, _t.Any]) -> bool: | ||
"""Set all config. | ||
Subclass **MUST** implement this method. | ||
""" | ||
raise NotImplementedError | ||
|
||
def get_all(self) -> NoReturn: | ||
"""Get all secrets. | ||
@abstractmethod | ||
def get_all(self) -> dict[str, _t.Any]: | ||
"""Get all configs. | ||
Subclass **MUST** implement this method. | ||
""" | ||
raise NotImplementedError |
Oops, something went wrong.