diff --git a/silverback/_cli.py b/silverback/_cli.py index b153ec51..50cd2704 100644 --- a/silverback/_cli.py +++ b/silverback/_cli.py @@ -3,6 +3,7 @@ from datetime import datetime, timedelta, timezone from pathlib import Path from typing import TYPE_CHECKING, Optional +from silverback.cluster.client import RegistryCredentials import click import yaml # type: ignore[import-untyped] @@ -859,12 +860,20 @@ def credentials_update(cluster: "ClusterClient", name: str, registry: str | None @cluster_client def credentials_remove(cluster: "ClusterClient", name: str): """Remove a set of registry credentials""" - if not (creds := cluster.registry_credentials.get(name)): + # Verify the credential exists in the list + if name not in cluster.registry_credentials: raise click.UsageError(f"Unknown credentials '{name}'") - creds.remove() # NOTE: No confirmation because can only delete if no references exist - click.secho(f"registry credentials '{creds.name}' removed.", fg="green", bold=True) - + # Create instance and remove + creds = RegistryCredentials( + name=name, + docker_server="", + docker_username="", + docker_password="", + docker_email="" + ) + creds.remove() # This will call DELETE /credentials/{name} + click.secho(f"registry credentials '{name}' removed.", fg="green", bold=True) @cluster.group(cls=SectionedHelpGroup) def vars(): diff --git a/silverback/cluster/client.py b/silverback/cluster/client.py index 1710cd00..63f550ff 100644 --- a/silverback/cluster/client.py +++ b/silverback/cluster/client.py @@ -231,6 +231,7 @@ def __init__(self, *args, **kwargs): RegistryCredentials.cluster = self # Connect to cluster client VariableGroup.cluster = self # Connect to cluster client Bot.cluster = self # Connect to cluster client + def send(self, request, *args, **kwargs): try: @@ -263,12 +264,21 @@ def health(self) -> ClusterHealth: handle_error_with_response(response) return ClusterHealth.model_validate(response.json()) + def get_credential_details(self, name: str) -> RegistryCredentialsInfo: + # Try to get full details of a single credential + response = self.get(f"/credentials/{name}") + handle_error_with_response(response) + return RegistryCredentialsInfo.model_validate(response.json()) + @property def registry_credentials(self) -> dict[str, RegistryCredentials]: response = self.get("/credentials") handle_error_with_response(response) - - return response.json() + + return { + name: self.get_credential_details(name) # We'd implement this to use the right HTTP method + for name in response.json() + } def new_credentials( self, name: str, docker_server: str, docker_username: str, docker_password: str, docker_email: str @@ -287,7 +297,6 @@ def new_credentials( except ValidationError as e: raise ClientError(f"Invalid response format: {e}") - @property def variable_groups(self) -> dict[str, VariableGroup]: response = self.get("/vars")