Skip to content

Commit

Permalink
fixed authn token issue
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyBRoswell committed Dec 6, 2024
1 parent dfa5834 commit 7c4c53d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion vreapis/auth/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ def authenticate(self, request: HttpRequest):
access_token: str = request.headers.get('Authorization', '')
print(access_token == f'Token {settings.NAAVRE_API_TOKEN}')
if access_token != f'Token {settings.NAAVRE_API_TOKEN}':
raise AuthenticationFailed(f'Invalid token')
raise AuthenticationFailed(f'Invalid NaaVRE API token')
return StaticTokenAuthentication.dummy_user, None
8 changes: 4 additions & 4 deletions vreapis/containerizer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from services.extractor.rextractor import RExtractor
from services.converter import ConverterReactFlowChart
import utils.cors
from auth.simple import StaticTokenAuthentication
# from auth.simple import StaticTokenAuthentication
from catalog.models import Cell

import common
Expand All @@ -55,7 +55,7 @@ def return_error(err_msg: str = 'Unknown ERROR', e: Optional[Exception] = None,


@api_view(['GET'])
@authentication_classes([StaticTokenAuthentication])
# @authentication_classes([StaticTokenAuthentication])
@permission_classes([IsAuthenticated])
def get_base_images(request):
url: str = os.getenv('BASE_IMAGE_TAGS_URL', 'https://github.com/QCDIS/NaaVRE-flavors/releases/latest/download/base_image_tags.json')
Expand All @@ -70,7 +70,7 @@ def get_base_images(request):


class ExtractorHandler(APIView):
authentication_classes = [StaticTokenAuthentication]
# authentication_classes = [StaticTokenAuthentication]
permission_classes = [IsAuthenticated]

def extract_cell_by_index(self, notebook: nbformat.notebooknode, cell_index: int) -> nbformat.NotebookNode:
Expand Down Expand Up @@ -204,7 +204,7 @@ class CellsHandler(viewsets.ModelViewSet):
common.logger.debug(f"BASE_PATH: {os.getenv('BASE_PATH')}")
queryset: QuerySet = Cell.objects.all()
serializer_class = CellSerializer
authentication_classes: list[BaseAuthentication] = [StaticTokenAuthentication]
# authentication_classes: list[BaseAuthentication] = [StaticTokenAuthentication]
permission_classes: list[BasePermission] = [IsAuthenticated]
cells_path: str = os.path.join(str(Path.home()), 'NaaVRE', 'cells')
github_url_repos: str = 'https://api.github.com/repos'
Expand Down
22 changes: 11 additions & 11 deletions vreapis/vreapis/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

ALLOWED_HOSTS = ['*']

# CSRF_TRUSTED_ORIGINS = [os.getenv('TRUSTED_ORIGINS')]
CSRF_TRUSTED_ORIGINS = os.getenv('TRUSTED_ORIGINS').split(sep=';')
CSRF_TRUSTED_ORIGINS = [os.getenv('TRUSTED_ORIGINS')]
# CSRF_TRUSTED_ORIGINS = os.getenv('TRUSTED_ORIGINS').split(sep=';')

CORS_ALLOWED_ORIGIN_REGEXES = [
r'^http:\/\/localhost:\d+$',
Expand Down Expand Up @@ -190,14 +190,14 @@

# CUSTOM VARS # todo. delete default values

API_ENDPOINT: str = os.getenv('API_ENDPOINT', "https://naavre-dev.minikube.test/vre-api-test")

KEYCLOAK_URL: str = os.getenv('KEYCLOAK_URL', 'https://naavre-dev.minikube.test/auth')
KEYCLOAK_REALM: str = os.getenv('KEYCLOAK_REALM', 'vre')
KEYCLOAK_LOGIN_URL: str = f'{KEYCLOAK_URL}/realms/{KEYCLOAK_REALM}/protocol/openid-connect/token'
KEYCLOAK_VERIF_URL: str = f'{KEYCLOAK_URL}/realms/{KEYCLOAK_REALM}/protocol/openid-connect/certs'
KEYCLOAK_CLIENT_ID: str = os.getenv('KEYCLOAK_CLIENT_ID', 'myclient')

NAAVRE_API_TOKEN: str = os.getenv('NAAVRE_API_TOKEN')
# API_ENDPOINT: str = os.getenv('API_ENDPOINT', "https://naavre-dev.minikube.test/vre-api-test")
#
# KEYCLOAK_URL: str = os.getenv('KEYCLOAK_URL', 'https://naavre-dev.minikube.test/auth')
# KEYCLOAK_REALM: str = os.getenv('KEYCLOAK_REALM', 'vre')
# KEYCLOAK_LOGIN_URL: str = f'{KEYCLOAK_URL}/realms/{KEYCLOAK_REALM}/protocol/openid-connect/token'
# KEYCLOAK_VERIF_URL: str = f'{KEYCLOAK_URL}/realms/{KEYCLOAK_REALM}/protocol/openid-connect/certs'
# KEYCLOAK_CLIENT_ID: str = os.getenv('KEYCLOAK_CLIENT_ID', 'myclient')
#
# NAAVRE_API_TOKEN: str = os.getenv('NAAVRE_API_TOKEN')

VENV_ACTIVATOR: str = os.getenv('VENV_ACTIVATOR', '/opt/venv/bin/activate')

0 comments on commit 7c4c53d

Please sign in to comment.