@@ -242,14 +242,14 @@ def _aks_bastion_get_current_shell_cmd():
242242 parent = psutil .Process (ppid )
243243 parent_name = parent .name ()
244244 logger .debug (f"Immediate parent process: { parent_name } (PID: { ppid } )" )
245-
246- # On Windows, Azure CLI is often invoked as az.cmd, which means the immediate parent
245+
246+ # On Windows, Azure CLI is often invoked as az.cmd, which means the immediate parent
247247 # is cmd.exe but the actual user shell (PowerShell) is the grandparent process
248248 if sys .platform .startswith ("win" ):
249249 try :
250250 parent_exe = parent .exe ()
251251 logger .debug (f"Parent executable path: { parent_exe } " )
252-
252+
253253 # If the immediate parent is cmd.exe, check if it's wrapping az.cmd for PowerShell
254254 if "cmd" in parent_name .lower ():
255255 try :
@@ -258,7 +258,7 @@ def _aks_bastion_get_current_shell_cmd():
258258 if grandparent :
259259 grandparent_name = grandparent .name ()
260260 logger .debug (f"Detected grandparent process: { grandparent_name } (PID: { grandparent .pid } )" )
261-
261+
262262 # If grandparent is PowerShell, that's the actual user shell
263263 if "pwsh" in grandparent_name .lower () or "powershell" in grandparent_name .lower ():
264264 logger .debug ("Grandparent is PowerShell - using PowerShell as target shell" )
@@ -282,7 +282,7 @@ def _aks_bastion_get_current_shell_cmd():
282282 # If we can't access grandparent, assume cmd is the actual shell
283283 logger .debug (f"Cannot access grandparent process: { e } - using cmd as target shell" )
284284 return "cmd"
285-
285+
286286 # For direct PowerShell processes (not wrapped by cmd), prefer pwsh over powershell.exe
287287 elif "pwsh" in parent_name .lower () or "powershell" in parent_name .lower ():
288288 logger .debug ("Direct PowerShell parent detected" )
@@ -304,7 +304,7 @@ def _aks_bastion_get_current_shell_cmd():
304304 except (psutil .NoSuchProcess , psutil .AccessDenied ) as e :
305305 logger .debug (f"Cannot access parent process details: { e } " )
306306 pass
307-
307+
308308 logger .debug (f"Using parent process name as shell: { parent_name } " )
309309 return parent_name
310310
@@ -314,7 +314,7 @@ def _aks_bastion_prepare_shell_cmd(kubeconfig_path):
314314
315315 shell_cmd = _aks_bastion_get_current_shell_cmd ()
316316 updated_shell_cmd = shell_cmd
317-
317+
318318 # Handle different shell types
319319 if shell_cmd .endswith ("bash" ) and os .path .exists (os .path .expanduser ("~/.bashrc" )):
320320 updated_shell_cmd = (
@@ -332,7 +332,7 @@ def _aks_bastion_prepare_shell_cmd(kubeconfig_path):
332332 elif shell_cmd == "cmd" or "cmd" in shell_cmd .lower ():
333333 # CMD: Set environment variable and keep session open
334334 updated_shell_cmd = f'cmd /k "set KUBECONFIG={ kubeconfig_path } "'
335-
335+
336336 return shell_cmd , updated_shell_cmd
337337
338338
0 commit comments