(self, params, **kwargs)
| 1088 | return msp_remove_parser |
| 1089 | |
| 1090 | def execute(self, params, **kwargs): |
| 1091 | mc_input = kwargs.get('mc', '') |
| 1092 | if not mc_input: |
| 1093 | raise CommandError('msp-remove', 'Managed Company name or id is required') |
| 1094 | managed_companies = params.enterprise.get('managed_companies', []) |
| 1095 | current_mc = get_mc_by_name_or_id(managed_companies, mc_input) |
| 1096 | if not current_mc: |
| 1097 | raise CommandError('msp-remove', f'Managed Company \"{mc_input}\" not found') |
| 1098 | if kwargs.get('force') is True: |
| 1099 | answer = 'y' |
| 1100 | else: |
| 1101 | answer = user_choice(bcolors.FAIL + bcolors.BOLD + 'ALERT!\n' + bcolors.ENDC + 'Remove Managed Company.\n\n' + |
| 1102 | 'Removing will expire the licences for the managed company and your admin access for the account.\n' + |
| 1103 | f'Managed Company Name: \"{current_mc["mc_enterprise_name"]}\", Licences: {current_mc["number_of_seats"]}\n\n' + |
| 1104 | 'I want to remove these licences managed vault folder and my access to the admin console from my MSP account.', 'yn', 'n') |
| 1105 | if answer.lower() == 'y': |
| 1106 | rq = { |
| 1107 | 'command': 'enterprise_remove_by_msp', |
| 1108 | 'enterprise_id': current_mc['mc_enterprise_id'] |
| 1109 | } |
| 1110 | rs = api.communicate(params, rq) |
| 1111 | if rs: |
| 1112 | logging.info('Managed company \"%s\" removed. ID=%d', current_mc['mc_enterprise_name'], current_mc['mc_enterprise_id']) |
| 1113 | api.query_enterprise(params) |
| 1114 | |
| 1115 | |
| 1116 | def get_mc_by_name_or_id(msc, name_or_id): |
nothing calls this directly
no test coverage detected