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

Method execute

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

Source from the content-addressed store, hash-verified

1614 return search_parser
1615
1616 def execute(self, params, **kwargs):
1617 pattern_args = kwargs.get('pattern') or []
1618 # Join multiple words into a single pattern string
1619 pattern = ' '.join(pattern_args) if isinstance(pattern_args, list) else (pattern_args or '')
1620 use_regex = kwargs.get('regex', False)
1621 device_mode = kwargs.get('device', False)
1622 fmt = kwargs.get('format', 'table')
1623 verbose = kwargs.get('verbose') is True
1624
1625 if device_mode:
1626 if use_regex:
1627 raise CommandError('search', '--regex is not supported with --device (pattern is UID or controllerName)')
1628 if kwargs.get('categories'):
1629 raise CommandError('search', '--categories is not supported with --device (only PAM Configs apply)')
1630 if not pattern:
1631 raise CommandError('search', '--device requires a pattern: gateway UID or controllerName substring (use "*" for all)')
1632 return self._execute_device_search(params, pattern, verbose, fmt)
1633
1634 # Handle wildcard: '*' means match all
1635 if pattern == '*':
1636 if use_regex:
1637 pattern = '.*'
1638 else:
1639 pattern = '' # Empty pattern matches all in token mode
1640
1641 categories = ''.join(kwargs.get('categories') or ['rstd']).lower()
1642 skip_details = not verbose
1643
1644 nsf_records_map = getattr(params, 'nested_share_records', {}) or {}
1645
1646 all_results = []
1647
1648 if 'r' in categories:
1649
1650 records = list(vault_extensions.find_records(params, pattern, record_version=None if verbose else [2,3], use_regex=use_regex))
1651 if records:
1652 if fmt == 'json':
1653 for record in records:
1654 is_nsf = record.record_uid in nsf_records_map
1655 result_item = {
1656 'type': 'record',
1657 'record_uid': record.record_uid,
1658 'record_type': record.record_type,
1659 'title': record.title,
1660 'description': vault_extensions.get_record_description(record),
1661 'record_category': 'nested' if is_nsf else 'classic',
1662 }
1663 all_results.append(result_item)
1664 else:
1665 logging.info('')
1666 table = []
1667 headers = ['Record UID', 'Type', 'Title', 'Description', 'Record Category']
1668 for record in records:
1669 record_category = 'nested' if record.record_uid in nsf_records_map else 'classic'
1670 row = [record.record_uid, record.record_type, record.title,
1671 vault_extensions.get_record_description(record), record_category]
1672 table.append(row)
1673 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
CommandErrorClass · 0.70
getMethod · 0.45
infoMethod · 0.45

Tested by 1

test_search_commandMethod · 0.76