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

Method execute

keepercommander/commands/record_edit.py:960–1151  ·  view source on GitHub ↗
(self, params, **kwargs)

Source from the content-addressed store, hash-verified

958 return record_add_parser
959
960 def execute(self, params, **kwargs):
961 if kwargs.get('syntax_help') is True:
962 print(record_fields_description)
963 return
964
965 # Validate email parameters
966 send_email = kwargs.get('send_email')
967 if send_email:
968 if not kwargs.get('email_config'):
969 raise CommandError('record-add', '--send-email requires --email-config to specify email configuration')
970
971 # Validate email provider dependencies early (before creating record)
972 try:
973 from .email_commands import find_email_config_record, load_email_config_from_record
974 from ..email_service import validate_email_provider_dependencies
975
976 email_config_name = kwargs.get('email_config')
977 config_uid = find_email_config_record(params, email_config_name)
978 if not config_uid:
979 raise CommandError('record-add', f'Email configuration "{email_config_name}" not found')
980 email_config_obj = load_email_config_from_record(params, config_uid)
981
982 # Check if required dependencies are installed for this provider
983 is_valid, error_message = validate_email_provider_dependencies(email_config_obj.provider)
984
985 if not is_valid:
986 raise CommandError('record-add', f'\n{error_message}')
987
988 except Exception as e:
989 # Re-raise CommandError as-is, wrap other exceptions
990 if isinstance(e, CommandError):
991 raise
992 raise CommandError('record-add', f'Failed to validate email configuration: {e}')
993
994 # Handle share link creation
995 # If --send-email is used without --self-destruct, create a 24h time-based expiration (not self-destruct)
996 expiration_period = None
997 self_destruct = kwargs.get('self_destruct')
998 is_self_destruct_link = False # Track whether to enable self-destruct on first use
999
1000 if self_destruct:
1001 expiration_period = parse_timeout(self_destruct)
1002 if expiration_period.total_seconds() > 182 * 24 * 60 * 60:
1003 raise CommandError('', 'URL expiration period cannot be greater than 6 months.')
1004 is_self_destruct_link = True # User explicitly requested self-destruct
1005 elif send_email:
1006 # Auto-create share link with 24-hour time-based expiration (without self-destruct)
1007 expiration_period = parse_timeout('24h')
1008 self_destruct = '24h' # For email template text
1009 is_self_destruct_link = False # Time-based only, can be used multiple times
1010 logging.info('--send-email used without --self-destruct, creating 24 hour time-based share link')
1011
1012 folder_name = kwargs.get('folder')
1013 folder_uid = FolderMixin.resolve_folder(params, folder_name)
1014 if folder_name and not folder_uid:
1015 raise CommandError('record-add', f'Folder "{folder_name}" cannot be found')
1016
1017 self.warnings.clear()

Callers

nothing calls this directly

Calls 15

_sync_password_to_pamMethod · 0.95
_format_add_resultMethod · 0.95
find_email_config_recordFunction · 0.85
parse_timeoutFunction · 0.85
resolve_folderMethod · 0.80
enforceMethod · 0.80
reset_password_policyMethod · 0.80
parse_fieldMethod · 0.80

Tested by

no test coverage detected