Skip to content

Commit

Permalink
Update some arg names
Browse files Browse the repository at this point in the history
  • Loading branch information
haoyang-graphics committed Feb 24, 2021
1 parent 2ed744b commit bc65104
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions tronclass_cli/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def cache_decorator(func):
def cached_func(*args, **kwargs):
call_args = inspect.getcallargs(func, *args, **kwargs)
self = call_args['self']
cache_key = f'api.{self._user_name}.{key.format(**call_args)}'
cache_key = f'api.{self._username}.{key.format(**call_args)}'
value = self._cache.get(cache_key)
if value is not None:
return value
Expand All @@ -30,9 +30,9 @@ def cached_func(*args, **kwargs):


class Api:
def __init__(self, base_url, user_name, cache: shelve.Shelf, session: Session):
def __init__(self, base_url, username, cache: shelve.Shelf, session: Session):
self._base_url = base_url
self._user_name = user_name
self._username = username
self._session = session
self._cache = cache

Expand Down
4 changes: 2 additions & 2 deletions tronclass_cli/api/auth/zjuam.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_pub_key(self):
e = int(pub['exponent'], base=16)
return rsa.PublicKey(n, e)

def login(self, user_id: str, password: str):
def login(self, username: str, password: str):
res = self.session.get(LOGIN_URL).text
soup = BeautifulSoup(res, 'lxml')
execution = soup.findAll('input', attrs={'name': 'execution'})[0]['value']
Expand All @@ -37,7 +37,7 @@ def login(self, user_id: str, password: str):
encrypted_pass = rsa_encrypt(password.encode(), pub_key).hex()

form = {
'username': user_id,
'username': username,
'password': encrypted_pass,
'authcode': '',
'execution': execution,
Expand Down
2 changes: 1 addition & 1 deletion tronclass_cli/middleware/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def _init_parser(self):

def _exec(self, args):
api_url = api_urls.get(args.api_url, args.api_url)
self._ctx.api = Api(api_url, self._ctx.user_name, self._ctx.cache, self._ctx.session)
self._ctx.api = Api(api_url, self._ctx.username, self._ctx.cache, self._ctx.session)
20 changes: 10 additions & 10 deletions tronclass_cli/middleware/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ class SessionMiddleware(Middleware):

def _init_parser(self):
group = self._parser.add_argument_group(self.name)
group.add_argument('--user-id', help='user id used to login')
group.add_argument('--provider', default='zju',
group.add_argument('--username', help='username for authentication')
group.add_argument('--auth-provider', default='zju',
help=f'authentication provider, available providers: {", ".join(get_all_auth_providers().keys())}')
group.add_argument('--no-save-credentials', dest='save_credentials', action='store_false',
help='do not save the credentials')

def _exec(self, args):
user_id = args.user_id or interact.prompt_input('User ID')
self._ctx.user_name = user_id
self._ctx.session = self._ctx.cache.get(f'session.{user_id}')
username = args.username or interact.prompt_input('Username')
self._ctx.username = username
self._ctx.session = self._ctx.cache.get(f'session.{username}')
if self._ctx.session is not None:
return
password = keyring.get_password(SERVICE_NAME, user_id) or getpass()
password = keyring.get_password(SERVICE_NAME, username) or getpass()
if args.save_credentials:
keyring.set_password(SERVICE_NAME, user_id, password)
auth_provider = get_auth_provider(args.provider)()
self._ctx.session = auth_provider.login(user_id, password)
self._ctx.cache.set(f'session.{user_id}', self._ctx.session, SESSION_LIFETIME)
keyring.set_password(SERVICE_NAME, username, password)
auth_provider = get_auth_provider(args.auth_provider)()
self._ctx.session = auth_provider.login(username, password)
self._ctx.cache.set(f'session.{username}', self._ctx.session, SESSION_LIFETIME)

0 comments on commit bc65104

Please sign in to comment.