| 2160 | |
| 2161 | |
| 2162 | class DeleteCorruptedCommand(Command): |
| 2163 | def execute(self, params, **kwargs): |
| 2164 | bad_records = set() |
| 2165 | for record_uid in params.record_cache: |
| 2166 | record = params.record_cache[record_uid] |
| 2167 | if not record.get('data_unencrypted'): |
| 2168 | if record_uid in params.record_owner_cache: |
| 2169 | own = params.record_owner_cache[record_uid] |
| 2170 | if own.owner is True: |
| 2171 | bad_records.add(record_uid) |
| 2172 | if len(bad_records) > 0: |
| 2173 | uc = user_choice('Do you want to delete {0} corrupted records?'.format(len(bad_records)), 'yn', default='n') |
| 2174 | if uc.lower() == 'y': |
| 2175 | request = { |
| 2176 | 'command': 'record_update', |
| 2177 | 'delete_records': list(bad_records) |
| 2178 | } |
| 2179 | logging.info('Deleting %s records from Keeper', len(params.record_cache)) |
| 2180 | response_json = api.communicate(params, request) |
| 2181 | success = [info for info in response_json['delete_records'] if info['status'] == 'success'] |
| 2182 | if len(success) > 0: |
| 2183 | logging.info("%s records deleted successfully", len(success)) |
| 2184 | failures = [info for info in response_json['delete_records'] if info['status'] != 'success'] |
| 2185 | if len(failures) > 0: |
| 2186 | logging.warning("%s records failed to delete", len(failures)) |
| 2187 | else: |
| 2188 | logging.info('No corrupted records are found.') |
| 2189 | |
| 2190 | |
| 2191 | class GenerateCommand(Command): |