| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| """ | ||
| URL utility functions for the Databricks SQL connector. | ||
| """ | ||
|
|
||
|
|
||
| def normalize_host_with_protocol(host: str) -> str: | ||
| """ | ||
| Normalize a connection hostname by ensuring it has a protocol. | ||
|
|
||
| This is useful for handling cases where users may provide hostnames with or without protocols | ||
| (common with dbt-databricks users copying URLs from their browser). | ||
|
|
||
| Args: | ||
| host: Connection hostname which may or may not include a protocol prefix (https:// or http://) | ||
|
Comment thread
nikhilsuri-db marked this conversation as resolved.
|
||
| and may or may not have a trailing slash | ||
|
|
||
| Returns: | ||
| Normalized hostname with protocol prefix and no trailing slashes | ||
|
|
||
| Examples: | ||
| normalize_host_with_protocol("myserver.com") -> "https://myserver.com" | ||
| normalize_host_with_protocol("https://myserver.com") -> "https://myserver.com" | ||
| normalize_host_with_protocol("HTTPS://myserver.com/") -> "https://myserver.com" | ||
| normalize_host_with_protocol("http://localhost:8080/") -> "http://localhost:8080" | ||
|
|
||
| Raises: | ||
| ValueError: If host is None or empty string | ||
| """ | ||
| # Handle None or empty host | ||
| if not host or not host.strip(): | ||
| raise ValueError("Host cannot be None or empty") | ||
|
|
||
| # Remove trailing slashes | ||
| host = host.rstrip("/") | ||
|
Comment thread
nikhilsuri-db marked this conversation as resolved.
|
||
|
|
||
| # Add protocol if not present (case-insensitive check) | ||
| host_lower = host.lower() | ||
| if not host_lower.startswith("https://") and not host_lower.startswith("http://"): | ||
| host = f"https://{host}" | ||
| elif host_lower.startswith("https://") or host_lower.startswith("http://"): | ||
| # Normalize protocol to lowercase | ||
| protocol_end = host.index("://") + 3 | ||
| host = host[:protocol_end].lower() + host[protocol_end:] | ||
|
|
||
| return host | ||
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.