def __init__(self,
                 url,
                 max_schemas_per_subject=1000,
                 ca_location=None,
                 cert_location=None,
                 key_location=None):
        # In order to maintain compatibility the url(conf in future versions) param has been preserved for now.
        conf = url
        if not isinstance(url, dict):
            conf = {
                'url': url,
                'ssl.ca.location': ca_location,
                'ssl.certificate.location': cert_location,
                'ssl.key.location': key_location
            }
            warnings.warn(
                "CachedSchemaRegistry constructor is being deprecated. "
                "Use CachedSchemaRegistryClient(dict: config) instead. "
                "Existing params ca_location, cert_location and key_location will be replaced with their "
                "librdkafka equivalents as keys in the conf dict: `ssl.ca.location`, `ssl.certificate.location` and "
                "`ssl.key.location` respectively",
                category=DeprecationWarning,
                stacklevel=2)
            """Construct a Schema Registry client"""

        # Ensure URL valid scheme is included; http[s]
        url = conf.pop('url', '')
        if not isinstance(url, string_type):
            raise TypeError("URL must be of type str")

        if not url.startswith('http'):
            raise ValueError("Invalid URL provided for Schema Registry")

        self.url = url.rstrip('/')

        # subj => { schema => id }
        self.subject_to_schema_ids = defaultdict(dict)
        # id => avro_schema
        self.id_to_schema = defaultdict(dict)
        # subj => { schema => version }
        self.subject_to_schema_versions = defaultdict(dict)

        s = Session()
        ca_path = conf.pop('ssl.ca.location', None)
        if ca_path is not None:
            s.verify = ca_path
        s.cert = self._configure_client_tls(conf)
        s.auth = self._configure_basic_auth(self.url, conf)
        self.url = utils.urldefragauth(self.url)

        self._session = s

        self.auto_register_schemas = conf.pop("auto.register.schemas", True)

        self.additional_headers = conf.pop("additional.headers", None)

        if len(conf) > 0:
            raise ValueError(
                "Unrecognized configuration properties: {}".format(
                    conf.keys()))
Beispiel #2
0
    def __init__(self, uri):

        # move basic auth creds into headers to avoid
        # https://github.com/requests/requests/issues/4275
        username, password = get_auth_from_url(uri)
        uri = urldefragauth(uri)

        self._base_url = '{}/api'.format(uri)
        self._session = Session()
        self._session.auth = HTTPBasicAuth(username, password)
        self._session.headers['content-type'] = 'application/json'
        self._verify_api_connection()
Beispiel #3
0
    def __init__(self, uri):

        # move basic auth creds into headers to avoid
        # https://github.com/requests/requests/issues/4275
        username, password = get_auth_from_url(uri)
        uri = urldefragauth(uri)

        self._base_url = '{}/api'.format(uri)
        self._session = Session()
        self._session.auth = HTTPBasicAuth(username, password)
        self._session.headers['content-type'] = 'application/json'
        self._verify_api_connection()
Beispiel #4
0
 def _configure_basic_auth(conf):
     url = conf['url']
     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 {}"
                          .format(VALID_AUTH_PROVIDERS))
     if auth_provider == 'SASL_INHERIT':
         if conf.pop('sasl.mechanism', '').upper() is ['GSSAPI']:
             raise ValueError("SASL_INHERIT does not support SASL mechanisms GSSAPI")
         auth = (conf.pop('sasl.username', ''), conf.pop('sasl.password', ''))
     elif auth_provider == 'USER_INFO':
         auth = tuple(conf.pop('basic.auth.user.info', '').split(':'))
     else:
         auth = utils.get_auth_from_url(url)
     conf['url'] = utils.urldefragauth(url)
     return auth
Beispiel #5
0
    def _configure_basic_auth(conf: dict) -> typing.Union[None, str, typing.Tuple[str, str]]:
        url = conf["url"]
        auth_provider = conf.pop("basic.auth.credentials.source", "URL").upper()

        if auth_provider not in utils.VALID_AUTH_PROVIDERS:
            raise ValueError(
                f"schema.registry.basic.auth.credentials.source " f"must be one of {utils.VALID_AUTH_PROVIDERS}"
            )

        if auth_provider == "SASL_INHERIT":
            if conf.pop("sasl.mechanism", "").upper() is ["GSSAPI"]:
                raise ValueError("SASL_INHERIT does not support SASL mechanisms GSSAPI")
            auth = (conf.pop("sasl.username", ""), conf.pop("sasl.password", ""))
        elif auth_provider == "USER_INFO":
            auth = tuple(conf.pop("basic.auth.user.info", "").split(":"))  # type: ignore
        else:
            auth = requests_utils.get_auth_from_url(url)
        conf["url"] = requests_utils.urldefragauth(url)

        return auth
Beispiel #6
0
def test_urldefragauth(url, expected):
    assert urldefragauth(url) == expected
Beispiel #7
0
def test_urldefragauth(url, expected):
    assert urldefragauth(url) == expected
 def request_url(self, request, proxies):
     proxy = select_proxy(request.url, proxies)
     if (not proxy.lower().startswith('socks') and
        request.url.lower().startswith('https://')):
         return urldefragauth(request.url)
     return super().request_url(request, proxies)