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

Method execute

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

Source from the content-addressed store, hash-verified

938 return msp_add_parser
939
940 def execute(self, params, **kwargs):
941 node_id = None
942 node_name = kwargs.get('node')
943 if node_name:
944 nodes = list(self.resolve_nodes(params, node_name))
945 if len(nodes) == 0:
946 logging.warning('Node \"%s\" is not found', node_name)
947 return
948 if len(nodes) > 1:
949 logging.warning('More than one nodes \"%s\" are found', node_name)
950 return
951 node_id = nodes[0]['node_id']
952 if node_id is None:
953 root_nodes = list(self.get_user_root_nodes(params))
954 if len(root_nodes) == 0:
955 raise CommandError('msp-create', 'No root nodes were detected. Specify --node parameter')
956 node_id = root_nodes[0]
957
958 permits = next((x['msp_permits'] for x in params.enterprise.get('licenses', []) if 'msp_permits' in x), None)
959
960 plan_name = kwargs.get('plan')
961 if not plan_name and permits:
962 allowed_products = permits['allowed_mc_products']
963 if allowed_products:
964 plan_name = allowed_products[0]
965 if not plan_name:
966 plan_name = constants.MSP_PLANS[0][1]
967 if permits:
968 has_plan = any((True for x in permits['allowed_mc_products'] if x.lower() == plan_name.lower()))
969 if not has_plan:
970 logging.warning('Managed Company plan \"%s\" is not allowed', plan_name)
971 return
972
973 plan_name = plan_name.lower()
974 product_plan = next((x for x in constants.MSP_PLANS if x[1].lower() == plan_name), None)
975 if not product_plan:
976 logging.warning('Managed Company plan \"%s\" is not found', plan_name)
977 return
978
979 seats = kwargs.get('seats')
980 if isinstance(seats, int) and seats < 0:
981 if permits:
982 if permits['allow_unlimited_licenses'] is False:
983 logging.warning('Managed Company unlimited licences are not allowed')
984 return
985 seats = 2147483647
986
987 name = kwargs['name']
988 managed_companies = params.enterprise.get('managed_companies', [])
989 existing_mc = get_mc_by_name_or_id(managed_companies, name)
990 if existing_mc:
991 logging.warning('Managed company \'%s\' already exists: Skipping', name)
992 return
993
994 tree_key = utils.generate_aes_key()
995 rq = {
996 'command': 'enterprise_registration_by_msp',
997 'node_id': node_id,

Callers

nothing calls this directly

Calls 10

get_mc_by_name_or_idFunction · 0.85
resolve_nodesMethod · 0.80
warningMethod · 0.80
get_user_root_nodesMethod · 0.80
communicateMethod · 0.80
CommandErrorClass · 0.70
getMethod · 0.45
encodeMethod · 0.45
infoMethod · 0.45
query_enterpriseMethod · 0.45

Tested by

no test coverage detected