mirror of
https://github.com/ansible/awx.git
synced 2026-10-30 06:13:24 -02:30
Pure formatting commit — no logic changes. Run `ruff format` across awx/ and awxkit/ (awx_collection excluded).
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
# Copyright (c) 2015 Ansible, Inc.
|
|
# All Rights Reserved.
|
|
|
|
# Python
|
|
import logging
|
|
|
|
# Django
|
|
from django.conf import settings
|
|
from django.utils.encoding import smart_str
|
|
|
|
# Django REST Framework
|
|
from rest_framework import authentication
|
|
|
|
logger = logging.getLogger('awx.api.authentication')
|
|
|
|
|
|
class LoggedBasicAuthentication(authentication.BasicAuthentication):
|
|
def authenticate(self, request):
|
|
if not settings.AUTH_BASIC_ENABLED:
|
|
return
|
|
ret = super(LoggedBasicAuthentication, self).authenticate(request)
|
|
if ret:
|
|
username = ret[0].username if ret[0] else '<none>'
|
|
logger.info(smart_str("User {} performed a {} to {} through the API".format(username, request.method, request.path)))
|
|
return ret
|
|
|
|
def authenticate_header(self, request):
|
|
if not settings.AUTH_BASIC_ENABLED:
|
|
return
|
|
return super(LoggedBasicAuthentication, self).authenticate_header(request)
|
|
|
|
|
|
class SessionAuthentication(authentication.SessionAuthentication):
|
|
def authenticate_header(self, request):
|
|
return 'Session'
|