Skip to content

Commit

Permalink
fix: merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjagod1251 committed Jan 17, 2025
1 parent 88a6d62 commit b0419fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
17 changes: 13 additions & 4 deletions silverback/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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():
Expand Down
15 changes: 12 additions & 3 deletions silverback/cluster/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit b0419fc

Please sign in to comment.