Skip to content

Commit

Permalink
fix error with trailing slash at the end (@IvanProdaiko94 , #749)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Prodaiko authored and rnpridgeon committed Dec 28, 2019
1 parent ba874b4 commit 143c37b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 4 additions & 7 deletions confluent_kafka/avro/cached_schema_registry_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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

Expand All @@ -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 {}"
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/avro/test_cached_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 143c37b

Please sign in to comment.