Skip to content

Commit

Permalink
More fixes from warnings in /docs/ page
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed May 8, 2024
1 parent b660136 commit f853acd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ansible_base/activitystream/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class Meta:
related_content_type_model = serializers.SerializerMethodField()
changes = serializers.SerializerMethodField()

def get_content_type_model(self, obj):
def get_content_type_model(self, obj) -> str:
if obj.content_type:
return obj.content_type.model

def get_related_content_type_model(self, obj):
def get_related_content_type_model(self, obj) -> str:
if obj.related_content_type:
return obj.related_content_type.model

Expand All @@ -47,7 +47,7 @@ def _field_value_to_python(self, entry, field_name, value):
field = model._meta.get_field(field_name)
return field.to_python(value)

def get_changes(self, obj):
def get_changes(self, obj) -> dict[str, dict]:
"""
We store strings, we have to convert them back to the correct type.
"""
Expand Down
8 changes: 8 additions & 0 deletions ansible_base/api_documentation/apps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from django.apps import AppConfig

from ansible_base.api_documentation.customizations import apply_authentication_customizations


class ApiDocumentationConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'ansible_base.api_documentation'
label = 'dab_api_documentation'

def ready(self):
from django.conf import settings

if 'ansible_base.authentication' in settings.INSTALLED_APPS:
apply_authentication_customizations()
16 changes: 16 additions & 0 deletions ansible_base/api_documentation/customizations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def apply_authentication_customizations() -> None:
"""Make the schema generator of the type of DAB authentication classes"""
from drf_spectacular.authentication import SessionScheme

from ansible_base.authentication.session import SessionAuthentication

class MyAuthenticationScheme(SessionScheme):
target_class = SessionAuthentication # full import path OR class ref
name = 'SessionAuthentication'

def get_security_definition(self, auto_schema):
return {
'type': 'apiKey',
'in': 'header',
'name': 'api_key',
}
6 changes: 6 additions & 0 deletions test_app/authentication/logged_basic_auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from django.utils.encoding import smart_str
from drf_spectacular.authentication import BasicScheme
from rest_framework import authentication

logger = logging.getLogger('test_app.authentication.logged_basic_auth')
Expand All @@ -20,3 +21,8 @@ def authenticate_header(self, request):

# NOTE: This file is common to many of the services and will allow DRF to return a 401 instead of a 403 on failed login.
# This is the expected behavior we want so we need this file in test_app to mimic other applications


class MyAuthenticationScheme(BasicScheme):
target_class = LoggedBasicAuthentication
name = 'LoggedBasicAuthentication' # name used in the schema

0 comments on commit f853acd

Please sign in to comment.