Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions kubernetes/client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,29 @@ def __init__(self, host="http://localhost",
self.proxy = None
"""Proxy URL
"""
self.no_proxy = None
# Load proxy from environment variables (if set)
self.authorization_header = "Authorization"
"""Custom authorization header name (default: "Authorization")"""
self.no_proxy = []
# Load proxy from environment variables (if set)
if os.getenv("HTTPS_PROXY"): self.proxy = os.getenv("HTTPS_PROXY")
if os.getenv("https_proxy"): self.proxy = os.getenv("https_proxy")
if os.getenv("HTTP_PROXY"): self.proxy = os.getenv("HTTP_PROXY")
if os.getenv("http_proxy"): self.proxy = os.getenv("http_proxy")
# Load no_proxy from environment variables (if set)
if os.getenv("NO_PROXY"): self.no_proxy = os.getenv("NO_PROXY")
if os.getenv("no_proxy"): self.no_proxy = os.getenv("no_proxy")
# Load and parse no_proxy from environment variables
# Check for uppercase NO_PROXY first (should take precedence)
no_proxy_env = None
# Check if NO_PROXY exists in environment (even if empty)
if "NO_PROXY" in os.environ:
no_proxy_env = os.getenv("NO_PROXY")
elif "no_proxy" in os.environ:
no_proxy_env = os.getenv("no_proxy")

if no_proxy_env is not None and no_proxy_env != "":
self.no_proxy = [
domain.strip()
for domain in no_proxy_env.split(",")
if domain.strip()
]
"""bypass proxy for host in the no_proxy list.
"""
self.proxy_headers = None
Expand Down Expand Up @@ -345,12 +359,22 @@ def auth_settings(self):
:return: The Auth Settings information dict.
"""
auth = {}
if 'authorization' in self.api_key:
# Check for the configured authorization header name in api_key (case-insensitive)
header_name_lower = self.authorization_header.lower()

# Find the actual key in api_key that matches case-insensitively
actual_key = None
for key in self.api_key:
if key.lower() == header_name_lower:
actual_key = key
break

if actual_key is not None:
auth['BearerToken'] = {
'type': 'api_key',
'in': 'header',
'key': 'authorization',
'value': self.get_api_key_with_prefix('authorization')
'key': self.authorization_header, # Use the configured case
'value': self.get_api_key_with_prefix(actual_key) # Use the actual key from api_key
}
return auth

Expand Down Expand Up @@ -411,4 +435,4 @@ def get_host_from_settings(self, index, variables=None):

url = url.replace("{" + variable_name + "}", used_value)

return url
return url