From 6bd39aea4b223071a26243c3a5f324ea965da84d Mon Sep 17 00:00:00 2001 From: Mauricio Magnani Jr Date: Tue, 13 May 2025 15:41:29 -0300 Subject: [PATCH] OPA server hostname with https or http results in connection errors (#6921) Signed-off-by: Mauricio Magnani --- awx/main/conf.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/awx/main/conf.py b/awx/main/conf.py index 8d9ea54fa8..4d6921d35d 100644 --- a/awx/main/conf.py +++ b/awx/main/conf.py @@ -1117,3 +1117,11 @@ if settings.FEATURE_POLICY_AS_CODE_ENABLED: # Unable to use flag_enabled due to category=('PolicyAsCode'), category_slug='policyascode', ) + + def policy_as_code_validate(serializer, attrs): + opa_host = attrs.get('OPA_HOST', '') + if opa_host and (opa_host.startswith('http://') or opa_host.startswith('https://')): + raise serializers.ValidationError({'OPA_HOST': _("OPA_HOST should not include 'http://' or 'https://' prefixes. Please enter only the hostname.")}) + return attrs + + register_validate('policyascode', policy_as_code_validate)