Skip to content

Commit

Permalink
Merge pull request #612 from kurusugawa-computer/af-update
Browse files Browse the repository at this point in the history
MFA有効化ユーザーに対するエラーの出し方を変更
  • Loading branch information
tei6 committed Oct 27, 2023
2 parents 54e59a9 + 57017b3 commit d6bfa0e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
2 changes: 0 additions & 2 deletions annofabapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from annofabapi.api2 import AnnofabApi2
from annofabapi.wrapper import Wrapper
from annofabapi.resource import build, build_from_netrc, build_from_env, Resource
from annofabapi.exceptions import NotSupportedUserError

from .__version__ import __version__

Expand All @@ -14,6 +13,5 @@
"build_from_netrc",
"build_from_env",
"Resource",
"NotSupportedUserError",
"__version__",
]
6 changes: 2 additions & 4 deletions annofabapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from requests.auth import AuthBase
from requests.cookies import RequestsCookieJar

from annofabapi.exceptions import NotLoggedInError, NotSupportedUserError
from annofabapi.exceptions import MfaEnabledUserExecutionError, NotLoggedInError
from annofabapi.generated_api import AbstractAnnofabApi

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -638,9 +638,7 @@ def login(self) -> Tuple[Dict[str, Any], requests.Response]:
response = self._execute_http_request("post", url, json=login_info)
json_obj = response.json()
if "token" not in json_obj:
raise NotSupportedUserError(
f"ユーザー(ユーザーID: {self.login_user_id})はMFAが有効です。" "MFAが有効なユーザーは、annofab-api-python-clientを利用できません。"
)
raise MfaEnabledUserExecutionError(self.login_user_id)
self.token_dict = json_obj["token"]

logger.debug("Logged in successfully. user_id = %s", self.login_user_id)
Expand Down
7 changes: 4 additions & 3 deletions annofabapi/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ def __init__(self, message: str, uploaded_data_hash: str, response_etag: str):
super().__init__(message)


class NotSupportedUserError(Exception):
class MfaEnabledUserExecutionError(Exception):
"""
annofab-api-python-clientでサポートされていないユーザが実行した際のエラー
MFAが有効化されたユーザーが実行したことを示すエラー
"""

def __init__(self, message: str):
def __init__(self, user_id: str):
message = f"User (User ID: {user_id}) cannot use annofab-api-python-client because MFA is enabled."
super().__init__(message)

0 comments on commit d6bfa0e

Please sign in to comment.