inm-icf-utilities/tests/test_datalad_workflows/utils.py
Christian Monch a300135a82 use HttpUrlOperations.probe_url for realm retrival
This commit changes the test utilities to use
existing functionality in HttpUrlOperations to
determine the authentication realm of a URL.
2024-07-05 10:20:09 +02:00

24 lines
640 B
Python

from __future__ import annotations
from datalad_next.url_operations.http import HttpUrlOperations
def get_restricted_realm(url: str) -> str | None:
"""Get the realm for basic auth-restricted access
Parameters
----------
url: str
URL to probe
Returns
-------
str | None
The name of the realm for basic authentication
or None, if either no authentication is required,
or if the authentication type is not "basic"
"""
http_url_ops = HttpUrlOperations()
_, url_properties = http_url_ops.probe_url(url)
return url_properties.get('auth', {}).get('basic', {}).get('realm')