diff --git a/src/aap_eda/api/resource_api.py b/src/aap_eda/api/resource_api.py new file mode 100644 index 000000000..c522af2f8 --- /dev/null +++ b/src/aap_eda/api/resource_api.py @@ -0,0 +1,35 @@ +# Copyright 2024 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ansible_base.resource_registry.registry import ( + ResourceConfig, + ServiceAPIConfig, + SharedResource, +) +from ansible_base.resource_registry.shared_types import UserType + +from aap_eda.core import models + + +class APIConfig(ServiceAPIConfig): + service_type = "eda" + + +RESOURCE_LIST = ( + ResourceConfig( + models.User, + shared_resource=SharedResource(serializer=UserType, is_provider=False), + name_field="username", + ), +) diff --git a/src/aap_eda/api/urls.py b/src/aap_eda/api/urls.py index 36a24456d..32b92348d 100644 --- a/src/aap_eda/api/urls.py +++ b/src/aap_eda/api/urls.py @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. from ansible_base.lib.dynamic_config.dynamic_urls import api_version_urls +from ansible_base.resource_registry.urls import ( + urlpatterns as resource_api_urls, +) from django.urls import include, path from drf_spectacular.views import ( SpectacularJSONAPIView, @@ -71,6 +74,7 @@ # <- Experimental LDAP Auth https://issues.redhat.com/browse/AAP-16938 path("", include(api_version_urls)), # -> + path("", include(resource_api_urls)), path("", include(openapi_urls)), path("auth/session/login/", views.SessionLoginView.as_view()), path("auth/session/logout/", views.SessionLogoutView.as_view()), diff --git a/src/aap_eda/settings/default.py b/src/aap_eda/settings/default.py index cc22f780d..9bd888c37 100644 --- a/src/aap_eda/settings/default.py +++ b/src/aap_eda/settings/default.py @@ -160,6 +160,7 @@ def _get_secret_key() -> str: "django_filters", # Experimental LDAP Auth https://issues.redhat.com/browse/AAP-16938 "ansible_base.authentication", + "ansible_base.resource_registry", # Local apps "aap_eda.api", "aap_eda.core", @@ -479,6 +480,11 @@ def _get_secret_key() -> str: "ANSIBLE_BASE_JWT_KEY", "https://localhost" ) +# --------------------------------------------------------- +# DJANGO ANSIBLE BASE RESOURCES REGISTRY SETTINGS +# --------------------------------------------------------- +ANSIBLE_BASE_RESOURCE_CONFIG_MODULE = "aap_eda.api.resource_api" + ACTIVATION_DB_HOST = settings.get( "ACTIVATION_DB_HOST", "host.containers.internal" )