Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add project removal #57

Merged
merged 1 commit into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions deepsearch/cps/cli/projects.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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()
8 changes: 8 additions & 0 deletions deepsearch/cps/client/components/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
25 changes: 25 additions & 0 deletions docs/guide/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
<div class="termy">

```console
$ deepsearch cps projects remove d1d526e14cdac562b5174c2df9dd1b04c29a8c33
```

</div>

=== "Python"

After you have generated the `api` object (from [login configuration](../getting_started/#authentication)),
you can remove a project given its key:

```python
# example project key to delete:
# proj_key = "7be8d8e763b55996710007cf97f31244e8ea237c"

api.projects.remove(proj_key=proj_key)
```