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

Method execute

keepercommander/commands/utils.py:543–652  ·  view source on GitHub ↗
(self, params, **kwargs)

Source from the content-addressed store, hash-verified

541 return this_device_parser
542
543 def execute(self, params, **kwargs):
544
545 ops = kwargs.get('ops')
546 output_format = kwargs.get('format', 'text')
547 if len(ops) == 0:
548 return ThisDeviceCommand.print_device_info(params, output_format=output_format)
549
550
551 action = ops[0].lower() if ops else ''
552
553 # Check for valid sub-commands that need a value
554 if len(ops) == 1 and action != 'register':
555 if action in ('timeout', 'to'):
556 logging.error(f"Usage: this-device timeout <duration> (e.g., 10m, 1h, 7d, 30d)")
557 elif action == '2fa_expiration':
558 logging.error(f"Usage: this-device 2fa_expiration <duration> (e.g., login, 12h, 24h, 30d, forever)")
559 elif action in ('persistent_login', 'persistent-login', 'pl'):
560 logging.error(f"Usage: this-device persistent-login <on|off>")
561 elif action in ('ip_auto_approve', 'ip-auto-approve', 'iaa'):
562 logging.error(f"Usage: this-device ip-auto-approve <on|off>")
563 elif action == 'no-yubikey-pin':
564 logging.error(f"Usage: this-device no-yubikey-pin <on|off>")
565 elif action in ('rename', 'ren'):
566 logging.error(f"Usage: this-device rename <name>")
567 else:
568 logging.error(f"Unknown sub-command: {action}")
569 logging.error(f"Run {Fore.GREEN}this-device -h{Fore.RESET} for detailed help.")
570 return
571
572 if len(ops) >= 1 and action != 'register' and len(ops) != 2:
573 logging.error(f"Invalid arguments. Run {Fore.GREEN}this-device -h{Fore.RESET} for help.")
574 return
575
576 def register_device():
577 is_device_registered = loginv3.LoginV3API.register_encrypted_data_key_for_device(params)
578
579 if is_device_registered:
580 logging.info(bcolors.OKGREEN + "Successfully registered device" + bcolors.ENDC)
581 else:
582 logging.info(bcolors.OKGREEN + "Device already registered" + bcolors.ENDC)
583
584 if action == 'rename' or action == 'ren':
585 value = ops[1]
586 loginv3.LoginV3API.rename_device(params, value)
587 logging.info(bcolors.OKGREEN + "Successfully renamed device to '" + value + "'" + bcolors.ENDC)
588
589 elif action == 'register':
590 register_device()
591
592 elif action == 'persistent_login' or action == 'persistent-login' or action == 'pl':
593 if ThisDeviceCommand.is_persistent_login_disabled(params):
594 logging.warning('"Stay Logged In" feature is restricted by Keeper Administrator')
595 return
596
597 value = ops[1]
598
599 value_extracted = ThisDeviceCommand.get_setting_str_to_value('persistent_login', value)
600 loginv3.LoginV3API.set_user_setting(params, 'persistent_login', value_extracted)

Callers

nothing calls this directly

Calls 14

enforce_timeout_rangeFunction · 0.85
format_timeoutFunction · 0.85
print_device_infoMethod · 0.80
rename_deviceMethod · 0.80
warningMethod · 0.80
set_user_settingMethod · 0.80
CommandErrorClass · 0.70
getMethod · 0.45

Tested by

no test coverage detected