Skip to content

Commit 1c3c05c

Browse files
committed
refactor: Update SSH key retrieval process and improve documentation for KeyVault integration
1 parent 5d89a0f commit 1c3c05c

2 files changed

Lines changed: 4 additions & 14 deletions

File tree

src/agents/plugins/workspace.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ def get_system_configuration(self, workspace_id: Annotated[str, "Workspace name/
238238
"sources": [],
239239
}
240240

241-
# Read sap-parameters.yaml
242241
sap_params = self.store.read_file(workspace_id, "sap-parameters.yaml")
243242
if sap_params:
244243
try:
@@ -261,12 +260,10 @@ def get_system_configuration(self, workspace_id: Annotated[str, "Workspace name/
261260
except Exception:
262261
result["sources"].append({"file": "sap-parameters.yaml", "error": "parse_error"})
263262

264-
# Read hosts.yaml
265263
hosts_raw = self.store.read_file(workspace_id, "hosts.yaml")
266264
if hosts_raw:
267265
try:
268266
hosts_parsed = yaml.safe_load(hosts_raw)
269-
# Expecting host groups or list
270267
result["hosts"] = hosts_parsed if hosts_parsed else []
271268
result["sources"].append(
272269
{
@@ -373,7 +370,7 @@ def resolve_ssh_key(self, workspace_id: Annotated[str, "Workspace name/ID"]) ->
373370
for filename in files:
374371
filename_lower = filename.lower()
375372
if any(pattern in filename_lower for pattern in key_patterns):
376-
if not filename.endswith(".pub"): # Skip public keys
373+
if not filename.endswith(".pub"):
377374
key_path = workspace_path / filename
378375
if key_path.exists():
379376
logger.info(f"Resolved SSH key: {key_path}")
@@ -482,27 +479,19 @@ def get_execution_context(self, workspace_id: Annotated[str, "Workspace name/ID"
482479
if not result["ssh_key_path"] and self.keyvault_plugin:
483480
secret_id = result["sap_parameters"].get("secret_id", "")
484481
if secret_id:
485-
logger.info(
486-
f"No local SSH key found, attempting to fetch from Key Vault "
487-
f"using secret_id: {secret_id}"
488-
)
489482
try:
490483
parse_result = json.loads(
491484
self.keyvault_plugin.parse_key_vault_id_and_secret_id(secret_id)
492485
)
493486
if "error" not in parse_result:
494487
vault_name = parse_result.get("vault_name")
495488
secret_name = parse_result.get("secret_name")
496-
managed_identity_client_id = result["sap_parameters"].get(
497-
"user_assigned_identity_client_id", ""
498-
)
499489
if vault_name and secret_name:
500490
key_result = json.loads(
501491
self.keyvault_plugin.get_ssh_private_key(
502492
secret_name=secret_name,
503493
vault_name=vault_name,
504494
key_filename=f"{workspace_id}_id_rsa",
505-
managed_identity_client_id=managed_identity_client_id,
506495
)
507496
)
508497
if "key_path" in key_result:

src/agents/prompts.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@
328328
329329
EXECUTION TOOLS:
330330
- get_execution_context: Get ALL workspace context in ONE call (inventory, parameters, SSH key)
331-
- get_ssh_key_for_workspace: Fetch SSH key from Azure KeyVault when missing locally
331+
- parse_key_vault_id_and_secret_id: Parse KeyVault URL to extract vault_name and secret_name
332+
- get_ssh_private_key: Fetch SSH key from Azure KeyVault (requires vault_name, secret_name)
332333
- run_test_by_id: Run tests (auto-resolves SSH key and parameters)
333334
- run_readonly_command: Run diagnostic commands on SAP VMs (auto-resolves SSH key)
334335
- tail_log: Tail logs
@@ -489,7 +490,7 @@
489490
490491
ERROR HANDLING:
491492
- Host unreachable: "Can't reach the host. Check if it's running and network is accessible."
492-
- SSH key missing: Check sap-parameters.yaml for kv_name. If present, call get_ssh_key_for_workspace(). If no KeyVault, ask user for key path.
493+
- SSH key missing: Read sap-parameters.yaml, find secret_id URL, parse with parse_key_vault_id_and_secret_id(), then call get_ssh_private_key(secret_name, vault_name).
493494
- Test not found: "That test doesn't exist. Available tests: [list]"
494495
- Keep errors user-friendly
495496

0 commit comments

Comments
 (0)