Skip to content

Commit c82c885

Browse files
committed
added debug logs
1 parent 9f64ea1 commit c82c885

2 files changed

Lines changed: 53 additions & 34 deletions

File tree

keepercommander/importer/cyberark/pam/import_builder.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,27 @@ def format_duration(seconds: float) -> str:
291291
return f"{s}s"
292292

293293

294+
def format_unmapped_section(unmapped_items: Optional[List[dict]]) -> str:
295+
"""Format the UNMAPPED manual-action section for debug logging."""
296+
if not unmapped_items:
297+
return ''
298+
lines = [
299+
' UNMAPPED — REQUIRES MANUAL ACTION',
300+
' ' + '-' * 40,
301+
]
302+
by_category = {} # type: Dict[str, List[dict]]
303+
for item in unmapped_items:
304+
cat = item.get("category", "Other")
305+
by_category.setdefault(cat, []).append(item)
306+
for cat, items in sorted(by_category.items()):
307+
lines.append(f' {cat}:')
308+
for item in items:
309+
lines.append(f' {item.get("item", "")}')
310+
lines.append(f' Action: {item.get("action", "")}')
311+
lines.append('')
312+
return "\n".join(lines)
313+
314+
294315
def build_report(project_name: str, safes_processed: int, total_accounts: int,
295316
resource_counts: Dict[str, Dict[str, int]],
296317
platform_counts: Dict[str, Dict[str, Any]],
@@ -402,20 +423,9 @@ def build_report(project_name: str, safes_processed: int, total_accounts: int,
402423
lines.append(f' Incomplete (missing fields): {incomplete_count}')
403424
lines.append('')
404425

405-
# UNMAPPED section
426+
# UNMAPPED details are debug-only (see format_unmapped_section / logging.debug)
406427
if unmapped_items:
407-
lines.append(' UNMAPPED — REQUIRES MANUAL ACTION')
408-
lines.append(' ' + '-' * 40)
409-
by_category = {} # type: Dict[str, List[dict]]
410-
for item in unmapped_items:
411-
cat = item.get("category", "Other")
412-
by_category.setdefault(cat, []).append(item)
413-
for cat, items in sorted(by_category.items()):
414-
lines.append(f' {cat}:')
415-
for item in items:
416-
lines.append(f' {item.get("item", "")}')
417-
lines.append(f' Action: {item.get("action", "")}')
418-
lines.append('')
428+
logging.debug('\n%s', format_unmapped_section(unmapped_items))
419429

420430
# Gateway deployment
421431
gw_token = ''
@@ -435,9 +445,13 @@ def build_report(project_name: str, safes_processed: int, total_accounts: int,
435445
# Next steps
436446
lines.append(' NEXT STEPS')
437447
lines.append(' ' + '-' * 40)
438-
lines.append(f' 1. Review UNMAPPED section — action each item')
439-
lines.append(f' 2. Verify: pam gateway list')
440-
lines.append(f' 3. Cleanup: pam project cyberark-cleanup --name "{project_name}"')
448+
step = 1
449+
if unmapped_items:
450+
lines.append(f' {step}. Review unmapped items in debug log (--debug)')
451+
step += 1
452+
lines.append(f' {step}. Verify: pam gateway list')
453+
step += 1
454+
lines.append(f' {step}. Cleanup: pam project cyberark-cleanup --name "{project_name}"')
441455
lines.append('')
442456

443457
# Command (redacted)

tests/test_cyberark_pam_import.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,32 +2555,37 @@ def test_returns_429_after_max_retries(self, mock_dns, mock_requests, mock_sleep
25552555
class TestEnhancedReport:
25562556
"""Tests for the enhanced build_report with all sections."""
25572557

2558-
def test_report_has_all_sections(self):
2558+
def test_report_has_all_sections(self, caplog):
2559+
import logging
25592560
from keepercommander.importer.cyberark.cyberark_pam import build_report
2560-
report = build_report(
2561-
project_name="Test",
2562-
safes_processed=3,
2563-
total_accounts=50,
2564-
resource_counts={"pamMachine": {"ok": 20, "skip": 0, "err": 0},
2565-
"login": {"ok": 10, "skip": 0, "err": 0}},
2566-
platform_counts={"UnixSSH": {"rotation": "general", "count": 20}},
2567-
skipped=[{"reason": "password retrieval failed"}],
2568-
incomplete_count=2,
2569-
duration=120.0,
2570-
unmapped_items=[{"category": "Master Policy",
2571-
"item": "Dual control = Active",
2572-
"action": "Use ticketing"}],
2573-
server="pvwa.example.com",
2574-
)
2561+
with caplog.at_level(logging.DEBUG):
2562+
report = build_report(
2563+
project_name="Test",
2564+
safes_processed=3,
2565+
total_accounts=50,
2566+
resource_counts={"pamMachine": {"ok": 20, "skip": 0, "err": 0},
2567+
"login": {"ok": 10, "skip": 0, "err": 0}},
2568+
platform_counts={"UnixSSH": {"rotation": "general", "count": 20}},
2569+
skipped=[{"reason": "password retrieval failed"}],
2570+
incomplete_count=2,
2571+
duration=120.0,
2572+
unmapped_items=[{"category": "Master Policy",
2573+
"item": "Dual control = Active",
2574+
"action": "Use ticketing"}],
2575+
server="pvwa.example.com",
2576+
)
25752577
assert "SOURCE SUMMARY" in report
25762578
assert "IMPORT RESULTS" in report
25772579
assert "PLATFORM MAPPING" in report
25782580
assert "SKIPPED ACCOUNTS" in report
2579-
assert "UNMAPPED" in report
2581+
assert "UNMAPPED — REQUIRES MANUAL ACTION" not in report
2582+
assert "Dual control" not in report
2583+
assert "debug log" in report
25802584
assert "NEXT STEPS" in report
25812585
assert "COMMAND" in report
25822586
assert "pvwa.example.com" in report
2583-
assert "Dual control" in report
2587+
assert "UNMAPPED — REQUIRES MANUAL ACTION" in caplog.text
2588+
assert "Dual control" in caplog.text
25842589

25852590
def test_report_gateway_token(self):
25862591
from keepercommander.importer.cyberark.cyberark_pam import build_report

0 commit comments

Comments
 (0)