fixed type errors when pylance type checking mode is strict.

This commit is contained in:
2023-07-19 21:47:47 +09:00
parent 23025bd679
commit 08d8a0626a
24 changed files with 387 additions and 236 deletions

View File

@ -1,5 +1,6 @@
import getpass
from argparse import Namespace, _SubParsersAction
from argparse import Namespace
from typing import Any
from mdrsclient.api import UserApi
from mdrsclient.commands.base import BaseCommand
@ -10,20 +11,25 @@ from mdrsclient.exceptions import MissingConfigurationException
class LoginCommand(BaseCommand):
@classmethod
def register(cls, parsers: _SubParsersAction) -> None:
command = cls()
def register(cls, parsers: Any) -> None:
login_parser = parsers.add_parser("login", help="login to remote host")
login_parser.add_argument("remote", help="label of remote host")
login_parser.set_defaults(func=command.login)
login_parser.set_defaults(func=cls.func)
def login(self, args: Namespace) -> None:
remote = self._parse_remote_host(args.remote)
@classmethod
def func(cls, args: Namespace) -> None:
remote = str(args.remote)
username = input("Username: ").strip()
password = getpass.getpass("Password: ").strip()
cls.login(remote, username, password)
@classmethod
def login(cls, remote: str, username: str, password: str) -> None:
remote = cls._parse_remote_host(remote)
config = ConfigFile(remote)
if config.url is None:
raise MissingConfigurationException(f"Remote host `{remote}` is not found.")
connection = MDRSConnection(config.remote, config.url)
username = input("Username: ").strip()
password = getpass.getpass("Password: ").strip()
user_api = UserApi(connection)
(user, token) = user_api.auth(username, password)
print("Login Successful")