| 1261 | |
| 1262 | |
| 1263 | class WhoamiCommand(Command): |
| 1264 | def get_parser(self): |
| 1265 | return whoami_parser |
| 1266 | |
| 1267 | @staticmethod |
| 1268 | def get_whoami_info(params: KeeperParams, verbose: bool = False): |
| 1269 | """Get whoami info as a dictionary (for programmatic use)""" |
| 1270 | data = {} |
| 1271 | |
| 1272 | if params.session_token: |
| 1273 | data['logged_in'] = True |
| 1274 | hostname = get_hostname(params.rest_context.server_base) |
| 1275 | data['user'] = params.user |
| 1276 | data['server'] = hostname |
| 1277 | data['data_center'] = get_data_center(hostname) |
| 1278 | |
| 1279 | environment = get_environment(hostname) |
| 1280 | if environment: |
| 1281 | data['environment'] = environment |
| 1282 | |
| 1283 | if params.license: |
| 1284 | account_type = params.license['account_type'] if 'account_type' in params.license else None |
| 1285 | if account_type == 2: |
| 1286 | data['admin'] = params.enterprise is not None |
| 1287 | |
| 1288 | account_type_name = 'Enterprise' if account_type == 2 \ |
| 1289 | else 'Family Plan' if account_type == 1 \ |
| 1290 | else params.license['product_type_name'] |
| 1291 | data['account_type'] = account_type_name |
| 1292 | data['renewal_date'] = params.license['expiration_date'] |
| 1293 | |
| 1294 | if 'bytes_total' in params.license: |
| 1295 | storage_bytes = int(params.license['bytes_total']) |
| 1296 | storage_gb = storage_bytes >> 30 |
| 1297 | storage_bytes_used = params.license['bytes_used'] if 'bytes_used' in params.license else 0 |
| 1298 | data['storage_capacity'] = f'{storage_gb}GB' |
| 1299 | storage_usage = (int(storage_bytes_used) * 100 // storage_bytes) if storage_bytes != 0 else 0 |
| 1300 | data['storage_usage'] = f'{storage_usage}%' |
| 1301 | data['storage_renewal_date'] = params.license['storage_expiration_date'] |
| 1302 | |
| 1303 | data['breachwatch'] = params.license.get('breach_watch_enabled', False) |
| 1304 | if params.enterprise: |
| 1305 | data['reporting_and_alerts'] = params.license.get('audit_and_reporting_enabled', False) |
| 1306 | |
| 1307 | if verbose: |
| 1308 | data['records_count'] = len(params.record_cache) |
| 1309 | sf_count = len(params.shared_folder_cache) |
| 1310 | if sf_count > 0: |
| 1311 | data['shared_folders_count'] = sf_count |
| 1312 | team_count = len(params.team_cache) |
| 1313 | if team_count > 0: |
| 1314 | data['teams_count'] = team_count |
| 1315 | else: |
| 1316 | data['logged_in'] = False |
| 1317 | data['message'] = 'Not logged in' |
| 1318 | |
| 1319 | return data |
| 1320 | |