44ANALYTICS = False
55ALLOWED_CONTENT_CHECKSUMS = ["sha1" , "sha256" , "sha512" ]
66
7- if os .environ .get ("PULP_HTTPS" , "false" ).lower () == "true" :
7+ pulp_https = os .environ .get ("PULP_HTTPS" , "false" ).lower () == "true"
8+ pulp_oauth2 = os .environ .get ("PULP_OAUTH2" , "false" ).lower () == "true"
9+
10+ if pulp_https and not pulp_oauth2 :
811 AUTHENTICATION_BACKENDS = "@merge django.contrib.auth.backends.RemoteUserBackend"
912 MIDDLEWARE = "@merge django.contrib.auth.middleware.RemoteUserMiddleware"
1013 REST_FRAMEWORK__DEFAULT_AUTHENTICATION_CLASSES = (
1114 "@merge pulpcore.app.authentication.PulpRemoteUserAuthentication"
1215 )
1316 REMOTE_USER_ENVIRON_NAME = "HTTP_REMOTEUSER"
1417
15- if os . environ . get ( "PULP_OAUTH2" , "false" ). lower () == "true" :
16- assert os . environ . get ( "PULP_HTTPS" , "false" ). lower () == "true"
18+ if pulp_oauth2 :
19+ assert pulp_https
1720
1821 def PulpCliFakeOauth2Authentication (* args , ** kwargs ):
1922 # We need to lazy load this.
2023 # Otherwise views may be instanciated, before this configuration is merged.
2124
22- from django .contrib .auth import authenticate
25+ from django .contrib .auth import get_user_model
2326 from drf_spectacular .extensions import OpenApiAuthenticationExtension
2427 from rest_framework .authentication import BaseAuthentication
2528
2629 class _PulpCliFakeOauth2Authentication (BaseAuthentication ):
2730 def authenticate (self , request ):
2831 auth_header = request .META .get ("HTTP_AUTHORIZATION" )
2932 if auth_header == "Bearer DEADBEEF" :
30- return authenticate ( request , remote_user = "admin" ), None
33+ return get_user_model (). objects . get ( username = "admin" ), None
3134 else :
3235 return None
3336
@@ -54,5 +57,5 @@ def get_security_definition(self, auto_schema):
5457 PULP_CLI_FAKE_OAUTH2_AUTHENTICATION = PulpCliFakeOauth2Authentication
5558
5659 REST_FRAMEWORK__DEFAULT_AUTHENTICATION_CLASSES = (
57- "@merge pulpcore.app.settings.PULP_CLI_FAKE_OAUTH2_AUTHENTICATION"
60+ "pulpcore.app.settings.PULP_CLI_FAKE_OAUTH2_AUTHENTICATION" ,
5861 )
0 commit comments