mirror of
https://github.com/ansible/awx.git
synced 2026-04-07 02:59:21 -02:30
Merge pull request #3606 from cchurch/fix-ldap-saml-defaults
Fix default value validation for LDAP/SAML settings to prevent warnings.
This commit is contained in:
@@ -34,6 +34,11 @@ class URLField(CharField):
|
|||||||
validator_kwargs['schemes'] = schemes
|
validator_kwargs['schemes'] = schemes
|
||||||
self.validators.append(URLValidator(**validator_kwargs))
|
self.validators.append(URLValidator(**validator_kwargs))
|
||||||
|
|
||||||
|
def to_representation(self, value):
|
||||||
|
if value is None:
|
||||||
|
return ''
|
||||||
|
return super(URLField, self).to_representation(value)
|
||||||
|
|
||||||
def run_validators(self, value):
|
def run_validators(self, value):
|
||||||
if self.allow_plain_hostname:
|
if self.allow_plain_hostname:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -169,6 +169,7 @@ register(
|
|||||||
field_class=fields.URLField,
|
field_class=fields.URLField,
|
||||||
schemes=('ldap', 'ldaps'),
|
schemes=('ldap', 'ldaps'),
|
||||||
allow_blank=True,
|
allow_blank=True,
|
||||||
|
default='',
|
||||||
label=_('LDAP Server URI'),
|
label=_('LDAP Server URI'),
|
||||||
help_text=_('URI to connect to LDAP server, such as "ldap://ldap.example.com:389" '
|
help_text=_('URI to connect to LDAP server, such as "ldap://ldap.example.com:389" '
|
||||||
'(non-SSL) or "ldaps://ldap.example.com:636" (SSL). LDAP authentication '
|
'(non-SSL) or "ldaps://ldap.example.com:636" (SSL). LDAP authentication '
|
||||||
@@ -880,6 +881,7 @@ register(
|
|||||||
register(
|
register(
|
||||||
'SOCIAL_AUTH_SAML_TECHNICAL_CONTACT',
|
'SOCIAL_AUTH_SAML_TECHNICAL_CONTACT',
|
||||||
field_class=fields.SAMLContactField,
|
field_class=fields.SAMLContactField,
|
||||||
|
allow_blank=True,
|
||||||
default={},
|
default={},
|
||||||
label=_('SAML Service Provider Technical Contact'),
|
label=_('SAML Service Provider Technical Contact'),
|
||||||
help_text=_('Configure this setting with your contact information.'),
|
help_text=_('Configure this setting with your contact information.'),
|
||||||
@@ -894,6 +896,7 @@ register(
|
|||||||
register(
|
register(
|
||||||
'SOCIAL_AUTH_SAML_SUPPORT_CONTACT',
|
'SOCIAL_AUTH_SAML_SUPPORT_CONTACT',
|
||||||
field_class=fields.SAMLContactField,
|
field_class=fields.SAMLContactField,
|
||||||
|
allow_blank=True,
|
||||||
default={},
|
default={},
|
||||||
label=_('SAML Service Provider Support Contact'),
|
label=_('SAML Service Provider Support Contact'),
|
||||||
help_text=_('Configure this setting with your contact information.'),
|
help_text=_('Configure this setting with your contact information.'),
|
||||||
|
|||||||
@@ -349,6 +349,10 @@ class BaseDictWithChildField(fields.DictField):
|
|||||||
}
|
}
|
||||||
allow_unknown_keys = False
|
allow_unknown_keys = False
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.allow_blank = kwargs.pop('allow_blank', False)
|
||||||
|
super(BaseDictWithChildField, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def to_representation(self, value):
|
def to_representation(self, value):
|
||||||
value = super(BaseDictWithChildField, self).to_representation(value)
|
value = super(BaseDictWithChildField, self).to_representation(value)
|
||||||
for k, v in value.items():
|
for k, v in value.items():
|
||||||
@@ -367,7 +371,7 @@ class BaseDictWithChildField(fields.DictField):
|
|||||||
continue
|
continue
|
||||||
elif key not in data:
|
elif key not in data:
|
||||||
missing_keys.add(key)
|
missing_keys.add(key)
|
||||||
if missing_keys:
|
if missing_keys and (data or not self.allow_blank):
|
||||||
keys_display = json.dumps(list(missing_keys)).lstrip('[').rstrip(']')
|
keys_display = json.dumps(list(missing_keys)).lstrip('[').rstrip(']')
|
||||||
self.fail('missing_keys', missing_keys=keys_display)
|
self.fail('missing_keys', missing_keys=keys_display)
|
||||||
if not self.allow_unknown_keys:
|
if not self.allow_unknown_keys:
|
||||||
|
|||||||
Reference in New Issue
Block a user