fix: fix login API error message

the login API does not return an error message

Change-Id: I76be8ca033effe8da98b6e0f5281561b183b6266
This commit is contained in:
yangshaoxue 2023-11-02 16:01:26 +08:00
parent a27c6daea6
commit 1cedd57d6a

View File

@ -54,44 +54,38 @@ async def _get_projects_and_unscope_token(
token: Optional[str] = None, token: Optional[str] = None,
project_enabled: bool = False, project_enabled: bool = False,
) -> Tuple[List[Any], str]: ) -> Tuple[List[Any], str]:
try: auth_url = await utils.get_endpoint(
auth_url = await utils.get_endpoint( region=region,
region=region, service="keystone",
service="keystone", session=get_system_session(),
session=get_system_session(), )
if token:
unscope_auth = Token(
auth_url=auth_url,
token=token,
reauthenticate=False,
)
else:
unscope_auth = Password(
auth_url=auth_url,
user_domain_name=domain,
username=username,
password=password,
reauthenticate=False,
) )
if token: session = Session(
unscope_auth = Token( auth=unscope_auth, verify=CONF.default.cafile, timeout=constants.DEFAULT_TIMEOUT
auth_url=auth_url, )
token=token, unscope_client = KeystoneClient(
reauthenticate=False, session=session,
) endpoint=auth_url,
else: interface=CONF.openstack.interface_type,
unscope_auth = Password( )
auth_url=auth_url,
user_domain_name=domain,
username=username,
password=password,
reauthenticate=False,
)
session = Session( project_scope = unscope_client.auth.projects()
auth=unscope_auth, verify=CONF.default.cafile, timeout=constants.DEFAULT_TIMEOUT unscope_token = token if token else session.get_token()
)
unscope_client = KeystoneClient(
session=session,
endpoint=auth_url,
interface=CONF.openstack.interface_type,
)
project_scope = unscope_client.auth.projects()
unscope_token = token if token else session.get_token()
except Exception as e:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=str(e),
)
if project_enabled: if project_enabled:
project_scope = [scope for scope in project_scope if scope.enabled] project_scope = [scope for scope in project_scope if scope.enabled]