Skip to content

Commit

Permalink
Refactor into apps and lib
Browse files Browse the repository at this point in the history
  • Loading branch information
john-westcott-iv committed Jan 17, 2024
1 parent 2520d24 commit b7b7a1f
Show file tree
Hide file tree
Showing 89 changed files with 402 additions and 299 deletions.
67 changes: 0 additions & 67 deletions ansible_base/README.md

This file was deleted.

File renamed without changes.
6 changes: 6 additions & 0 deletions ansible_base/api_documentation/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ApiDocumentationConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'ansible_base.api_documentation'
File renamed without changes.
8 changes: 8 additions & 0 deletions ansible_base/api_documentation/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView

urlpatterns = [
path('docs/schema/', SpectacularAPIView.as_view(), name='schema'),
path('docs/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
path('docs/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
]
8 changes: 0 additions & 8 deletions ansible_base/apps.py

This file was deleted.

2 changes: 1 addition & 1 deletion ansible_base/authentication/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.apps import AppConfig

import ansible_base.checks # noqa: F401 - register checks
import ansible_base.lib.checks # noqa: F401 - register checks


class AuthenticationConfig(AppConfig):
Expand Down
2 changes: 1 addition & 1 deletion ansible_base/authentication/authenticator_plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rest_framework.serializers import ValidationError

from ansible_base.authentication.models import Authenticator
from ansible_base.common.serializers.fields import JSONField
from ansible_base.lib.serializers.fields import JSONField

logger = logging.getLogger('ansible_base.authentication.authenticator_plugins.base')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ansible_base.authentication.authenticator_plugins.base import AbstractAuthenticatorPlugin, BaseAuthenticatorConfiguration
from ansible_base.authentication.social_auth import SocialAuthMixin
from ansible_base.common.serializers.fields import CharField, URLField
from ansible_base.lib.serializers.fields import CharField, URLField

logger = logging.getLogger('ansible_base.authentication.authenticator_plugins.keycloak')

Expand Down
4 changes: 2 additions & 2 deletions ansible_base/authentication/authenticator_plugins/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

from ansible_base.authentication.authenticator_plugins.base import AbstractAuthenticatorPlugin, Authenticator, BaseAuthenticatorConfiguration
from ansible_base.authentication.utils.claims import get_or_create_authenticator_user, update_user_claims
from ansible_base.common.serializers.fields import BooleanField, CharField, ChoiceField, DictField, ListField, URLListField, UserAttrMap
from ansible_base.common.utils.validation import VALID_STRING
from ansible_base.lib.serializers.fields import BooleanField, CharField, ChoiceField, DictField, ListField, URLListField, UserAttrMap
from ansible_base.lib.utils.validation import VALID_STRING

logger = logging.getLogger('ansible_base.authentication.authenticator_plugins.ldap')

Expand Down
6 changes: 3 additions & 3 deletions ansible_base/authentication/authenticator_plugins/saml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from ansible_base.authentication.authenticator_plugins.utils import generate_authenticator_slug, get_authenticator_plugin
from ansible_base.authentication.models import Authenticator
from ansible_base.authentication.social_auth import AuthenticatorConfigTestStrategy, AuthenticatorStorage, AuthenticatorStrategy, SocialAuthMixin
from ansible_base.common.serializers.fields import CharField, JSONField, ListField, PrivateKey, PublicCert, URLField
from ansible_base.common.utils.encryption import ENCRYPTED_STRING
from ansible_base.common.utils.validation import validate_cert_with_key
from ansible_base.lib.serializers.fields import CharField, JSONField, ListField, PrivateKey, PublicCert, URLField
from ansible_base.lib.utils.encryption import ENCRYPTED_STRING
from ansible_base.lib.utils.validation import validate_cert_with_key

logger = logging.getLogger('ansible_base.authentication.authenticator_plugins.saml')

Expand Down
8 changes: 4 additions & 4 deletions ansible_base/authentication/models/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from django.db.models import JSONField, ManyToManyField, fields

from ansible_base.authentication.authenticator_plugins.utils import generate_authenticator_slug, get_authenticator_plugin
from ansible_base.common.models.common import UniqueNamedCommonModel
from ansible_base.common.utils.models import prevent_search
from ansible_base.lib.abstract_models.common import UniqueNamedCommonModel
from ansible_base.lib.utils.models import prevent_search


class Authenticator(UniqueNamedCommonModel):
Expand Down Expand Up @@ -35,7 +35,7 @@ class Authenticator(UniqueNamedCommonModel):
reverse_foreign_key_fields = ['authenticator-map']

def save(self, *args, **kwargs):
from ansible_base.common.utils.encryption import ansible_encryption
from ansible_base.lib.utils.encryption import ansible_encryption

# Here we are going to allow an exception to raise because what else can we do at this point?
authenticator = get_authenticator_plugin(self.type)
Expand All @@ -58,7 +58,7 @@ def __str__(self):

@classmethod
def from_db(cls, db, field_names, values):
from ansible_base.common.utils.encryption import ENCRYPTED_STRING, ansible_encryption
from ansible_base.lib.utils.encryption import ENCRYPTED_STRING, ansible_encryption

instance = super().from_db(db, field_names, values)

Expand Down
2 changes: 1 addition & 1 deletion ansible_base/authentication/models/authenticator_map.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models

from ansible_base.common.models.common import NamedCommonModel
from ansible_base.lib.abstract_models.common import NamedCommonModel

from .authenticator import Authenticator

Expand Down
4 changes: 2 additions & 2 deletions ansible_base/authentication/serializers/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from ansible_base.authentication.authenticator_plugins.utils import get_authenticator_plugin, get_authenticator_plugins
from ansible_base.authentication.models import Authenticator
from ansible_base.common.serializers.common import NamedCommonModelSerializer
from ansible_base.common.utils.encryption import ENCRYPTED_STRING
from ansible_base.lib.serializers.common import NamedCommonModelSerializer
from ansible_base.lib.utils.encryption import ENCRYPTED_STRING

logger = logging.getLogger('ansible_base.authentication.serializers.authenticator')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from ansible_base.authentication.models import AuthenticatorMap
from ansible_base.authentication.utils.trigger_definition import TRIGGER_DEFINITION
from ansible_base.common.serializers.common import NamedCommonModelSerializer
from ansible_base.lib.serializers.common import NamedCommonModelSerializer


class AuthenticatorMapSerializer(NamedCommonModelSerializer):
Expand Down
4 changes: 2 additions & 2 deletions ansible_base/authentication/views/ui_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from rest_framework.views import APIView

from ansible_base.authentication.models import Authenticator
from ansible_base.common.utils.settings import get_setting
from ansible_base.common.utils.validation import validate_image_data, validate_url
from ansible_base.lib.utils.settings import get_setting
from ansible_base.lib.utils.validation import validate_image_data, validate_url

logger = logging.getLogger('ansible_base.authentication.views.ui_auth')

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from inflection import underscore
from rest_framework.reverse import reverse

logger = logging.getLogger('ansible_base.common.models.common')
logger = logging.getLogger('ansible_base.lib.abstract_models.common')


class CommonModel(models.Model):
Expand Down Expand Up @@ -71,7 +71,7 @@ def save(self, *args, **kwargs):
update_fields.append('modified_by')

# Encrypt any fields
from ansible_base.common.utils.encryption import ansible_encryption
from ansible_base.lib.utils.encryption import ansible_encryption

for field in self.encrypted_fields:
field_value = getattr(self, field, None)
Expand All @@ -84,7 +84,7 @@ def save(self, *args, **kwargs):
def from_db(self, db, field_names, values):
instance = super().from_db(db, field_names, values)

from ansible_base.common.utils.encryption import ENCRYPTED_STRING, ansible_encryption
from ansible_base.lib.utils.encryption import ENCRYPTED_STRING, ansible_encryption

for field in self.encrypted_fields:
field_value = getattr(instance, field, None)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from rest_framework.request import Request
from rest_framework.settings import api_settings

logger = logging.getLogger('ansible_base.channels.middleware')
logger = logging.getLogger('ansible_base.lib.channels.middleware')
User = get_user_model()


Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,42 @@
#

try:
ANSIBLE_BASE_FEATURES # noqa: F821
INSTALLED_APPS # noqa: F821
except NameError:
ANSIBLE_BASE_FEATURES = {}
INSTALLED_APPS = []

try:
INSTALLED_APPS # noqa: F821
REST_FRAMEWORK # noqa: F821
except NameError:
INSTALLED_APPS = []
REST_FRAMEWORK = {}


if ANSIBLE_BASE_FEATURES.get('SWAGGER', False): # noqa: F821
if 'drf_spectacular' not in INSTALLED_APPS: # noqa: F821
INSTALLED_APPS.append('drf_spectacular') # noqa: F821
if 'ansible_base.api_documentation' in INSTALLED_APPS:
if 'drf_spectacular' not in INSTALLED_APPS:
INSTALLED_APPS.append('drf_spectacular')

try:
SPECTACULAR_SETTINGS # noqa: F821
except NameError:
SPECTACULAR_SETTINGS = {
'TITLE': 'AAP Open API',
'DESCRIPTION': 'AAP Open API',
'VERSION': 'v1',
'SCHEMA_PATH_PREFIX': '/api/v1/',
}

if 'DEFAULT_SCHEMA_CLASS' not in REST_FRAMEWORK:
REST_FRAMEWORK['DEFAULT_SCHEMA_CLASS'] = 'drf_spectacular.openapi.AutoSchema'


if ANSIBLE_BASE_FEATURES.get('FILTERING', False): # noqa: F821
REST_FRAMEWORK.update( # noqa: F821
if 'ansible_base.rest_filters' in INSTALLED_APPS:
REST_FRAMEWORK.update(
{
'DEFAULT_FILTER_BACKENDS': (
'ansible_base.filters.rest_framework.type_filter_backend.TypeFilterBackend',
'ansible_base.filters.rest_framework.field_lookup_backend.FieldLookupBackend',
'ansible_base.rest_filters.rest_framework.type_filter_backend.TypeFilterBackend',
'ansible_base.rest_filters.rest_framework.field_lookup_backend.FieldLookupBackend',
'rest_framework.filters.SearchFilter',
'ansible_base.filters.rest_framework.order_backend.OrderByBackend',
'ansible_base.rest_filters.rest_framework.order_backend.OrderByBackend',
)
}
)
Expand All @@ -51,11 +64,6 @@
except NameError:
MIDDLEWARE = [middleware_class]

try:
REST_FRAMEWORK # noqa: F821
except NameError:
REST_FRAMEWORK = {}

drf_authentication_class = 'ansible_base.authentication.session.SessionAuthentication'
if 'DEFAULT_AUTHENTICATION_CLASSES' not in REST_FRAMEWORK: # noqa: F821
REST_FRAMEWORK['DEFAULT_AUTHENTICATION_CLASSES'] = [] # noqa: F821
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.conf import settings
from django.urls import include, path

logger = logging.getLogger('ansible_base.urls')
logger = logging.getLogger('ansible_base.lib.dynamic_config.dynamic_urls')

list_actions = {'get': 'list', 'post': 'create'}
detail_actions = {'get': 'retrieve', 'put': 'update', 'patch': 'partial_update', 'delete': 'destroy'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from rest_framework.fields import empty
from rest_framework.reverse import reverse_lazy

from ansible_base.common.utils.encryption import ENCRYPTED_STRING
from ansible_base.lib.utils.encryption import ENCRYPTED_STRING

logger = logging.getLogger('ansible_base.common.serializers.common')
logger = logging.getLogger('ansible_base.lib.serializers.common')


class CommonModelSerializer(serializers.ModelSerializer):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from django.contrib.auth import get_user_model
from rest_framework import serializers

from ansible_base.common.utils.encryption import ENCRYPTED_STRING
from ansible_base.common.utils.validation import validate_url, validate_url_list
from ansible_base.lib.utils.encryption import ENCRYPTED_STRING
from ansible_base.lib.utils.validation import validate_url, validate_url_list

User = get_user_model()

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AuthToken(BaseModel):
sensitive_data = prevent_search(models.CharField(...))
The flag set by this function is used by
`ansible_base.filters.rest_framework.field_lookup_backend.FieldLookupBackend` to block fields and relations that
`ansible_base.rest_filters.rest_framework.field_lookup_backend.FieldLookupBackend` to block fields and relations that
should not be searchable/filterable via search query params
"""
setattr(relation, '__prevent_search__', True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django.conf import settings

logger = logging.getLogger('ansible_base.common.utils.settings')
logger = logging.getLogger('ansible_base.lib.utils.settings')


class SettingNotSetException(Exception):
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions ansible_base/rest_filters/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.apps import AppConfig

import ansible_base.lib.checks # noqa: F401 - register checks


class AuthenticationConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'ansible_base.rest_filters'
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from rest_framework.exceptions import ParseError
from rest_framework.filters import BaseFilterBackend

from ansible_base.common.utils.validation import to_python_boolean
from ansible_base.filters.utils import get_fields_from_path
from ansible_base.lib.utils.validation import to_python_boolean
from ansible_base.rest_filters.utils import get_fields_from_path


class FieldLookupBackend(BaseFilterBackend):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rest_framework.exceptions import ParseError
from rest_framework.filters import BaseFilterBackend

from ansible_base.filters.utils import get_all_field_names, get_field_from_path
from ansible_base.rest_filters.utils import get_all_field_names, get_field_from_path


class OrderByBackend(BaseFilterBackend):
Expand Down
Loading

0 comments on commit b7b7a1f

Please sign in to comment.