MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / execute

Method execute

keepercommander/commands/record.py:1545–1703  ·  view source on GitHub ↗
(self, params, **kwargs)

Source from the content-addressed store, hash-verified

1543 return search_parser
1544
1545 def execute(self, params, **kwargs):
1546 pattern_args = kwargs.get('pattern') or []
1547 # Join multiple words into a single pattern string
1548 pattern = ' '.join(pattern_args) if isinstance(pattern_args, list) else (pattern_args or '')
1549 use_regex = kwargs.get('regex', False)
1550 device_mode = kwargs.get('device', False)
1551 fmt = kwargs.get('format', 'table')
1552 verbose = kwargs.get('verbose') is True
1553
1554 if device_mode:
1555 if use_regex:
1556 raise CommandError('search', '--regex is not supported with --device (pattern is UID or controllerName)')
1557 if kwargs.get('categories'):
1558 raise CommandError('search', '--categories is not supported with --device (only PAM Configs apply)')
1559 if not pattern:
1560 raise CommandError('search', '--device requires a pattern: gateway UID or controllerName substring (use "*" for all)')
1561 return self._execute_device_search(params, pattern, verbose, fmt)
1562
1563 # Handle wildcard: '*' means match all
1564 if pattern == '*':
1565 if use_regex:
1566 pattern = '.*'
1567 else:
1568 pattern = '' # Empty pattern matches all in token mode
1569
1570 categories = ''.join(kwargs.get('categories') or ['rstd']).lower()
1571 skip_details = not verbose
1572
1573 nsf_records_map = getattr(params, 'nested_share_records', {}) or {}
1574
1575 all_results = []
1576
1577 if 'r' in categories:
1578
1579 records = list(vault_extensions.find_records(params, pattern, record_version=None if verbose else [2,3], use_regex=use_regex))
1580 if records:
1581 if fmt == 'json':
1582 for record in records:
1583 is_nsf = record.record_uid in nsf_records_map
1584 result_item = {
1585 'type': 'record',
1586 'record_uid': record.record_uid,
1587 'record_type': record.record_type,
1588 'title': record.title,
1589 'description': vault_extensions.get_record_description(record),
1590 'record_category': 'nested' if is_nsf else 'classic',
1591 }
1592 all_results.append(result_item)
1593 else:
1594 logging.info('')
1595 table = []
1596 headers = ['Record UID', 'Type', 'Title', 'Description', 'Record Category']
1597 for record in records:
1598 record_category = 'nested' if record.record_uid in nsf_records_map else 'classic'
1599 row = [record.record_uid, record.record_type, record.title,
1600 vault_extensions.get_record_description(record), record_category]
1601 table.append(row)
1602 table.sort(key=lambda x: (x[2] or '').lower())

Callers 1

test_search_commandMethod · 0.95

Calls 8

executeMethod · 0.95
_display_parent_uidMethod · 0.95
RecordGetUidCommandClass · 0.85
getMethod · 0.80
CommandErrorClass · 0.70
infoMethod · 0.45

Tested by 1

test_search_commandMethod · 0.76