Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error with trailing slash at the end #749

Merged
merged 1 commit into from
Dec 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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):
IvanProdaiko94 marked this conversation as resolved.
Show resolved Hide resolved
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