From de2aee8b1dfcf70b6fc30d4a8118d85caab92981 Mon Sep 17 00:00:00 2001 From: Andrew Vaillancourt Date: Mon, 2 Jun 2025 23:48:26 -0400 Subject: [PATCH] Add __str__ and __repr__ to Registry class Previously, logging a Registry object in docker-related keywords produced unreadable memory addresses (e.g., ). This commit adds __str__ and __repr__ methods to return a formatted string like 'local_registry (registry.local:9001)'. Type hints and docstrings were added to satisfy pre-commit linting. Change-Id: Ic2b3c8263fe9e12d5149749ee93376d37803bdc6 Signed-off-by: Andrew Vaillancourt --- config/docker/objects/registry.py | 52 +++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/config/docker/objects/registry.py b/config/docker/objects/registry.py index 3946f838..a09f79a0 100644 --- a/config/docker/objects/registry.py +++ b/config/docker/objects/registry.py @@ -1,9 +1,16 @@ class Registry: - """ - Class for Registry object - """ + """Represents a Docker registry configuration.""" def __init__(self, registry_name: str, registry_url: str, user_name: str, password: str): + """ + Initializes a Registry object. + + Args: + registry_name (str): Logical name of the registry (e.g., "source_registry"). + registry_url (str): Registry endpoint URL (e.g., "docker.io/starlingx"). + user_name (str): Username for authenticating with the registry. + password (str): Password for authenticating with the registry. + """ self.registry_name = registry_name self.registry_url = registry_url self.user_name = user_name @@ -11,27 +18,54 @@ class Registry: def get_registry_name(self) -> str: """ - Getter for registry name - Returns: + Returns the logical name of the registry. + Returns: + str: Registry name. """ return self.registry_name def get_registry_url(self) -> str: """ - Getter for registry url - Returns: + Returns the URL endpoint of the registry. + Returns: + str: Registry URL. """ return self.registry_url def get_user_name(self) -> str: """ - Getter for user name - Returns: + Returns the username used for registry authentication. + Returns: + str: Username. """ return self.user_name def get_password(self) -> str: + """ + Returns the password used for registry authentication. + + Returns: + str: Password. + """ return self.password + + def __str__(self) -> str: + """ + Returns a human-readable string representation of the registry. + + Returns: + str: Formatted string showing registry name and URL. + """ + return f"{self.registry_name} ({self.registry_url})" + + def __repr__(self) -> str: + """ + Returns the representation string of the registry. + + Returns: + str: Registry representation. + """ + return self.__str__()