-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add AD checks for instrument scientists * Formatting and linting commit * Trial fixes for e2e * Add is_instrument_scientist patchs to e2e tests * Add docstring * Add docstring checks to ruff * DO a whole bunch of docs fixes. * DO a whole bunch of docs fixes. * DO a whole bunch of docs fixes. * Remove support for D100 ruff linter * Formatting and linting commit --------- Co-authored-by: github-actions <[email protected]>
- Loading branch information
Showing
19 changed files
with
217 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
"""Error handlers""" | ||
|
||
import logging | ||
from http import HTTPStatus | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
""" | ||
FIA Auth custom exceptions | ||
""" | ||
"""FIA Auth custom exceptions""" | ||
|
||
|
||
class UOWSError(Exception): | ||
|
||
"""Problem authenticating with the user office web service""" | ||
|
||
|
||
class ProposalAllocationsError(Exception): | ||
|
||
"""Problem connecting with the proposal allocations api""" | ||
|
||
|
||
class AuthenticationError(Exception): | ||
|
||
"""Problem with authentication mechanism""" | ||
|
||
|
||
class BadCredentialsError(AuthenticationError): | ||
""" "Bad Credentials Provided""" | ||
|
||
"""Bad Credentials Provided""" | ||
|
||
|
||
class BadJWTError(AuthenticationError): | ||
|
||
"""Raised when a bad jwt has been given to the service""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Functions for handling role checks""" | ||
|
||
import os | ||
from http import HTTPStatus | ||
|
||
import requests | ||
|
||
|
||
def is_instrument_scientist(user_number: int) -> bool: | ||
""" | ||
Check if the user number is an instrument scientist according to UOWs (User Office Web Service). | ||
:param user_number: The user number assigned to each user from UOWs | ||
:return: True if the user number is an instrument scientist, false if not or failed connection. | ||
""" | ||
uows_url = os.environ.get("UOWS_URL", "https://devapi.facilities.rl.ac.uk/users-service") | ||
uows_api_key = os.environ.get("UOWS_API_KEY", "") | ||
response = requests.get( | ||
url=f"{uows_url}/v1/role/{user_number}", | ||
headers={"Authorization": f"Api-key {uows_api_key}", "accept": "application/json"}, | ||
timeout=1, | ||
) | ||
if response.status_code != HTTPStatus.OK: | ||
from fia_auth.auth import logger | ||
|
||
logger.info("User number %s is not an instrument scientist or UOWS API is down", user_number) | ||
return False | ||
roles = response.json() | ||
return {"name": "ISIS Instrument Scientist"} in roles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.