diff options
author | Zuul <zuul@review.openstack.org> | 2019-01-17 02:44:57 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2019-01-17 02:44:57 +0000 |
commit | e39aa0cffada9da42d2b5f9102a3c33264a4bc73 (patch) | |
tree | a663b1d746706815bf30a31f15c990cdb1d80d16 /oslo_config | |
parent | c63b8b8df9a77bec905b515d28b9ad3429c69d6a (diff) | |
parent | 4a2b7af7182118923c68a49be897c15c71fed56f (diff) | |
download | oslo-config-e39aa0cffada9da42d2b5f9102a3c33264a4bc73.tar.gz |
Merge "Resolve deprecation warning for rfc3986 uri validation"
Diffstat (limited to 'oslo_config')
-rw-r--r-- | oslo_config/types.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/oslo_config/types.py b/oslo_config/types.py index a973d0e..652599b 100644 --- a/oslo_config/types.py +++ b/oslo_config/types.py @@ -884,20 +884,23 @@ class URI(ConfigType): self.schemes = schemes def __call__(self, value): - if not rfc3986.is_valid_uri(value, require_scheme=True, - require_authority=True): - raise ValueError('invalid URI: %r' % value) + uri = rfc3986.uri_reference(value) + validator = rfc3986.validators.Validator().require_presence_of( + 'scheme', 'host', + ).check_validity_of( + 'scheme', 'host', 'path', + ) + if self.schemes: + validator = validator.allow_schemes(*self.schemes) + try: + validator.validate(uri) + except rfc3986.exceptions.RFC3986Exception as exc: + raise ValueError(exc) if self.max_length is not None and len(value) > self.max_length: raise ValueError("Value '%s' exceeds maximum length %d" % (value, self.max_length)) - if self.schemes: - scheme = rfc3986.uri_reference(value).scheme - if scheme not in self.schemes: - raise ValueError("URI scheme '%s' not in %s" % - (scheme, self.schemes)) - # NOTE(dhellmann): self.value is deprecated, and we don't want # to trigger a deprecation warning ourselves so we modify # self._value directly. |