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)