Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds repository credentials to bot update command
Browse files Browse the repository at this point in the history
mikeshultz committed Oct 2, 2024
1 parent 51db28a commit b37334d
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions silverback/_cli.py
Original file line number Diff line number Diff line change
@@ -608,6 +608,12 @@ def bot_info(cluster: ClusterClient, bot_name: str):
@click.option("-n", "--network")
@click.option("-a", "--account")
@click.option("-g", "--group", "vargroups", multiple=True)
@click.option(
"-r",
"--registry-credentials",
"registry_credentials_name",
help="registry credentials to use to pull the image",
)
@click.argument("name", metavar="BOT")
@cluster_client
def update_bot(
@@ -617,6 +623,7 @@ def update_bot(
network: str | None,
account: str | None,
vargroups: list[str],
registry_credentials_name: str | None,
name: str,
):
"""Update configuration of BOT in CLUSTER
@@ -635,6 +642,14 @@ def update_bot(
if network:
click.echo(f"Network:\n old: {bot.network}\n new: {network}")

registry_credentials_id = None
if registry_credentials_name:
if not (
creds := cluster.registry_credentials.get(registry_credentials_name)
): # NOTE: Check if credentials exist
raise click.UsageError(f"Unknown registry credentials '{registry_credentials_name}'")
registry_credentials_id = creds.id

redeploy_required = False
if image:
redeploy_required = True
@@ -668,6 +683,7 @@ def update_bot(
network=network,
account=account,
environment=environment if set_environment else None,
registry_credentials_id=registry_credentials_id,
)

# NOTE: Skip machine `.id`
4 changes: 4 additions & 0 deletions silverback/cluster/client.py
Original file line number Diff line number Diff line change
@@ -132,6 +132,7 @@ def update(
network: str | None = None,
account: str | None = None,
environment: list[VariableGroupInfo] | None = None,
registry_credentials_id: str | None = None,
) -> "Bot":
form: dict = dict(
name=name,
@@ -145,6 +146,9 @@ def update(
dict(id=str(env.id), revision=env.revision) for env in environment
]

if registry_credentials_id:
form["registry_credentials_id"] = registry_credentials_id

response = self.cluster.put(f"/bots/{self.id}", json=form)
handle_error_with_response(response)
return Bot.model_validate(response.json())

0 comments on commit b37334d

Please sign in to comment.