Skip to content

Commit

Permalink
Move get_clevis_info method into ClevisInfo class
Browse files Browse the repository at this point in the history
For better organization.

Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Aug 17, 2023
1 parent eee39a3 commit 52b5efc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/stratis_cli/_actions/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from ._constants import TOP_OBJECT
from ._formatting import get_property, get_uuid_formatter
from ._list_pool import list_pools
from ._utils import get_clevis_info
from ._utils import ClevisInfo


def _generate_pools_to_blockdevs(managed_objects, to_be_added, tier):
Expand Down Expand Up @@ -176,7 +176,7 @@ def create_pool(namespace): # pylint: disable=too-many-locals

_check_same_tier(pool_name, managed_objects, blockdevs, BlockDevTiers.DATA)

clevis_info = get_clevis_info(namespace)
clevis_info = ClevisInfo.get_info_from_namespace(namespace)

(
(changed, (pool_object_path, _)),
Expand Down
60 changes: 30 additions & 30 deletions src/stratis_cli/_actions/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,40 +52,40 @@ def __str__(self): # pragma: no cover
)
return f"{self.pin} {config_string}"

@staticmethod
def get_info_from_namespace(namespace):
"""
Get clevis info, if any, from the namespace.
def get_clevis_info(namespace):
"""
Get clevis info, if any, from the namespace.
:param namespace: namespace set up by the parser
:param namespace: namespace set up by the parser
:returns: clevis info or None
:rtype: ClevisInfo or NoneType
"""
clevis_info = None
if namespace.clevis is not None:
if namespace.clevis in ("nbde", "tang"):
if namespace.tang_url is None:
raise StratisCliMissingClevisTangURLError()

:returns: clevis info or None
:rtype: ClevisInfo or NoneType
"""
clevis_info = None
if namespace.clevis is not None:
if namespace.clevis in ("nbde", "tang"):
if namespace.tang_url is None:
raise StratisCliMissingClevisTangURLError()

if not namespace.trust_url and namespace.thumbprint is None:
raise StratisCliMissingClevisThumbprintError()

clevis_config = {CLEVIS_KEY_URL: namespace.tang_url}
if namespace.trust_url:
clevis_config[CLEVIS_KEY_TANG_TRUST_URL] = True
else:
assert namespace.thumbprint is not None
clevis_config[CLEVIS_KEY_THP] = namespace.thumbprint
if not namespace.trust_url and namespace.thumbprint is None:
raise StratisCliMissingClevisThumbprintError()

clevis_config = {CLEVIS_KEY_URL: namespace.tang_url}
if namespace.trust_url:
clevis_config[CLEVIS_KEY_TANG_TRUST_URL] = True
else:
assert namespace.thumbprint is not None
clevis_config[CLEVIS_KEY_THP] = namespace.thumbprint

clevis_info = ClevisInfo(CLEVIS_PIN_TANG, clevis_config)
clevis_info = ClevisInfo(CLEVIS_PIN_TANG, clevis_config)

elif namespace.clevis == "tpm2":
clevis_info = ClevisInfo(CLEVIS_PIN_TPM2, {})
elif namespace.clevis == "tpm2":
clevis_info = ClevisInfo(CLEVIS_PIN_TPM2, {})

else:
raise AssertionError(
f"unexpected value {namespace.clevis} for clevis option"
) # pragma: no cover
else:
raise AssertionError(
f"unexpected value {namespace.clevis} for clevis option"
) # pragma: no cover

return clevis_info
return clevis_info

0 comments on commit 52b5efc

Please sign in to comment.