Skip to content

Commit a5b277d

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent bcf9cdf commit a5b277d

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

docs/source/users/kernel-envs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ There are several supported `KERNEL_` variables that the Enterprise Gateway serv
8080
(e.g "{{ kernel_prefix }}-{{ kernel_id | replace('-', '') }}")
8181
which will be processed for safe substitution against existing list
8282
of environment variables. In case of invalid template (e.g. missing variables)
83-
it will fall back to original way to calculate the pod name using
83+
it will fall back to original way to calculate the pod name using
8484
KERNEL_USERNAME - KERNEL_ID.
8585
8686
KERNEL_REMOTE_HOST=<remote host name>

enterprise_gateway/services/processproxies/k8s.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ def replace_var(match):
240240
# Check if there are any remaining {{ }} patterns that didn't match our simple pattern
241241
# This catches malicious templates like {{ foo.__class__ }} or {{ 1+1 }}
242242
if '{{' in result and '}}' in result:
243-
self.log.warning(f"Invalid template syntax detected in KERNEL_POD_NAME: contains unsupported expressions")
243+
self.log.warning(
244+
"Invalid template syntax detected in KERNEL_POD_NAME: contains unsupported expressions"
245+
)
244246
return None
245247

246248
# Log missing variables and return None if any are missing

enterprise_gateway/tests/test_process_proxy.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from unittest.mock import Mock, patch
77

88
# Mock Kubernetes configuration before importing the module
9-
with patch('kubernetes.config.load_incluster_config'), \
10-
patch('kubernetes.config.load_kube_config'):
9+
with patch('kubernetes.config.load_incluster_config'), patch('kubernetes.config.load_kube_config'):
1110
from enterprise_gateway.services.processproxies.k8s import KubernetesProcessProxy
1211

1312

@@ -19,15 +18,14 @@ def setUp(self):
1918
self.mock_kernel_manager = Mock()
2019
self.mock_kernel_manager.get_kernel_username.return_value = "testuser"
2120
self.mock_kernel_manager.port_range = "0..0" # Mock port range
22-
21+
2322
# Mock proxy config
24-
self.proxy_config = {
25-
"kernel_id": "test-kernel-id",
26-
"kernel_name": "python3"
27-
}
23+
self.proxy_config = {"kernel_id": "test-kernel-id", "kernel_name": "python3"}
2824

2925
# Mock KernelSessionManager methods
30-
with patch('enterprise_gateway.services.processproxies.k8s.KernelSessionManager') as mock_session_manager:
26+
with patch(
27+
'enterprise_gateway.services.processproxies.k8s.KernelSessionManager'
28+
) as mock_session_manager:
3129
mock_session_manager.get_kernel_username.return_value = "testuser"
3230
self.proxy = KubernetesProcessProxy(self.mock_kernel_manager, self.proxy_config)
3331
self.proxy.kernel_id = "test-kernel-id"
@@ -54,7 +52,7 @@ def test_valid_template_substitution(self):
5452
result = self.proxy._safe_template_substitute(template, variables)
5553
self.assertEqual(result, expected)
5654

57-
def test_missing_variables_fallback(self):
55+
def test_missing_variables_fallback(self):
5856
# Test the full pod name determination process
5957
kwargs = {
6058
"env": {
@@ -63,8 +61,9 @@ def test_missing_variables_fallback(self):
6361
}
6462
}
6563

66-
with patch.object(self.proxy, 'log'), \
67-
patch('enterprise_gateway.services.processproxies.k8s.KernelSessionManager') as mock_session_manager:
64+
with patch.object(self.proxy, 'log'), patch(
65+
'enterprise_gateway.services.processproxies.k8s.KernelSessionManager'
66+
) as mock_session_manager:
6867
mock_session_manager.get_kernel_username.return_value = "testuser"
6968
result = self.proxy._determine_kernel_pod_name(**kwargs)
7069
# Should fall back to default naming: kernel_username + "-" + kernel_id
@@ -132,8 +131,9 @@ def test_pod_name_determination_with_malicious_template(self):
132131
}
133132
}
134133

135-
with patch.object(self.proxy, 'log'), \
136-
patch('enterprise_gateway.services.processproxies.k8s.KernelSessionManager') as mock_session_manager:
134+
with patch.object(self.proxy, 'log'), patch(
135+
'enterprise_gateway.services.processproxies.k8s.KernelSessionManager'
136+
) as mock_session_manager:
137137
mock_session_manager.get_kernel_username.return_value = "testuser"
138138
result = self.proxy._determine_kernel_pod_name(**kwargs)
139139
# Should fall back to default naming
@@ -148,8 +148,9 @@ def test_pod_name_determination_with_missing_variables(self):
148148
}
149149
}
150150

151-
with patch.object(self.proxy, 'log'), \
152-
patch('enterprise_gateway.services.processproxies.k8s.KernelSessionManager') as mock_session_manager:
151+
with patch.object(self.proxy, 'log'), patch(
152+
'enterprise_gateway.services.processproxies.k8s.KernelSessionManager'
153+
) as mock_session_manager:
153154
mock_session_manager.get_kernel_username.return_value = "testuser"
154155
result = self.proxy._determine_kernel_pod_name(**kwargs)
155156
# Should fall back to default naming

0 commit comments

Comments
 (0)