Skip to content

Commit

Permalink
feat: project new and fix logout
Browse files Browse the repository at this point in the history
  • Loading branch information
Alw3ys committed Jan 23, 2024
1 parent 7cb06f0 commit c9fc7dc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions dctl/commands/logout.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def logout():
session = config.session()
headers = {**get_auth_header()}
url = f"{config.api_base_url}/auth/logout"
# TODO: Fix, seems like isn't working.
requests.delete(url, headers=headers, params={"session_id": session.id})
request = requests.delete(url, headers=headers, params={"session_id": session.id})
request.raise_for_status()
config.remove_stored_credentials()
click.echo("Logout Succeeded!")
39 changes: 39 additions & 0 deletions dctl/commands/new.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from enum import Enum

import click
import requests
from pydantic import BaseModel

from dctl.config import Config
from dctl.utils.session import get_auth_header

config = Config()


class Template(BaseModel):
source_full_name: str
path: str
branch: str


class TemplateType(Enum):
FASTAPI = Template(source_full_name="doseiai/dosei", path="examples/fastapi", branch="main")


@click.command()
@click.option(
'--template',
default="fastapi",
type=click.Choice(['fastapi'], case_sensitive=False),
required=True
)
@click.argument('name', nargs=1, default=None, required=True)
def new(template, name):
"""New project"""
headers = {**get_auth_header()}
url = f"{config.api_base_url}/projects/test/clone"
response = requests.post(url, headers=headers, json={
"name": name,
**TemplateType[template.upper()].value.model_dump()
})
response.raise_for_status()
2 changes: 2 additions & 0 deletions dctl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dctl.commands.login import login
from dctl.commands.logout import logout
from dctl.commands.logs import logs
from dctl.commands.new import new
from dctl.commands.project import project
from dctl.config import Config

Expand All @@ -17,6 +18,7 @@ def cli():


cli.add_command(login)
cli.add_command(new)
cli.add_command(logout)
cli.add_command(logs)
cli.add_command(env)
Expand Down

0 comments on commit c9fc7dc

Please sign in to comment.