Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions gateway/api/migrations/0041_remove_allauth_tables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
Migration to remove django-allauth tables that are no longer used.

This migration cleans up tables from the 'account' and 'socialaccount' apps
that were part of django-allauth, which has been removed from the project.
"""

from django.db import migrations


def remove_allauth_tables(apps, schema_editor):
"""Remove allauth tables if they exist."""
# Skip in SQLite (tests). Allauth and socialaccount tables are never created
if schema_editor.connection.vendor == "sqlite":
return

tables = [
"socialaccount_socialtoken",
"socialaccount_socialapp_sites",
"socialaccount_socialapp",
"socialaccount_socialaccount",
"account_emailconfirmation",
"account_emailaddress",
]

with schema_editor.connection.cursor() as cursor:
for table in tables:
cursor.execute(f"DROP TABLE IF EXISTS {table} CASCADE")

cursor.execute(
"DELETE FROM django_migrations WHERE app IN ('account', 'socialaccount')"
)


def reverse_noop(apps, schema_editor):
"""No-op reverse migration"""
pass


class Migration(migrations.Migration):
dependencies = [
("api", "0040_programhistory"),
]

operations = [
migrations.RunPython(remove_allauth_tables, reverse_noop),
]
20 changes: 8 additions & 12 deletions gateway/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,18 @@ def build_env_variables( # pylint: disable=too-many-positional-arguments
job.id,
)

if settings.SETTINGS_AUTH_MECHANISM != "default":
if instance:
extra = {
"QISKIT_IBM_INSTANCE": str(instance),
}
extra.update(
{
"QISKIT_IBM_TOKEN": str(token),
"QISKIT_IBM_CHANNEL": channel.value,
"QISKIT_IBM_URL": settings.QISKIT_IBM_URL,
}
)
extra.update(
{
"QISKIT_IBM_TOKEN": str(token),
"QISKIT_IBM_CHANNEL": channel.value,
"QISKIT_IBM_URL": settings.QISKIT_IBM_URL,
}
)

if instance:
extra.update(
{
"QISKIT_IBM_INSTANCE": str(instance),
"ENV_JOB_GATEWAY_INSTANCE": str(instance),
}
)
Expand Down
30 changes: 2 additions & 28 deletions gateway/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import os
import os.path
import sys
from datetime import timedelta
from pathlib import Path
from utils import sanitize_file_path

Expand Down Expand Up @@ -71,9 +70,6 @@
"django_prometheus",
"rest_framework",
"rest_framework.authtoken",
"rest_framework_simplejwt",
"allauth",
"allauth.socialaccount",
"pgactivity",
"pglock",
"api",
Expand Down Expand Up @@ -201,11 +197,6 @@
},
]

AUTHENTICATION_BACKENDS = [
# `allauth` specific authentication methods, such as login by e-mail
"allauth.account.auth_backends.AuthenticationBackend",
]

# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/

Expand Down Expand Up @@ -235,13 +226,8 @@
# =============
# AUTH SETTINGS
# =============
SETTINGS_AUTH_MECHANISM = os.environ.get("SETTINGS_AUTH_MECHANISM", "default")
SETTINGS_DEFAULT_AUTH_CLASSES = [
"rest_framework_simplejwt.authentication.JWTAuthentication",
"dj_rest_auth.jwt_auth.JWTCookieAuthentication",
]
SETTINGS_AUTH_MECHANISM = os.environ.get("SETTINGS_AUTH_MECHANISM", "custom_token")
ALL_AUTH_CLASSES_CONFIGURATION = {
"default": SETTINGS_DEFAULT_AUTH_CLASSES,
"custom_token": [
"api.authentication.CustomTokenBackend",
],
Expand All @@ -250,7 +236,7 @@
],
}
DJR_DEFAULT_AUTHENTICATION_CLASSES = ALL_AUTH_CLASSES_CONFIGURATION.get(
SETTINGS_AUTH_MECHANISM, SETTINGS_DEFAULT_AUTH_CLASSES
SETTINGS_AUTH_MECHANISM, ALL_AUTH_CLASSES_CONFIGURATION["mock_token"]
)
# mock token value
SETTINGS_AUTH_MOCK_TOKEN = os.environ.get("SETTINGS_AUTH_MOCK_TOKEN", "awesome_token")
Expand All @@ -270,12 +256,6 @@
"PAGE_SIZE": 100,
}

REST_AUTH = {
"USE_JWT": True,
# 'JWT_AUTH_COOKIE': 'gateway-app-auth',
# 'JWT_AUTH_REFRESH_COOKIE': 'gateway-refresh-token',
}

SWAGGER_SETTINGS = {
"SECURITY_DEFINITIONS": {
"Bearer Token": {
Expand All @@ -290,12 +270,6 @@
SITE_ID = 1
SITE_HOST = os.environ.get("SITE_HOST", "http://localhost:8000")

# Provider specific settings
SIMPLE_JWT = {
"ACCESS_TOKEN_LIFETIME": timedelta(days=10),
"REFRESH_TOKEN_LIFETIME": timedelta(days=20),
}

# custom token auth
QUANTUM_PLATFORM_API_BASE_URL = os.environ.get("QUANTUM_PLATFORM_API_BASE_URL", None)
# verification fields to check when returned from auth api
Expand Down
3 changes: 0 additions & 3 deletions gateway/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cryptography>=44.0.3, <45
djangorestframework>=3.15.2, <4
django-allauth[socialaccount]>=65.7.0, <66
django-allow-cidr>=0.7.1, <1
dj-rest-auth>=7.0.0, <8
django-csp>=3.8, <4
djangorestframework-simplejwt>=5.3.1, <6
django_prometheus>=2.3.1, <3
ray[default]>=2.30.0, <3
Django>=5.2.1, <6
Expand Down