Skip to content

Commit 8faad9e

Browse files
committed
feat: add support for custom authorization header names
Signed-off-by: Kosea Kalema <koseakalema2@gmail.com>
1 parent 3762c1d commit 8faad9e

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

kubernetes/client/configuration.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,29 @@ def __init__(self, host="http://localhost",
161161
self.proxy = None
162162
"""Proxy URL
163163
"""
164-
self.no_proxy = None
165-
# Load proxy from environment variables (if set)
164+
self.authorization_header = "Authorization"
165+
"""Custom authorization header name (default: "Authorization")"""
166+
self.no_proxy = []
167+
# Load proxy from environment variables (if set)
166168
if os.getenv("HTTPS_PROXY"): self.proxy = os.getenv("HTTPS_PROXY")
167169
if os.getenv("https_proxy"): self.proxy = os.getenv("https_proxy")
168170
if os.getenv("HTTP_PROXY"): self.proxy = os.getenv("HTTP_PROXY")
169171
if os.getenv("http_proxy"): self.proxy = os.getenv("http_proxy")
170-
# Load no_proxy from environment variables (if set)
171-
if os.getenv("NO_PROXY"): self.no_proxy = os.getenv("NO_PROXY")
172-
if os.getenv("no_proxy"): self.no_proxy = os.getenv("no_proxy")
172+
# Load and parse no_proxy from environment variables
173+
# Check for uppercase NO_PROXY first (should take precedence)
174+
no_proxy_env = None
175+
# Check if NO_PROXY exists in environment (even if empty)
176+
if "NO_PROXY" in os.environ:
177+
no_proxy_env = os.getenv("NO_PROXY")
178+
elif "no_proxy" in os.environ:
179+
no_proxy_env = os.getenv("no_proxy")
180+
181+
if no_proxy_env is not None and no_proxy_env != "":
182+
self.no_proxy = [
183+
domain.strip()
184+
for domain in no_proxy_env.split(",")
185+
if domain.strip()
186+
]
173187
"""bypass proxy for host in the no_proxy list.
174188
"""
175189
self.proxy_headers = None
@@ -345,12 +359,22 @@ def auth_settings(self):
345359
:return: The Auth Settings information dict.
346360
"""
347361
auth = {}
348-
if 'authorization' in self.api_key:
362+
# Check for the configured authorization header name in api_key (case-insensitive)
363+
header_name_lower = self.authorization_header.lower()
364+
365+
# Find the actual key in api_key that matches case-insensitively
366+
actual_key = None
367+
for key in self.api_key:
368+
if key.lower() == header_name_lower:
369+
actual_key = key
370+
break
371+
372+
if actual_key is not None:
349373
auth['BearerToken'] = {
350374
'type': 'api_key',
351375
'in': 'header',
352-
'key': 'authorization',
353-
'value': self.get_api_key_with_prefix('authorization')
376+
'key': self.authorization_header, # Use the configured case
377+
'value': self.get_api_key_with_prefix(actual_key) # Use the actual key from api_key
354378
}
355379
return auth
356380

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

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

414-
return url
438+
return url

0 commit comments

Comments
 (0)