Skip to content

Commit

Permalink
Merge pull request #18 from unbekanntes-pferd/feature/0.5.0
Browse files Browse the repository at this point in the history
feature/0.5.0
  • Loading branch information
unbekanntes-pferd authored Jan 28, 2024
2 parents 25039f2 + ebb1c66 commit 81ee07c
Show file tree
Hide file tree
Showing 11 changed files with 700 additions and 479 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ __pycache__
/dist

#virtual environment
.venv
.venv

# vscode settings
.vscode
8 changes: 0 additions & 8 deletions .vscode/settings.json

This file was deleted.

26 changes: 21 additions & 5 deletions dccmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

__version__ = "0.4.3"
__version__ = "0.5.0"

# std imports
import sys
Expand Down Expand Up @@ -100,6 +100,9 @@ def upload(
password: str = typer.Argument(
None, help="Password to log in to DRACOON - only works with active cli mode"
),
encryption_password: str = typer.Argument(
None, help="Encryption password in use in DRACOON - only works with active cli mode"
)
):
"""Upload a file or folder into DRACOON """

Expand All @@ -125,9 +128,14 @@ async def _upload():
sys.exit(1)

if node_info.isEncrypted is True:
crypto_secret = get_crypto_credentials(base_url)
if cli_mode:
crypto_secret = get_crypto_credentials(base_url=base_url, cli_mode=cli_mode)
if not crypto_secret:
crypto_secret = encryption_password
else:
crypto_secret = get_crypto_credentials(base_url, cli_mode)
await init_keypair(
dracoon=dracoon, base_url=base_url, crypto_secret=crypto_secret
dracoon=dracoon, base_url=base_url, cli_mode=cli_mode, crypto_secret=crypto_secret
)

is_folder = is_directory(folder_path=source_dir_path)
Expand Down Expand Up @@ -772,6 +780,9 @@ def download(
password: str = typer.Argument(
None, help="Password to log in to DRACOON - only works with active cli mode"
),
encryption_password: str = typer.Argument(
None, help="Encryption password in use in DRACOON - only works with active cli mode"
)
):
"""
Download a file, folder or room from DRACOON
Expand Down Expand Up @@ -803,9 +814,14 @@ async def _download():

if node_info and node_info.isEncrypted is True:

crypto_secret = get_crypto_credentials(base_url)
if cli_mode:
crypto_secret = get_crypto_credentials(base_url=base_url, cli_mode=cli_mode)
if not crypto_secret:
crypto_secret = encryption_password
else:
crypto_secret = get_crypto_credentials(base_url, cli_mode=cli_mode)
await init_keypair(
dracoon=dracoon, base_url=base_url, crypto_secret=crypto_secret
dracoon=dracoon, base_url=base_url, cli_mode=cli_mode, crypto_secret=crypto_secret
)

is_container = node_info.type == NodeType.folder or node_info.type == NodeType.room
Expand Down
19 changes: 12 additions & 7 deletions dccmd/main/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@
@auth_app.command()
#pylint: disable=C0103
def rm(
base_url: str = typer.Argument(..., help="Base DRACOON url (example: dracoon.team)")
base_url: str = typer.Argument(..., help="Base DRACOON url (example: dracoon.team)"),
cli_mode: bool = typer.Option(
False, help="When active, targets insecure config file"
),
):
"""removes auth token(refresh token) for OAuth2 authentication in DRACOON"""

base_url = parse_base_url(full_path=f"{base_url}/")
creds = get_credentials(base_url)
creds = get_credentials(base_url, cli_mode)
crypto = get_crypto_credentials(base_url)

if not creds:
typer.echo(format_error_message(msg=f"No token stored DRACOON url: {base_url}"))
sys.exit(1)

delete_credentials(base_url)
delete_credentials(base_url, cli_mode)

if crypto:
delete_crypto_credentials(base_url)
Expand All @@ -56,15 +59,17 @@ def rm(
@auth_app.command()
#pylint: disable=C0103
def ls(
base_url: str = typer.Argument(..., help="Base DRACOON url (example: dracoon.team)")
base_url: str = typer.Argument(..., help="Base DRACOON url (example: dracoon.team)"),
cli_mode: bool = typer.Option(
False, help="When active, targets insecure config file"
),
):
"""displays auth info for OAuth2 authentication in DRACOON"""

async def _ls():

parsed_base_url = parse_base_url(full_path=f"{base_url}/")
refresh_token = get_credentials(parsed_base_url)
crypto_creds = get_crypto_credentials(parsed_base_url)
refresh_token = get_credentials(parsed_base_url, cli_mode)
crypto_creds = get_crypto_credentials(parsed_base_url, cli_mode)

if not refresh_token:
typer.echo(
Expand Down
21 changes: 15 additions & 6 deletions dccmd/main/auth/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,27 @@

@client_app.command()
def register(
base_url: str = typer.Argument(..., help="Base DRACOON url (example: dracoon.team)")
base_url: str = typer.Argument(..., help="Base DRACOON url (example: dracoon.team)"),
cli_mode: bool = typer.Option(
False, help="When active, targets insecure config file"
),
):
"""sets up client (client id and secret) for OAuth2 authentication in DRACOON"""
asyncio.run(register_client(base_url))
asyncio.run(register_client(base_url, cli_mode))


@client_app.command()
#pylint: disable=C0103
def rm(
base_url: str = typer.Argument(..., help="Base DRACOON url (example: dracoon.team)")
base_url: str = typer.Argument(..., help="Base DRACOON url (example: dracoon.team)"),
cli_mode: bool = typer.Option(
False, help="When active, targets insecure config file"
),
):
"""removes client (client id and secret) for OAuth2 authentication in DRACOON"""

try:
remove_client(base_url)
remove_client(base_url, cli_mode)
except DCClientParseError:
typer.echo(
format_error_message(msg=f"Client not found for DRACOON url: {base_url}.")
Expand All @@ -45,13 +51,16 @@ def rm(
@client_app.command()
#pylint: disable=C0103
def ls(
base_url: str = typer.Argument(..., help="Base DRACOON url (example: dracoon.team)")
base_url: str = typer.Argument(..., help="Base DRACOON url (example: dracoon.team)"),
cli_mode: bool = typer.Option(
False, help="When active, targets insecure config file"
),
):
"""displays client (client id and secret) for OAuth2 authentication in DRACOON"""

base_url = parse_base_url(f"{base_url}/")
try:
client_id, client_secret = get_client_credentials(base_url)
client_id, client_secret = get_client_credentials(base_url, cli_mode)
except DCClientParseError:
typer.echo(
format_error_message(msg=f"Client not found for DRACOON url: {base_url}")
Expand Down
Loading

0 comments on commit 81ee07c

Please sign in to comment.