-
Notifications
You must be signed in to change notification settings - Fork 2
Initial implementation of the smart_proxy app #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 2021.08.26-425-gfdd7d2d | ||
| 2021.08.26-426-g3a3f8a1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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("/") | ||
evgeni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # 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, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering if we could derive these values from settings. We set some values (https://github.com/theforeman/puppet-pulpcore/blob/8288f3736a1543417eba6322e7013d0f230bd85e/templates/settings.py.erb#L52-L59) so perhaps that works. I think you should check if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about that, but then wasn't sure how to get from Looking at https://pulpproject.org/pulpcore/docs/admin/guides/auth/external/,
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The non-cert option is mostly interesting for development setups, but I think it's highly questionable if it makes sense in this plugin. In the Ruby based implementation we assume a trusted (authenticated) channel from Foreman to Foreman Proxy. The v2 features API (which exposes the settings) is normally only available if you are authenticated (typically using client certs). If you take that to this, you either make the username/password available without authentication (effectively disabling authentication) or you have authentication but then don't need the credentials. What you can do is to return
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this related to pulp/pulpcore#5438 which we could not bring forward until openapi 3.1.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorta, but also not really :) We have a Pulp running somewhere, and we need to tell the "client" (Katello) how to get there and how to auth there. So yeah, if the APIdoc would announce "you can use certs here", that would get rid of that particular line, the whole concept of "someone tells katello how pulp is configured" remains (I'd argue the way we do discovery of services, like pulp, is not optimal) |
||
| "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} | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes Foreman issue a warning as the version obviously doesn't match the Foreman version…
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought Foreman is supposed to work with "older" versions of the smart proxy...
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does! Doesn't forbid it to issue useless warnings ;)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, I've been complaining about that a few times: we need a better way to determine compatibility than version numbers. |
||
| return Response(data) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() |
Uh oh!
There was an error while loading. Please reload this page.