From 0ce7b31502eb23e0ea18998444cf105030274727 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Wed, 28 Sep 2016 11:04:35 -0400 Subject: [PATCH] Fix default value validation for LDAP/SAML settings to prevent warnings. --- awx/conf/fields.py | 5 +++++ awx/sso/conf.py | 3 +++ awx/sso/fields.py | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/awx/conf/fields.py b/awx/conf/fields.py index a560d3a637..ae299137e6 100644 --- a/awx/conf/fields.py +++ b/awx/conf/fields.py @@ -34,6 +34,11 @@ class URLField(CharField): validator_kwargs['schemes'] = schemes 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): if self.allow_plain_hostname: try: diff --git a/awx/sso/conf.py b/awx/sso/conf.py index 264b609367..e0842f6031 100644 --- a/awx/sso/conf.py +++ b/awx/sso/conf.py @@ -169,6 +169,7 @@ register( field_class=fields.URLField, schemes=('ldap', 'ldaps'), allow_blank=True, + default='', label=_('LDAP Server URI'), 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 ' @@ -880,6 +881,7 @@ register( register( 'SOCIAL_AUTH_SAML_TECHNICAL_CONTACT', field_class=fields.SAMLContactField, + allow_blank=True, default={}, label=_('SAML Service Provider Technical Contact'), help_text=_('Configure this setting with your contact information.'), @@ -894,6 +896,7 @@ register( register( 'SOCIAL_AUTH_SAML_SUPPORT_CONTACT', field_class=fields.SAMLContactField, + allow_blank=True, default={}, label=_('SAML Service Provider Support Contact'), help_text=_('Configure this setting with your contact information.'), diff --git a/awx/sso/fields.py b/awx/sso/fields.py index 6655ad3523..a0d472756e 100644 --- a/awx/sso/fields.py +++ b/awx/sso/fields.py @@ -349,6 +349,10 @@ class BaseDictWithChildField(fields.DictField): } 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): value = super(BaseDictWithChildField, self).to_representation(value) for k, v in value.items(): @@ -367,7 +371,7 @@ class BaseDictWithChildField(fields.DictField): continue elif key not in data: 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(']') self.fail('missing_keys', missing_keys=keys_display) if not self.allow_unknown_keys: