Skip to content
Merged
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
15 changes: 6 additions & 9 deletions .ci/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,30 @@
ANALYTICS = False
ALLOWED_CONTENT_CHECKSUMS = ["sha1", "sha256", "sha512"]

pulp_https = os.environ.get("PULP_HTTPS", "false").lower() == "true"
pulp_oauth2 = os.environ.get("PULP_OAUTH2", "false").lower() == "true"

if pulp_https and not pulp_oauth2:
if os.environ.get("PULP_HTTPS", "false").lower() == "true":
AUTHENTICATION_BACKENDS = "@merge django.contrib.auth.backends.RemoteUserBackend"
MIDDLEWARE = "@merge django.contrib.auth.middleware.RemoteUserMiddleware"
REST_FRAMEWORK__DEFAULT_AUTHENTICATION_CLASSES = (
"@merge pulpcore.app.authentication.PulpRemoteUserAuthentication"
)
REMOTE_USER_ENVIRON_NAME = "HTTP_REMOTEUSER"

if pulp_oauth2:
assert pulp_https
if os.environ.get("PULP_OAUTH2", "false").lower() == "true":
assert os.environ.get("PULP_HTTPS", "false").lower() == "true"

def PulpCliFakeOauth2Authentication(*args, **kwargs):
# We need to lazy load this.
# Otherwise views may be instanciated, before this configuration is merged.

from django.contrib.auth import get_user_model
from django.contrib.auth import authenticate
from drf_spectacular.extensions import OpenApiAuthenticationExtension
from rest_framework.authentication import BaseAuthentication

class _PulpCliFakeOauth2Authentication(BaseAuthentication):
def authenticate(self, request):
auth_header = request.META.get("HTTP_AUTHORIZATION")
if auth_header == "Bearer DEADBEEF":
return get_user_model().objects.get(username="admin"), None
return authenticate(request, remote_user="admin"), None
else:
return None

Expand All @@ -57,5 +54,5 @@ def get_security_definition(self, auto_schema):
PULP_CLI_FAKE_OAUTH2_AUTHENTICATION = PulpCliFakeOauth2Authentication

REST_FRAMEWORK__DEFAULT_AUTHENTICATION_CLASSES = (
"pulpcore.app.settings.PULP_CLI_FAKE_OAUTH2_AUTHENTICATION",
"@merge pulpcore.app.settings.PULP_CLI_FAKE_OAUTH2_AUTHENTICATION"
)
Loading