|
4 | 4 | # Django |
5 | 5 | from django.core.checks import Error |
6 | 6 | from django.utils.translation import gettext_lazy as _ |
7 | | -from django.conf import settings |
8 | 7 |
|
9 | 8 | # Django REST Framework |
10 | 9 | from rest_framework import serializers |
@@ -975,123 +974,122 @@ def csrf_trusted_origins_validate(serializer, attrs): |
975 | 974 | register_validate('system', csrf_trusted_origins_validate) |
976 | 975 |
|
977 | 976 |
|
978 | | -if settings.FEATURE_POLICY_AS_CODE_ENABLED: # Unable to use flag_enabled due to AppRegistryNotReady error |
979 | | - register( |
980 | | - 'OPA_HOST', |
981 | | - field_class=fields.CharField, |
982 | | - label=_('OPA server hostname'), |
983 | | - default='', |
984 | | - help_text=_('The hostname used to connect to the OPA server. If empty, policy enforcement will be disabled.'), |
985 | | - category=('PolicyAsCode'), |
986 | | - category_slug='policyascode', |
987 | | - allow_blank=True, |
988 | | - ) |
989 | | - |
990 | | - register( |
991 | | - 'OPA_PORT', |
992 | | - field_class=fields.IntegerField, |
993 | | - label=_('OPA server port'), |
994 | | - default=8181, |
995 | | - help_text=_('The port used to connect to the OPA server. Defaults to 8181.'), |
996 | | - category=('PolicyAsCode'), |
997 | | - category_slug='policyascode', |
998 | | - ) |
999 | | - |
1000 | | - register( |
1001 | | - 'OPA_SSL', |
1002 | | - field_class=fields.BooleanField, |
1003 | | - label=_('Use SSL for OPA connection'), |
1004 | | - default=False, |
1005 | | - help_text=_('Enable or disable the use of SSL to connect to the OPA server. Defaults to false.'), |
1006 | | - category=('PolicyAsCode'), |
1007 | | - category_slug='policyascode', |
1008 | | - ) |
1009 | | - |
1010 | | - register( |
1011 | | - 'OPA_AUTH_TYPE', |
1012 | | - field_class=fields.ChoiceField, |
1013 | | - label=_('OPA authentication type'), |
1014 | | - choices=[OPA_AUTH_TYPES.NONE, OPA_AUTH_TYPES.TOKEN, OPA_AUTH_TYPES.CERTIFICATE], |
1015 | | - default=OPA_AUTH_TYPES.NONE, |
1016 | | - help_text=_('The authentication type that will be used to connect to the OPA server: "None", "Token", or "Certificate".'), |
1017 | | - category=('PolicyAsCode'), |
1018 | | - category_slug='policyascode', |
1019 | | - ) |
1020 | | - |
1021 | | - register( |
1022 | | - 'OPA_AUTH_TOKEN', |
1023 | | - field_class=fields.CharField, |
1024 | | - label=_('OPA authentication token'), |
1025 | | - default='', |
1026 | | - help_text=_( |
1027 | | - 'The token for authentication to the OPA server. Required when OPA_AUTH_TYPE is "Token". If an authorization header is defined in OPA_AUTH_CUSTOM_HEADERS, it will be overridden by OPA_AUTH_TOKEN.' |
1028 | | - ), |
1029 | | - category=('PolicyAsCode'), |
1030 | | - category_slug='policyascode', |
1031 | | - allow_blank=True, |
1032 | | - encrypted=True, |
1033 | | - ) |
1034 | | - |
1035 | | - register( |
1036 | | - 'OPA_AUTH_CLIENT_CERT', |
1037 | | - field_class=fields.CharField, |
1038 | | - label=_('OPA client certificate content'), |
1039 | | - default='', |
1040 | | - help_text=_('The content of the client certificate file for mTLS authentication to the OPA server. Required when OPA_AUTH_TYPE is "Certificate".'), |
1041 | | - category=('PolicyAsCode'), |
1042 | | - category_slug='policyascode', |
1043 | | - allow_blank=True, |
1044 | | - ) |
1045 | | - |
1046 | | - register( |
1047 | | - 'OPA_AUTH_CLIENT_KEY', |
1048 | | - field_class=fields.CharField, |
1049 | | - label=_('OPA client key content'), |
1050 | | - default='', |
1051 | | - help_text=_('The content of the client key for mTLS authentication to the OPA server. Required when OPA_AUTH_TYPE is "Certificate".'), |
1052 | | - category=('PolicyAsCode'), |
1053 | | - category_slug='policyascode', |
1054 | | - allow_blank=True, |
1055 | | - encrypted=True, |
1056 | | - ) |
1057 | | - |
1058 | | - register( |
1059 | | - 'OPA_AUTH_CA_CERT', |
1060 | | - field_class=fields.CharField, |
1061 | | - label=_('OPA CA certificate content'), |
1062 | | - default='', |
1063 | | - help_text=_('The content of the CA certificate for mTLS authentication to the OPA server. Required when OPA_AUTH_TYPE is "Certificate".'), |
1064 | | - category=('PolicyAsCode'), |
1065 | | - category_slug='policyascode', |
1066 | | - allow_blank=True, |
1067 | | - ) |
1068 | | - |
1069 | | - register( |
1070 | | - 'OPA_AUTH_CUSTOM_HEADERS', |
1071 | | - field_class=fields.DictField, |
1072 | | - label=_('OPA custom authentication headers'), |
1073 | | - default={}, |
1074 | | - help_text=_('Optional custom headers included in requests to the OPA server. Defaults to empty dictionary ({}).'), |
1075 | | - category=('PolicyAsCode'), |
1076 | | - category_slug='policyascode', |
1077 | | - ) |
1078 | | - |
1079 | | - register( |
1080 | | - 'OPA_REQUEST_TIMEOUT', |
1081 | | - field_class=fields.FloatField, |
1082 | | - label=_('OPA request timeout'), |
1083 | | - default=1.5, |
1084 | | - help_text=_('The number of seconds after which the connection to the OPA server will time out. Defaults to 1.5 seconds.'), |
1085 | | - category=('PolicyAsCode'), |
1086 | | - category_slug='policyascode', |
1087 | | - ) |
1088 | | - |
1089 | | - register( |
1090 | | - 'OPA_REQUEST_RETRIES', |
1091 | | - field_class=fields.IntegerField, |
1092 | | - label=_('OPA request retry count'), |
1093 | | - default=2, |
1094 | | - help_text=_('The number of retry attempts for connecting to the OPA server. Default is 2.'), |
1095 | | - category=('PolicyAsCode'), |
1096 | | - category_slug='policyascode', |
1097 | | - ) |
| 977 | +register( |
| 978 | + 'OPA_HOST', |
| 979 | + field_class=fields.CharField, |
| 980 | + label=_('OPA server hostname'), |
| 981 | + default='', |
| 982 | + help_text=_('The hostname used to connect to the OPA server. If empty, policy enforcement will be disabled.'), |
| 983 | + category=('PolicyAsCode'), |
| 984 | + category_slug='policyascode', |
| 985 | + allow_blank=True, |
| 986 | +) |
| 987 | + |
| 988 | +register( |
| 989 | + 'OPA_PORT', |
| 990 | + field_class=fields.IntegerField, |
| 991 | + label=_('OPA server port'), |
| 992 | + default=8181, |
| 993 | + help_text=_('The port used to connect to the OPA server. Defaults to 8181.'), |
| 994 | + category=('PolicyAsCode'), |
| 995 | + category_slug='policyascode', |
| 996 | +) |
| 997 | + |
| 998 | +register( |
| 999 | + 'OPA_SSL', |
| 1000 | + field_class=fields.BooleanField, |
| 1001 | + label=_('Use SSL for OPA connection'), |
| 1002 | + default=False, |
| 1003 | + help_text=_('Enable or disable the use of SSL to connect to the OPA server. Defaults to false.'), |
| 1004 | + category=('PolicyAsCode'), |
| 1005 | + category_slug='policyascode', |
| 1006 | +) |
| 1007 | + |
| 1008 | +register( |
| 1009 | + 'OPA_AUTH_TYPE', |
| 1010 | + field_class=fields.ChoiceField, |
| 1011 | + label=_('OPA authentication type'), |
| 1012 | + choices=[OPA_AUTH_TYPES.NONE, OPA_AUTH_TYPES.TOKEN, OPA_AUTH_TYPES.CERTIFICATE], |
| 1013 | + default=OPA_AUTH_TYPES.NONE, |
| 1014 | + help_text=_('The authentication type that will be used to connect to the OPA server: "None", "Token", or "Certificate".'), |
| 1015 | + category=('PolicyAsCode'), |
| 1016 | + category_slug='policyascode', |
| 1017 | +) |
| 1018 | + |
| 1019 | +register( |
| 1020 | + 'OPA_AUTH_TOKEN', |
| 1021 | + field_class=fields.CharField, |
| 1022 | + label=_('OPA authentication token'), |
| 1023 | + default='', |
| 1024 | + help_text=_( |
| 1025 | + 'The token for authentication to the OPA server. Required when OPA_AUTH_TYPE is "Token". If an authorization header is defined in OPA_AUTH_CUSTOM_HEADERS, it will be overridden by OPA_AUTH_TOKEN.' |
| 1026 | + ), |
| 1027 | + category=('PolicyAsCode'), |
| 1028 | + category_slug='policyascode', |
| 1029 | + allow_blank=True, |
| 1030 | + encrypted=True, |
| 1031 | +) |
| 1032 | + |
| 1033 | +register( |
| 1034 | + 'OPA_AUTH_CLIENT_CERT', |
| 1035 | + field_class=fields.CharField, |
| 1036 | + label=_('OPA client certificate content'), |
| 1037 | + default='', |
| 1038 | + help_text=_('The content of the client certificate file for mTLS authentication to the OPA server. Required when OPA_AUTH_TYPE is "Certificate".'), |
| 1039 | + category=('PolicyAsCode'), |
| 1040 | + category_slug='policyascode', |
| 1041 | + allow_blank=True, |
| 1042 | +) |
| 1043 | + |
| 1044 | +register( |
| 1045 | + 'OPA_AUTH_CLIENT_KEY', |
| 1046 | + field_class=fields.CharField, |
| 1047 | + label=_('OPA client key content'), |
| 1048 | + default='', |
| 1049 | + help_text=_('The content of the client key for mTLS authentication to the OPA server. Required when OPA_AUTH_TYPE is "Certificate".'), |
| 1050 | + category=('PolicyAsCode'), |
| 1051 | + category_slug='policyascode', |
| 1052 | + allow_blank=True, |
| 1053 | + encrypted=True, |
| 1054 | +) |
| 1055 | + |
| 1056 | +register( |
| 1057 | + 'OPA_AUTH_CA_CERT', |
| 1058 | + field_class=fields.CharField, |
| 1059 | + label=_('OPA CA certificate content'), |
| 1060 | + default='', |
| 1061 | + help_text=_('The content of the CA certificate for mTLS authentication to the OPA server. Required when OPA_AUTH_TYPE is "Certificate".'), |
| 1062 | + category=('PolicyAsCode'), |
| 1063 | + category_slug='policyascode', |
| 1064 | + allow_blank=True, |
| 1065 | +) |
| 1066 | + |
| 1067 | +register( |
| 1068 | + 'OPA_AUTH_CUSTOM_HEADERS', |
| 1069 | + field_class=fields.DictField, |
| 1070 | + label=_('OPA custom authentication headers'), |
| 1071 | + default={}, |
| 1072 | + help_text=_('Optional custom headers included in requests to the OPA server. Defaults to empty dictionary ({}).'), |
| 1073 | + category=('PolicyAsCode'), |
| 1074 | + category_slug='policyascode', |
| 1075 | +) |
| 1076 | + |
| 1077 | +register( |
| 1078 | + 'OPA_REQUEST_TIMEOUT', |
| 1079 | + field_class=fields.FloatField, |
| 1080 | + label=_('OPA request timeout'), |
| 1081 | + default=1.5, |
| 1082 | + help_text=_('The number of seconds after which the connection to the OPA server will time out. Defaults to 1.5 seconds.'), |
| 1083 | + category=('PolicyAsCode'), |
| 1084 | + category_slug='policyascode', |
| 1085 | +) |
| 1086 | + |
| 1087 | +register( |
| 1088 | + 'OPA_REQUEST_RETRIES', |
| 1089 | + field_class=fields.IntegerField, |
| 1090 | + label=_('OPA request retry count'), |
| 1091 | + default=2, |
| 1092 | + help_text=_('The number of retry attempts for connecting to the OPA server. Default is 2.'), |
| 1093 | + category=('PolicyAsCode'), |
| 1094 | + category_slug='policyascode', |
| 1095 | +) |
0 commit comments