Commit 6ed7fd7a authored by msuhr1's avatar msuhr1
Browse files

Updated is_authorized method to take into account the effects of the new...

Updated is_authorized method to take into account the effects of the new replace_credentials preprocessing.
parent c403de8b
Pipeline #180188 passed with stages
in 1 minute and 16 seconds
......@@ -15,6 +15,7 @@ from typing import Any, Dict, Optional, Union, List
from annotator import config
from annotator import error_log
from annotator import models_activeworkflow as awmodels
from annotator.config import BasicSettings
from annotator.errors import ActiveWorkflowError
......@@ -154,10 +155,8 @@ def is_authorized(
Check if a params section is authorized to use this Annotation agent instance.
This method will check 1) if credentials are set in the configuration of the agent and 2)
whether the supplied params are authorized to use the agent. If not credentials are set
(which is the default), the method will return True. In any other case, the `api_key`
option has to contain the credential name in Liquid Templating notation which refers to
the credentials parameter.
whether the supplied params are authorized to use the agent. If no credentials are set
(which is the default), the method will return True.
Parameters
----------
......@@ -169,30 +168,14 @@ def is_authorized(
bool
True if parameters hold valid credentials, authorizing any request. False otherwise
"""
api_keys = BasicSettings().application_api_keys
if len(config.BasicSettings().application_api_keys) == 0:
if len(api_keys) == 0:
# If there are no credentials set, no credentials are needed.
return True
set_api_key = params.options.api_key
if set_api_key.startswith("{%") and set_api_key.endswith("%}"):
set_api_key = set_api_key[2:-2].strip()
if set_api_key.startswith("credential"):
search_credential_name = set_api_key[len("credential"):].strip()
else:
# If you end up here: an api key like `{% something %}` has been supplied. Either use
# the `credential` key word or use the plain API key, but do not mix.
return False
else:
if set_api_key.strip() in config.BasicSettings().application_api_keys:
return True
else:
return False
for credential in params.credentials:
if credential.name == search_credential_name:
if credential.value in config.BasicSettings().application_api_keys:
return True
if params.options.api_key in api_keys:
return True
return False
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment