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

Method execute

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

Source from the content-addressed store, hash-verified

1335 return data
1336
1337 def execute(self, params, **kwargs):
1338 json_output = kwargs.get('json_output', False)
1339 verbose = kwargs.get('verbose', False)
1340
1341 if json_output:
1342 # Collect data for JSON output
1343 data = {}
1344
1345 if params.session_token:
1346 data['logged_in'] = True
1347 hostname = get_hostname(params.rest_context.server_base)
1348 data['user'] = params.user
1349 data['server'] = hostname
1350 data['data_center'] = get_data_center(hostname)
1351
1352 environment = get_environment(hostname)
1353 if environment:
1354 data['environment'] = environment
1355
1356 if params.license:
1357 account_type = params.license['account_type'] if 'account_type' in params.license else None
1358 if account_type == 2:
1359 data['admin'] = params.enterprise is not None
1360
1361 account_type_name = 'Enterprise' if account_type == 2 \
1362 else 'Family Plan' if account_type == 1 \
1363 else params.license['product_type_name']
1364 data['account_type'] = account_type_name
1365 data['renewal_date'] = params.license['expiration_date']
1366
1367 if 'bytes_total' in params.license:
1368 storage_bytes = int(params.license['bytes_total'])
1369 storage_gb = storage_bytes >> 30
1370 storage_bytes_used = params.license['bytes_used'] if 'bytes_used' in params.license else 0
1371 data['storage_capacity'] = f'{storage_gb}GB'
1372 storage_usage = (int(storage_bytes_used) * 100 // storage_bytes) if storage_bytes != 0 else 0
1373 data['storage_usage'] = f'{storage_usage}%'
1374 data['storage_renewal_date'] = params.license['storage_expiration_date']
1375
1376 data['breachwatch'] = params.license.get('breach_watch_enabled', False)
1377 if params.enterprise:
1378 data['reporting_and_alerts'] = params.license.get('audit_and_reporting_enabled', False)
1379
1380 if verbose:
1381 data['records_count'] = len(params.record_cache)
1382 sf_count = len(params.shared_folder_cache)
1383 if sf_count > 0:
1384 data['shared_folders_count'] = sf_count
1385 team_count = len(params.team_cache)
1386 if team_count > 0:
1387 data['teams_count'] = team_count
1388
1389 if params.enterprise:
1390 enterprise_licenses = []
1391 for x in params.enterprise.get('licenses', []):
1392 license_info = {}
1393 product_type_id = x.get('product_type_id', 0)
1394 tier = x.get('tier', 0)

Callers 1

test_whoamiMethod · 0.95

Calls 4

get_hostnameFunction · 0.85
get_data_centerFunction · 0.85
get_environmentFunction · 0.85
getMethod · 0.45

Tested by 1

test_whoamiMethod · 0.76