-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathsettings.py
More file actions
59 lines (47 loc) · 2.37 KB
/
Copy pathsettings.py
File metadata and controls
59 lines (47 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
ALLOWED_EXPORT_PATHS = ["/tmp"]
ANALYTICS = False
ALLOWED_CONTENT_CHECKSUMS = ["sha1", "sha256", "sha512"]
TASK_DIAGNOSTICS = ["memory"]
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 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 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 authenticate(request, remote_user="admin"), None
else:
return None
def authenticate_header(self, request):
return 'Bearer realm="Pulp"'
class PulpCliFakeOauth2AuthenticationScheme(OpenApiAuthenticationExtension):
target_class = _PulpCliFakeOauth2Authentication
name = "PulpCliFakeOauth2"
def get_security_definition(self, auto_schema):
return {
"type": "oauth2",
"flows": {
"clientCredentials": {
"tokenUrl": "https://localhost:8080/oauth2token/",
"scopes": {"api.console": "grant_access_to_pulp"},
},
},
}
return _PulpCliFakeOauth2Authentication(*args, **kwargs)
PULP_CLI_FAKE_OAUTH2_AUTHENTICATION = PulpCliFakeOauth2Authentication
REST_FRAMEWORK__DEFAULT_AUTHENTICATION_CLASSES = (
"@merge pulpcore.app.settings.PULP_CLI_FAKE_OAUTH2_AUTHENTICATION"
)