Skip to content

Commit

Permalink
remove unicore env requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
ludvigalden committed Jan 23, 2024
1 parent fdadf3b commit 7205602
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/moore/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@
INSTAGRAM_REDIRECT_URL = config('INSTAGRAM_REDIRECT_URL', default='')

try:
UNICORE_URL = config('UNICORE_URL')
UNICORE_ADMIN = config('UNICORE_ADMIN')
except UndefinedValueError:
# This allows the tests to be runned without having to have UNICORE_URL and
Expand All @@ -256,11 +255,18 @@
# not filled in the variables in their .env. I.e. The variables are still
# required, except for when the tests are runned.
if not IS_RUNNING_TEST:
raise UndefinedValueError(
"You must add UNICORE_URL and UNICORE_ADMIN to you .env file"
)
print(UndefinedValueError(
"You are missing UNICORE_ADMIN in your .env file, which means "
+ "user data cannot be retrieved from Unicore. All users will "
+ "be assumed to be members of UTN (is_member returns True)."
))

UNICORE_ADMIN = config('UNICORE_ADMIN', default='')
UNICORE_ORG_ID = config('UNICORE_ORG_ID', default='')
UNICORE_URL = config(
'UNICORE_URL',
default='https://unicorecustomapi.mecenat.com/utn'
)

# Google API
GOOGLE_API_KEY = config('GOOGLE_API_KEY', default='')
Expand Down
7 changes: 7 additions & 0 deletions src/utils/unicore_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def request_get(self, path, params=None):
if params is not None:
params['orgId'] = settings.UNICORE_ORG_ID

if settings.UNICORE_ADMIN == '':
raise requests.exceptions.RequestException(
"Missing token to make requests to the Unicore API."
)

return requests.get(
settings.UNICORE_URL + "/" + path,
auth=HTTPBasicAuth('admin', settings.UNICORE_ADMIN),
Expand Down Expand Up @@ -89,6 +94,8 @@ def get_user_data(unicore_id):

@staticmethod
def is_member(ssn):
if settings.UNICORE_ADMIN == '':
return True
UnicoreClient.__setup()
return UnicoreClient.client.is_member(ssn)

Expand Down

0 comments on commit 7205602

Please sign in to comment.