Skip to content

Commit

Permalink
Fix OpenTTD#4: Do not authenticate unless required
Browse files Browse the repository at this point in the history
  • Loading branch information
erenes committed Apr 12, 2021
1 parent d588e35 commit 4a87073
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bananas_cli/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def wait_for_code():
raise Exit


async def authenticate(session, client_id):
async def authenticate(session):
config_folder = click.get_app_dir("bananas-cli")
os.makedirs(config_folder, exist_ok=True)
token_filename = config_folder + "/token"
Expand All @@ -104,7 +104,7 @@ async def authenticate(session, client_id):
"audience=github&"
"redirect_uri=http%3A%2F%2Flocalhost%3A3977%2F&"
"response_type=code&"
f"client_id={client_id}&"
f"client_id={Authenticate.client_id}&"
f"code_challenge={code_challenge}&"
"code_challenge_method=S256"
)
Expand Down
4 changes: 2 additions & 2 deletions bananas_cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import click
import logging

from .authentication import authenticate
from .authentication import Authenticate
from .helpers import task
from .session import Session

Expand Down Expand Up @@ -43,7 +43,7 @@ async def cli(ctx, api_url, tus_url, client_id):
ctx.obj = session

await session.start()
await authenticate(session, client_id)
Authenticate.client_id = client_id


@task
Expand Down
3 changes: 3 additions & 0 deletions bananas_cli/commands/list_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)
from ..exceptions import Exit
from ..helpers import task
from ..authentication import authenticate

log = logging.getLogger(__name__)

Expand All @@ -14,6 +15,8 @@
@pass_session
@task
async def list_self(session):
await authenticate(session)

status, data = await session.get("/package/self")
if status != 200:
log.error(f"Server returned invalid status code {status}: {data}")
Expand Down
3 changes: 3 additions & 0 deletions bananas_cli/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ..enums import License
from ..exceptions import Exit
from ..helpers import task
from ..authentication import authenticate

log = logging.getLogger(__name__)

Expand All @@ -28,6 +29,8 @@ def show_validation_errors(data):
@pass_session
@task
async def upload(session, version, name, description, url, license, files):
await authenticate(session)

parts = files[0].split("/")[:-1]
for filename in files:
check_parts = filename.split("/")
Expand Down

0 comments on commit 4a87073

Please sign in to comment.