Skip to content

Commit

Permalink
fix: reorganize functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dtdang committed Oct 25, 2024
1 parent ebf0c66 commit 2693687
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 33 deletions.
60 changes: 29 additions & 31 deletions silverback/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,20 @@ def list_workspaces(platform: PlatformClient):
)


@workspaces.command(name="info", section="Platform Commands (https://silverback.apeworx.io)")
@click.argument("workspace")
@platform_client
def workspace_info(platform: PlatformClient, workspace: str):
"""Get Configuration information about a WORKSPACE"""

if not (workspace_info := platform.workspaces.get(workspace)):
raise click.BadOptionUsage("workspace", f"Unknown workspace '{workspace}'")

click.echo(f"{click.style('Name', fg='green')}: {workspace_info.name}")
click.echo(f"{click.style('Slug', fg='green')}: '{workspace_info.slug}'")
click.echo(f"{click.style('Date Created', fg='green')}: '{workspace_info.created}'")


@workspaces.command(name="new", section="Platform Commands (https://silverback.apeworx.io)")
@click.option(
"-n",
Expand Down Expand Up @@ -286,23 +300,6 @@ def new_workspace(
click.echo(f"{click.style('SUCCESS', fg='green')}: Created '{workspace_name}'")


@workspaces.command(name="delete", section="Platform Commands (https://silverback.apeworx.io)")
@click.argument("workspace")
@platform_client
def delete_workspace(platform: PlatformClient, workspace: str):
"""Delete an empty Workspace on the Silverback Platform"""

if not (workspace_client := platform.workspaces.get(workspace)):
raise click.BadOptionUsage("workspace", f"Unknown workspace '{workspace}'")

if list(workspace_client.clusters):
raise click.UsageError("Running Clusters found in Workspace. Shut them down first.")

else:
platform.remove_workspace(workspace)
click.echo(f"{click.style('SUCCESS', fg='green')}: Deleted '{workspace}'")


@workspaces.command(name="update", section="Platform Commands (https://silverback.apeworx.io)")
@click.option(
"-n",
Expand Down Expand Up @@ -334,27 +331,28 @@ def update_workspace(
"No update name or slug found. Please enter a name or slug to update."
)

else:
platform.update_workspace(
workspace=workspace,
update_name=update_name,
update_slug=update_slug,
)
click.echo(f"{click.style('SUCCESS', fg='green')}: Updated '{update_name}'")
platform.update_workspace(
workspace=workspace,
update_name=update_name,
update_slug=update_slug,
)
click.echo(f"{click.style('SUCCESS', fg='green')}: Updated '{update_name}'")


@workspaces.command(name="info", section="Platform Commands (https://silverback.apeworx.io)")
@workspaces.command(name="delete", section="Platform Commands (https://silverback.apeworx.io)")
@click.argument("workspace")
@platform_client
def workspace_info(platform: PlatformClient, workspace: str):
"""Get Configuration information about a WORKSPACE"""
def delete_workspace(platform: PlatformClient, workspace: str):
"""Delete an empty Workspace on the Silverback Platform"""

if not (workspace_info := platform.workspaces.get(workspace)):
if not (workspace_client := platform.workspaces.get(workspace)):
raise click.BadOptionUsage("workspace", f"Unknown workspace '{workspace}'")

click.echo(f"{click.style('Name', fg='green')}: {workspace_info.name}")
click.echo(f"{click.style('Slug', fg='green')}: '{workspace_info.slug}'")
click.echo(f"{click.style('Date Created', fg='green')}: '{workspace_info.created}'")
if len(workspace_client.clusters) > 0:
raise click.UsageError("Running Clusters found in Workspace. Shut them down first.")

platform.remove_workspace(workspace)
click.echo(f"{click.style('SUCCESS', fg='green')}: Deleted '{workspace}'")


@cluster.command(name="list", section="Platform Commands (https://silverback.apeworx.io)")
Expand Down
4 changes: 2 additions & 2 deletions silverback/cluster/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def create_workspace(

def remove_workspace(self, workspace_slug):
workspace_id = self.workspaces[workspace_slug].id
response = self.delete(f"/workspaces/{str(workspace_id)}")
response = self.delete(f"/workspaces/{workspace_id}")
handle_error_with_response(response)

def update_workspace(
Expand All @@ -465,7 +465,7 @@ def update_workspace(
):
workspace_id = self.workspaces[workspace].id
response = self.patch(
f"/workspaces/{str(workspace_id)}",
f"/workspaces/{workspace_id}",
data=dict(slug=update_slug, name=update_name),
)
handle_error_with_response(response)
Expand Down

0 comments on commit 2693687

Please sign in to comment.