From 3333fbb537be35dee2c3407f2e00ce42abea66f0 Mon Sep 17 00:00:00 2001 From: Panos Vagenas <35837085+vagenas@users.noreply.github.com> Date: Thu, 15 Dec 2022 13:31:39 +0100 Subject: [PATCH] feat: add project removal (#57) Signed-off-by: Panos Vagenas <35837085+vagenas@users.noreply.github.com> --- deepsearch/cps/cli/projects.py | 18 ++++++++++++++ deepsearch/cps/client/components/projects.py | 8 +++++++ docs/guide/projects.md | 25 ++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/deepsearch/cps/cli/projects.py b/deepsearch/cps/cli/projects.py index 87c01b8a..a0553fba 100644 --- a/deepsearch/cps/cli/projects.py +++ b/deepsearch/cps/cli/projects.py @@ -1,6 +1,9 @@ +import json + import typer from deepsearch.core.util.cli_output import OutputEnum, OutputOption, cli_output +from deepsearch.cps.apis.user.exceptions import ApiException from deepsearch.cps.client.api import CpsApi app = typer.Typer(no_args_is_help=True) @@ -29,5 +32,20 @@ def create( cli_output(results, output, headers="keys") +@app.command(name="remove", help="Remove a project") +def remove( + proj_key: str, +): + api = CpsApi.default_from_env() + try: + api.projects.remove(proj_key=proj_key) + except ApiException as e: + data = json.loads(e.body) + if data.get("status") == 404: + print("Project not found") + else: + raise + + if __name__ == "__main__": app() diff --git a/deepsearch/cps/client/components/projects.py b/deepsearch/cps/client/components/projects.py index d6c7f339..271ca689 100644 --- a/deepsearch/cps/client/components/projects.py +++ b/deepsearch/cps/client/components/projects.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional import deepsearch.cps.apis.user +from deepsearch.cps.apis.user.models.token_response import TokenResponse if TYPE_CHECKING: from deepsearch.cps.client import CpsApi @@ -30,6 +31,13 @@ def create(self, name: str) -> Project: proj: deepsearch.cps.apis.user.Project = self.sw_api.create(data=create_data) return self._load(proj) + def remove(self, proj_key: str) -> Project: + token_resp: TokenResponse = self.sw_api.get_delete_confirmation_token( + proj_key=proj_key + ) + del_token: str = token_resp.token + return self.sw_api.delete(proj_key=proj_key, confirmation_token=del_token) + def _load(self, project: deepsearch.cps.apis.user.Project) -> Project: return Project( # api=self.api, diff --git a/docs/guide/projects.md b/docs/guide/projects.md index f4a6e5f4..4232c245 100644 --- a/docs/guide/projects.md +++ b/docs/guide/projects.md @@ -83,3 +83,28 @@ A collaborator may be added to a project as `owner`, `editor`, or `viewer`. Belo df = pd.DataFrame(projects) print(df) ``` + +### Removing a project + +=== "CLI" + + Using the [`deepsearch cps`](../cli-reference.md#cps) component: +