diff --git a/.github/template_gitref b/.github/template_gitref index e2852b3..201b085 100644 --- a/.github/template_gitref +++ b/.github/template_gitref @@ -1 +1 @@ -2021.08.26-425-gfdd7d2d +2021.08.26-426-g3a3f8a1 diff --git a/.github/workflows/scripts/install.sh b/.github/workflows/scripts/install.sh index ee45184..6d74464 100755 --- a/.github/workflows/scripts/install.sh +++ b/.github/workflows/scripts/install.sh @@ -69,7 +69,7 @@ VARSYAML cat >> vars/main.yaml << VARSYAML pulp_env: {} -pulp_settings: null +pulp_settings: {"smart_proxy_rhsm_url": "https://rhsm.example.com/rhsm"} pulp_scheme: https pulp_default_container: ghcr.io/pulp/pulp-ci-centos9:latest VARSYAML diff --git a/pulp_smart_proxy/app/__init__.py b/pulp_smart_proxy/app/__init__.py index 1515698..99df878 100644 --- a/pulp_smart_proxy/app/__init__.py +++ b/pulp_smart_proxy/app/__init__.py @@ -9,3 +9,7 @@ class PulpSmartProxyPluginAppConfig(PulpPluginAppConfig): version = "0.0.0.dev" python_package_name = "pulp_smart_proxy" domain_compatible = True + + def ready(self): + super().ready() + from . import checks diff --git a/pulp_smart_proxy/app/checks.py b/pulp_smart_proxy/app/checks.py new file mode 100644 index 0000000..b72df35 --- /dev/null +++ b/pulp_smart_proxy/app/checks.py @@ -0,0 +1,15 @@ +from django.conf import settings +from django.core.checks import Error as CheckError, register + + +@register(deploy=True) +def smart_proxy_rhsm_url_check(app_configs, **kwargs): + messages = [] + if getattr(settings, "SMART_PROXY_RHSM_URL", "UNREACHABLE") == "UNREACHABLE": + messages.append( + CheckError( + "SMART_PROXY_RHSM_URL is a required setting but it was not configured.", + id="pulp_smart_proxy.E001", + ) + ) + return messages diff --git a/pulp_smart_proxy/app/settings.py b/pulp_smart_proxy/app/settings.py index c67a45c..582cdf3 100644 --- a/pulp_smart_proxy/app/settings.py +++ b/pulp_smart_proxy/app/settings.py @@ -1,6 +1,4 @@ -""" -Check `Plugin Writer's Guide`_ for more details. - -.. _Plugin Writer's Guide: - https://pulpproject.org/pulpcore/docs/dev/ -""" +SMART_PROXY_MIRROR = False +SMART_PROXY_AUTH_USERNAME = None +SMART_PROXY_AUTH_PASSWORD = None +SMART_PROXY_AUTH_METHODS = ["client_certificate"] diff --git a/pulp_smart_proxy/app/urls.py b/pulp_smart_proxy/app/urls.py new file mode 100644 index 0000000..67198e8 --- /dev/null +++ b/pulp_smart_proxy/app/urls.py @@ -0,0 +1,19 @@ +from django.conf import settings +from django.urls import path, include + +from .views import FeaturesView, FeaturesV2View, VersionView + +if settings.DOMAIN_ENABLED: + V3_API_ROOT = settings.V3_DOMAIN_API_ROOT_NO_FRONT_SLASH +else: + V3_API_ROOT = settings.V3_API_ROOT_NO_FRONT_SLASH + +smart_proxy_patterns = [ + path("features", FeaturesView.as_view()), + path("v2/features", FeaturesV2View.as_view()), + path("version", VersionView.as_view()), +] + +urlpatterns = [ + path(f"{V3_API_ROOT}smart_proxy/", include(smart_proxy_patterns)), +] diff --git a/pulp_smart_proxy/app/views.py b/pulp_smart_proxy/app/views.py new file mode 100644 index 0000000..64c5da9 --- /dev/null +++ b/pulp_smart_proxy/app/views.py @@ -0,0 +1,73 @@ +from urllib.parse import urljoin + +from django.conf import settings +from drf_spectacular.utils import extend_schema +from rest_framework.response import Response +from rest_framework.views import APIView + +from pulpcore.app.apps import pulp_plugin_configs, get_plugin_config + + +class FeaturesView(APIView): + """ + Returns features of the smart_proxy + """ + + @extend_schema( + summary="Inspect features", + operation_id="features_read", + ) + def get(self, request): + data = ["pulpcore"] + return Response(data) + + +class FeaturesV2View(APIView): + """ + Returns features of the smart_proxy in v2 format + """ + + @extend_schema( + summary="Inspect features", + operation_id="featuresv2_read", + ) + def get(self, request): + # there is no setting for the API url + # not adding /pulp/api/v3 here as Katello does so on its own + pulp_url = request.build_absolute_uri("/") + # CONTENT_ORIGIN can be None, guess based on the API url then + content_origin = settings.CONTENT_ORIGIN or pulp_url + capabilities = [app.label for app in pulp_plugin_configs()] + data = { + "pulpcore": { + "http_enabled": False, + "https_enabled": True, + "settings": { + "pulp_url": pulp_url, + "mirror": settings.SMART_PROXY_MIRROR, + "content_app_url": urljoin(content_origin, settings.CONTENT_PATH_PREFIX), + "username": settings.SMART_PROXY_AUTH_USERNAME, + "password": settings.SMART_PROXY_AUTH_PASSWORD, + "client_authentication": settings.SMART_PROXY_AUTH_METHODS, + "rhsm_url": settings.SMART_PROXY_RHSM_URL, + }, + "state": "running", + "capabilities": capabilities, + } + } + + return Response(data) + + +class VersionView(APIView): + """ + Returns version of the smart_proxy plugin + """ + + @extend_schema( + summary="Inspect version", + operation_id="version_read", + ) + def get(self, request): + data = {"version": get_plugin_config("smart_proxy").version} + return Response(data) diff --git a/pulp_smart_proxy/tests/functional/api/test_smart_proxy_api.py b/pulp_smart_proxy/tests/functional/api/test_smart_proxy_api.py new file mode 100644 index 0000000..a48f3aa --- /dev/null +++ b/pulp_smart_proxy/tests/functional/api/test_smart_proxy_api.py @@ -0,0 +1,17 @@ +import requests +from urllib.parse import urljoin + + +def test_version(pulp_api_v3_url): + r = requests.get(urljoin(pulp_api_v3_url, "smart_proxy/version")) + assert "version" in r.json() + + +def test_features(pulp_api_v3_url): + r = requests.get(urljoin(pulp_api_v3_url, "smart_proxy/features")) + assert ["pulpcore"] == r.json() + + +def test_features_v2(pulp_api_v3_url): + r = requests.get(urljoin(pulp_api_v3_url, "smart_proxy/v2/features")) + assert "pulpcore" in r.json() diff --git a/template_config.yml b/template_config.yml index cadab89..4a75cd4 100644 --- a/template_config.yml +++ b/template_config.yml @@ -40,7 +40,8 @@ pulp_env_azure: {} pulp_env_gcp: {} pulp_env_s3: {} pulp_scheme: https -pulp_settings: null +pulp_settings: + smart_proxy_rhsm_url: https://rhsm.example.com/rhsm pulp_settings_azure: domain_enabled: true pulp_settings_gcp: null