(params, app_name_or_uid, client_names_and_hashes, force=False)
| 2075 | |
| 2076 | @staticmethod |
| 2077 | def remove_client(params, app_name_or_uid, client_names_and_hashes, force=False): |
| 2078 | |
| 2079 | def convert_ids_and_hashes_to_hashes(cnahs, app_uid): |
| 2080 | |
| 2081 | client_id_hashes_bytes = [] |
| 2082 | |
| 2083 | app_info = KSMCommand.get_app_info(params, app_uid) |
| 2084 | |
| 2085 | for ai in app_info: |
| 2086 | |
| 2087 | if len(ai.clients) > 0: |
| 2088 | for c in ai.clients: |
| 2089 | name = c.id |
| 2090 | client_id = utils.base64_url_encode(c.clientId) |
| 2091 | |
| 2092 | for cnah in cnahs: |
| 2093 | if name == cnah: |
| 2094 | client_id_hashes_bytes.append(c.clientId) |
| 2095 | else: |
| 2096 | if len(cnah) >= KSMCommand.CLIENT_SHORT_ID_LENGTH and client_id.startswith(cnah): |
| 2097 | client_id_hashes_bytes.append(c.clientId) |
| 2098 | |
| 2099 | return client_id_hashes_bytes |
| 2100 | |
| 2101 | if not app_name_or_uid: |
| 2102 | raise Exception("No app provided") |
| 2103 | |
| 2104 | app = KSMCommand.get_app_record(params, app_name_or_uid) |
| 2105 | if not app: |
| 2106 | raise Exception("KMS App with name or uid '%s' not found" % app_name_or_uid) |
| 2107 | |
| 2108 | app_uid = app.get('record_uid') |
| 2109 | |
| 2110 | client_hashes = convert_ids_and_hashes_to_hashes(client_names_and_hashes, app_uid) |
| 2111 | |
| 2112 | found_clients_count = len(client_hashes) |
| 2113 | if found_clients_count == 0: |
| 2114 | print(bcolors.WARNING + "No Client Devices found with given name or ID\n" + bcolors.ENDC) |
| 2115 | return |
| 2116 | |
| 2117 | if not force: |
| 2118 | uc = user_choice(f'\tAre you sure you want to delete {found_clients_count} matching clients from this application?', |
| 2119 | 'yn', default='n') |
| 2120 | if uc.lower() != 'y': |
| 2121 | return |
| 2122 | |
| 2123 | rq = APIRequest_pb2.RemoveAppClientsRequest() |
| 2124 | |
| 2125 | rq.appRecordUid = utils.base64_url_decode(app_uid) |
| 2126 | rq.clients.extend(client_hashes) |
| 2127 | api.communicate_rest(params, rq, 'vault/app_client_remove') |
| 2128 | print(bcolors.OKGREEN + "\nClient removal was successful\n" + bcolors.ENDC) |
| 2129 | |
| 2130 | @staticmethod |
| 2131 | def revoke_client(params, client_ids, force=False): |
no test coverage detected