From 7f5f8a10a9168801d5030741848b995e66a1fee2 Mon Sep 17 00:00:00 2001 From: Drew Short Date: Mon, 27 Dec 2021 13:52:19 -0600 Subject: [PATCH] Support retrieving a specific profile --- acm.py | 11 ++++++++--- acm/config.py | 11 ++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/acm.py b/acm.py index 0305b56..0c833aa 100755 --- a/acm.py +++ b/acm.py @@ -16,7 +16,7 @@ import click from minio import Minio, InvalidResponseError from minio.error import S3Error -from acm.config import VERSION, default_config +from acm.config import VERSION, get_default_config from acm.logging import setup_basic_logging, update_logging_level from acm.utility import get_string_sha256sum @@ -295,9 +295,14 @@ def print_default_config(ctx, profile): Print the configuration """ if profile == "all": - print(default_config().json(exclude_none=True, indent=2, sort_keys=True)) + print(get_default_config().json(exclude_none=True, indent=2, sort_keys=True)) else: - config = default_config() + config = get_default_config() + profile_names = config.get_profile_names() + if profile in profile_names: + print(config.get_profile(profile).json(exclude_none=True, indent=2, sort_keys=True)) + else: + print(f"Profile \"{profile}\" is not in {profile_names}") ############################### # S3 Storage Focused Commands # diff --git a/acm/config.py b/acm/config.py index 37df568..813a862 100644 --- a/acm/config.py +++ b/acm/config.py @@ -107,8 +107,17 @@ class ACMConfig(BaseSettings): env_prefix = 'ACM_' env_nested_delimiter = '__' + def get_profile_names(self) -> typing.List[str]: + return [profile.name for profile in self.profiles] -def default_config(): + def get_profile(self, name: str) -> typing.Optional[ACMProfile]: + for profile in self.profiles: + if name == profile.name: + return profile + return None + + +def get_default_config(): """ Returns the default ACM config """