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

Class ThisDeviceCommand

keepercommander/commands/utils.py:522–795  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

520
521
522class ThisDeviceCommand(Command):
523
524 def get_parser(self):
525 return this_device_parser
526
527 def execute(self, params, **kwargs):
528
529 ops = kwargs.get('ops')
530 output_format = kwargs.get('format', 'text')
531 if len(ops) == 0:
532 return ThisDeviceCommand.print_device_info(params, output_format=output_format)
533
534
535 action = ops[0].lower() if ops else ''
536
537 # Check for valid sub-commands that need a value
538 if len(ops) == 1 and action != 'register':
539 if action in ('timeout', 'to'):
540 logging.error(f"Usage: this-device timeout <duration> (e.g., 10m, 1h, 7d, 30d)")
541 elif action == '2fa_expiration':
542 logging.error(f"Usage: this-device 2fa_expiration <duration> (e.g., login, 12h, 24h, 30d, forever)")
543 elif action in ('persistent_login', 'persistent-login', 'pl'):
544 logging.error(f"Usage: this-device persistent-login <on|off>")
545 elif action in ('ip_auto_approve', 'ip-auto-approve', 'iaa'):
546 logging.error(f"Usage: this-device ip-auto-approve <on|off>")
547 elif action == 'no-yubikey-pin':
548 logging.error(f"Usage: this-device no-yubikey-pin <on|off>")
549 elif action in ('rename', 'ren'):
550 logging.error(f"Usage: this-device rename <name>")
551 else:
552 logging.error(f"Unknown sub-command: {action}")
553 logging.error(f"Run {Fore.GREEN}this-device -h{Fore.RESET} for detailed help.")
554 return
555
556 if len(ops) >= 1 and action != 'register' and len(ops) != 2:
557 logging.error(f"Invalid arguments. Run {Fore.GREEN}this-device -h{Fore.RESET} for help.")
558 return
559
560 def register_device():
561 is_device_registered = loginv3.LoginV3API.register_encrypted_data_key_for_device(params)
562
563 if is_device_registered:
564 logging.info(bcolors.OKGREEN + "Successfully registered device" + bcolors.ENDC)
565 else:
566 logging.info(bcolors.OKGREEN + "Device already registered" + bcolors.ENDC)
567
568 if action == 'rename' or action == 'ren':
569 value = ops[1]
570 loginv3.LoginV3API.rename_device(params, value)
571 logging.info(bcolors.OKGREEN + "Successfully renamed device to '" + value + "'" + bcolors.ENDC)
572
573 elif action == 'register':
574 register_device()
575
576 elif action == 'persistent_login' or action == 'persistent-login' or action == 'pl':
577 if ThisDeviceCommand.is_persistent_login_disabled(params):
578 logging.warning('"Stay Logged In" feature is restricted by Keeper Administrator')
579 return

Callers 2

register_commandsFunction · 0.85
_setup_deviceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected