Skip to content

Commit a06ec4c

Browse files
committed
refactor: Simplify get_ssh_private_key parameters and improve documentation; remove unused SSH key retrieval logic in WorkspacePlugin
1 parent c274363 commit a06ec4c

2 files changed

Lines changed: 6 additions & 57 deletions

File tree

src/agents/plugins/keyvault.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -172,27 +172,14 @@ def parse_key_vault_id_and_secret_id(
172172
@kernel_function(
173173
name="get_ssh_private_key",
174174
description="Retrieve SSH private key from Azure Key Vault. "
175-
+ "IMPORTANT: Read sap-parameters.yaml first to get vault_name (from secret_id), "
176-
+ "secret_name, and user_assigned_identity_client_id (pass as managed_identity_client_id).",
175+
+ "Read sap-parameters.yaml first to get secret_id and user_assigned_identity_client_id.",
177176
)
178177
def get_ssh_private_key(
179178
self,
180-
secret_name: Annotated[
181-
str,
182-
"Name of the SSH key secret in Key Vault (e.g., 'sshkey', 'deployer-ssh-key')",
183-
],
184-
vault_name: Annotated[
185-
str,
186-
"Name of the Azure Key Vault (parse from secret_id in sap-parameters.yaml)",
187-
] = "",
188-
key_filename: Annotated[
189-
str,
190-
"Filename for the temporary key file (default: 'id_rsa')",
191-
] = "id_rsa",
192-
managed_identity_client_id: Annotated[
193-
str,
194-
"Client ID from user_assigned_identity_client_id in sap-parameters.yaml",
195-
] = "",
179+
secret_name: Annotated[str, "Name of the SSH key secret in Key Vault"],
180+
vault_name: Annotated[str, "Name of the Azure Key Vault"],
181+
key_filename: Annotated[str, "Filename for the temporary key file"] = "id_rsa",
182+
managed_identity_client_id: Annotated[str, "Client ID from sap-parameters.yaml"] = "",
196183
) -> Annotated[str, "JSON string with key file path or error"]:
197184
"""Retrieve SSH private key and save to temporary file.
198185
@@ -223,10 +210,8 @@ def get_ssh_private_key(
223210
Example output (error):
224211
{"error": "Failed to retrieve SSH key", "secret_name": "sshkey"}
225212
"""
213+
effective_identity = managed_identity_client_id.strip() if managed_identity_client_id else None
226214
effective_vault = vault_name.strip() if vault_name else None
227-
effective_identity = (
228-
managed_identity_client_id.strip() if managed_identity_client_id else None
229-
)
230215

231216
if not effective_vault:
232217
error_msg = "No Key Vault specified. Provide vault_name."

src/agents/plugins/workspace.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -478,42 +478,6 @@ def get_execution_context(self, workspace_id: Annotated[str, "Workspace name/ID"
478478
logger.info(f"Resolved SSH key from KeyVault temp: {temp_key_path}")
479479
break
480480

481-
if not result["ssh_key_path"] and self.keyvault_plugin:
482-
secret_id = result["sap_parameters"].get("secret_id", "")
483-
if secret_id:
484-
try:
485-
parse_result = json.loads(
486-
self.keyvault_plugin.parse_key_vault_id_and_secret_id(secret_id)
487-
)
488-
if "error" not in parse_result:
489-
vault_name = parse_result.get("vault_name")
490-
secret_name = parse_result.get("secret_name")
491-
if vault_name and secret_name:
492-
key_result = json.loads(
493-
self.keyvault_plugin.get_ssh_private_key(
494-
secret_name=secret_name,
495-
vault_name=vault_name,
496-
key_filename=f"{workspace_id}_id_rsa",
497-
)
498-
)
499-
if "key_path" in key_result:
500-
result["ssh_key_path"] = key_result["key_path"]
501-
result["ssh_key_file"] = f"{workspace_id}_id_rsa"
502-
result["ssh_key_source"] = "keyvault"
503-
logger.info(
504-
f"Successfully fetched SSH key from Key Vault: "
505-
f"{key_result['key_path']}"
506-
)
507-
else:
508-
logger.warning(
509-
f"Failed to fetch SSH key from Key Vault: "
510-
f"{key_result.get('error', 'Unknown error')}"
511-
)
512-
else:
513-
logger.warning(f"Failed to parse secret_id: {parse_result.get('error')}")
514-
except Exception as e:
515-
logger.error(f"Error fetching SSH key from Key Vault: {e}")
516-
517481
if not result["ssh_key_path"]:
518482
result["missing"].append("ssh_key")
519483
result["ready"] = (

0 commit comments

Comments
 (0)