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

Method execute

keepercommander/commands/msp.py:459–610  ·  view source on GitHub ↗
(self, params, **kwargs)

Source from the content-addressed store, hash-verified

457 return msp_update_parser
458
459 def execute(self, params, **kwargs):
460 managed_companies = params.enterprise['managed_companies']
461 mc_input = kwargs.get('mc')
462 current_mc = get_mc_by_name_or_id(managed_companies, mc_input)
463 if not current_mc:
464 raise CommandError('msp-remove', f'Managed Company \"{mc_input}\" not found')
465
466 rq = {
467 'command': 'enterprise_update_by_msp',
468 'enterprise_id': current_mc['mc_enterprise_id'],
469 'enterprise_name': current_mc['mc_enterprise_name'],
470 'product_id': current_mc['product_id'],
471 'seats': current_mc['number_of_seats'],
472 }
473
474 node_name = kwargs.get('node')
475 if node_name:
476 nodes = list(self.resolve_nodes(params, node_name))
477 if len(nodes) == 0:
478 raise CommandError('msp-update', f'Node \"{node_name}\" is not found')
479 if len(nodes) > 1:
480 raise CommandError('msp-update', f'More than one nodes \"{node_name}\" are found')
481 rq['node_id'] = nodes[0]['node_id']
482
483 new_name = kwargs.get('name')
484 if new_name:
485 rq['enterprise_name'] = new_name
486
487 permits = next((x['msp_permits'] for x in params.enterprise.get('licenses', []) if 'msp_permits' in x), None)
488
489 plan_name = kwargs.get('plan')
490 if plan_name:
491 plan_name = plan_name.lower()
492 product_plan = next((x for x in constants.MSP_PLANS if x[1].lower() == plan_name), None)
493 if not product_plan:
494 raise CommandError('msp-update', f'Managed Company plan \"{plan_name}\" is not found')
495 if permits:
496 has_plan = any((True for x in permits['allowed_mc_products'] if x.lower() == plan_name))
497 if not has_plan:
498 raise CommandError('msp-update', f'Managed Company plan \"{plan_name}\" is not allowed')
499 rq['product_id'] = product_plan[1]
500
501 seats = kwargs.get('seats')
502 if isinstance(seats, int):
503 if seats < 0 and permits:
504 if permits['allow_unlimited_licenses'] is False:
505 raise CommandError('msp-update', 'Managed Company unlimited licences are not allowed')
506 rq['seats'] = seats if seats >= 0 else 2147483647
507
508 plan_name = kwargs.get('file_plan')
509 if plan_name:
510 plan_name = plan_name.lower()
511 file_plan = next((x for x in constants.MSP_FILE_PLANS if plan_name in (y.lower() for y in x if isinstance(y, str))), None)
512 if not file_plan:
513 raise CommandError('msp-update', f'File plan \"{plan_name}\" is not found')
514 if permits:
515 allowed_file_plan_name = permits['max_file_plan_type'].lower()
516 if allowed_file_plan_name:

Callers

nothing calls this directly

Calls 8

get_mc_by_name_or_idFunction · 0.85
findFunction · 0.85
resolve_nodesMethod · 0.80
communicateMethod · 0.80
CommandErrorClass · 0.70
getMethod · 0.45
infoMethod · 0.45
query_enterpriseMethod · 0.45

Tested by

no test coverage detected