Skip to content

Commit

Permalink
feat: Allow inconsistent users (#37)
Browse files Browse the repository at this point in the history
Co-authored-by: spencerwooo <[email protected]>
  • Loading branch information
YDX-2147483647 and spencerwooo authored May 9, 2023
1 parent 7d7b5ba commit ee5608e
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 141 deletions.
9 changes: 9 additions & 0 deletions bitsrun/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import warnings
from getpass import getpass
from json import dumps

Expand All @@ -18,6 +19,14 @@
]


# Replace the default implementation
warnings.showwarning = (
lambda message, category, filename, lineno, file=None, line=None: click.echo(
f"{click.style('warning:', fg='yellow')} {message}", err=True
)
)


# Decorator to add options to a click command (used w/ the hack above)
def add_options(options):
def _add_options(func):
Expand Down
12 changes: 9 additions & 3 deletions bitsrun/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
from hashlib import sha1
from typing import Optional
from warnings import warn

import httpx

Expand Down Expand Up @@ -55,9 +56,12 @@ def __init__(self, username: str, password: str):

# Validate if current logged in user matches the provided username
if self.logged_in_user and self.logged_in_user != self.username:
raise Exception(
warn(
f"Current logged in user ({self.logged_in_user}) and "
f"yours ({self.username}) does not match"
f"yours ({self.username}) does not match. "
"Most likely bitsrun will work fine, "
"but that may differ from what you really want.",
stacklevel=1,
)

def login(self) -> UserResponseType:
Expand Down Expand Up @@ -121,7 +125,9 @@ def logout(self) -> UserResponseType:
"action": "logout",
"ac_id": self.acid,
"ip": self.ip,
"username": self.username,
"username": self.logged_in_user,
# `logged_in_user` may differ from `username`.
# Anyway, we can logout without password.
}
response = self.client.get("/cgi-bin/srun_portal", params=params)
return json.loads(response.text[6:-1])
Expand Down
Loading

0 comments on commit ee5608e

Please sign in to comment.