diff --git a/confluent_kafka/avro/cached_schema_registry_client.py b/confluent_kafka/avro/cached_schema_registry_client.py index af9ce88e4..a3d15a541 100644 --- a/confluent_kafka/avro/cached_schema_registry_client.py +++ b/confluent_kafka/avro/cached_schema_registry_client.py @@ -85,7 +85,7 @@ def __init__(self, url, max_schemas_per_subject=1000, ca_location=None, cert_loc """Construct a Schema Registry client""" # Ensure URL valid scheme is included; http[s] - url = conf.get('url', '') + url = conf.pop('url', '') if not isinstance(url, string_type): raise TypeError("URL must be of type str") @@ -106,9 +106,8 @@ def __init__(self, url, max_schemas_per_subject=1000, ca_location=None, cert_loc if ca_path is not None: s.verify = ca_path s.cert = self._configure_client_tls(conf) - s.auth = self._configure_basic_auth(conf) - - self.url = conf.pop('url') + s.auth = self._configure_basic_auth(self.url, conf) + self.url = utils.urldefragauth(self.url) self._session = s @@ -128,8 +127,7 @@ def close(self): self._session.close() @staticmethod - def _configure_basic_auth(conf): - url = conf['url'] + def _configure_basic_auth(url, conf): auth_provider = conf.pop('basic.auth.credentials.source', 'URL').upper() if auth_provider not in VALID_AUTH_PROVIDERS: raise ValueError("schema.registry.basic.auth.credentials.source must be one of {}" @@ -142,7 +140,6 @@ def _configure_basic_auth(conf): auth = tuple(conf.pop('basic.auth.user.info', '').split(':')) else: auth = utils.get_auth_from_url(url) - conf['url'] = utils.urldefragauth(url) return auth @staticmethod diff --git a/tests/avro/test_cached_client.py b/tests/avro/test_cached_client.py index 2ee116e91..e713e43f4 100644 --- a/tests/avro/test_cached_client.py +++ b/tests/avro/test_cached_client.py @@ -180,6 +180,12 @@ def test_invalid_url(self): 'url': 'example.com:65534' }) + def test_trailing_slash_removal(self): + self.client = CachedSchemaRegistryClient({ + 'url': 'http://127.0.0.1:65534/' + }) + self.assertEqual(self.client.url, "http://127.0.0.1:65534") + def test_basic_auth_url(self): self.client = CachedSchemaRegistryClient({ 'url': 'https://user_url:secret_url@127.0.0.1:65534',