| 1699 | return False |
| 1700 | |
| 1701 | def execute(self, params, **kwargs): |
| 1702 | from ..constants import KEEPER_SERVERS, get_abbrev_by_host |
| 1703 | |
| 1704 | if msp.current_mc_id: |
| 1705 | msp.current_mc_id = None |
| 1706 | msp.mc_params_dict.clear() |
| 1707 | |
| 1708 | # Handle --server option to change data center |
| 1709 | server = kwargs.get('server') |
| 1710 | if server: |
| 1711 | server_upper = server.upper().replace('-', '_') |
| 1712 | if server_upper in KEEPER_SERVERS: |
| 1713 | params.server = KEEPER_SERVERS[server_upper] |
| 1714 | logging.info(f'Data center set to {server_upper}') |
| 1715 | else: |
| 1716 | logging.warning(f'Unknown server region: {server}. Using default.') |
| 1717 | |
| 1718 | user = kwargs.get('email') or '' |
| 1719 | password = kwargs.get('password') or '' |
| 1720 | |
| 1721 | try: |
| 1722 | if not user: |
| 1723 | # Show current data center before prompting for email |
| 1724 | region = get_abbrev_by_host(params.server) if params.server else 'US' |
| 1725 | if not region: |
| 1726 | # Check extended server list |
| 1727 | region = next((k for k, v in KEEPER_SERVERS.items() if v == params.server), params.server) |
| 1728 | print(f'{Fore.CYAN}Data center: {Fore.WHITE}{region}{Fore.RESET}', file=sys.stderr) |
| 1729 | hint_cmd = 'keeper login --server <region>' if params.batch_mode else 'login --server <region>' |
| 1730 | print(f'{Fore.CYAN}Use {Fore.GREEN}{hint_cmd}{Fore.CYAN} to change (US, EU, AU, CA, JP, GOV){Fore.RESET}', file=sys.stderr) |
| 1731 | print('', file=sys.stderr) |
| 1732 | user = input(f'{Fore.GREEN}Email: {Fore.RESET}').strip() |
| 1733 | if not user: |
| 1734 | return |
| 1735 | except KeyboardInterrupt as e: |
| 1736 | logging.info('Canceled') |
| 1737 | return |
| 1738 | |
| 1739 | params.user = user.lower() |
| 1740 | if not password and isinstance(params.config, dict): |
| 1741 | if 'user' in params.config and 'password' in params.config: |
| 1742 | if params.config['user'] == params.user: |
| 1743 | password = params.config['password'] |
| 1744 | |
| 1745 | params.password = password |
| 1746 | new_login = kwargs.get('new_login') is True |
| 1747 | skip_sync = kwargs.get('skip_sync') is True |
| 1748 | |
| 1749 | # Apply storage backend choice before login so that store_config_properties |
| 1750 | # (called inside api.login) honours the user's explicit preference. |
| 1751 | # Mirrors KSM CLI's use_config_file / use_keyring logic in Profile.init(). |
| 1752 | import platform as _platform |
| 1753 | from ..config_storage.loader import ( |
| 1754 | CONFIG_STORAGE_URL, OS_KEYCHAIN_URL, is_os_keychain_available, _is_os_keychain_url |
| 1755 | ) |
| 1756 | |
| 1757 | use_config_file = ( |
| 1758 | kwargs.get('config_file') is True |