(params, record, skip_extra=False)
| 189 | |
| 190 | |
| 191 | def update_record(params, record, skip_extra=False): |
| 192 | # type: (KeeperParams, vault.KeeperRecord, bool) -> None |
| 193 | storage_record = params.record_cache.get(record.record_uid) |
| 194 | if not storage_record: |
| 195 | raise Exception(f'Record Update: {record.record_uid} not found.') |
| 196 | |
| 197 | existing_record = vault.KeeperRecord.load(params, storage_record) |
| 198 | if type(existing_record) != type(record): |
| 199 | raise Exception(f'Record {record.record_uid}: Invalid record type.') |
| 200 | |
| 201 | record_change_status = compare_records(record, existing_record) |
| 202 | |
| 203 | if isinstance(record, vault.PasswordRecord) and isinstance(existing_record, vault.PasswordRecord): |
| 204 | record_object = { |
| 205 | 'record_uid': record.record_uid, |
| 206 | 'version': 2, |
| 207 | 'revision': existing_record.revision, |
| 208 | 'client_modified_time': utils.current_milli_time(), |
| 209 | } |
| 210 | path = api.resolve_record_write_path(params, record.record_uid) |
| 211 | if path: |
| 212 | record_object.update(path) |
| 213 | |
| 214 | data = vault_extensions.extract_password_record_data(record) |
| 215 | record_object['data'] = utils.base64_url_encode( |
| 216 | crypto.encrypt_aes_v1(json.dumps(data).encode(), record.record_key)) |
| 217 | |
| 218 | if not skip_extra: |
| 219 | existing_extra = None |
| 220 | try: |
| 221 | if 'extra_unencrypted' in storage_record: |
| 222 | existing_extra = json.loads(storage_record['extra_unencrypted']) |
| 223 | except Exception as e: |
| 224 | logging.warning('Decrypt record %s extra error: %s', record.record_uid, e) |
| 225 | |
| 226 | extra = vault_extensions.extract_password_record_extras(record, existing_extra) |
| 227 | extra_str = json.dumps(extra) |
| 228 | record_object['extra'] = utils.base64_url_encode( |
| 229 | crypto.encrypt_aes_v1(extra_str.encode('utf-8'), record.record_key)) |
| 230 | |
| 231 | if 'udata' in storage_record: |
| 232 | u = storage_record['udata'] |
| 233 | if isinstance(u, dict): |
| 234 | udata = u |
| 235 | elif isinstance(u, (str, bytes)): |
| 236 | udata = json.loads(u) |
| 237 | else: |
| 238 | udata = {} |
| 239 | else: |
| 240 | udata = {} |
| 241 | |
| 242 | file_ids = [] |
| 243 | udata['file_ids'] = file_ids |
| 244 | if record.attachments: |
| 245 | for atta in record.attachments: |
| 246 | file_ids.append(atta.id) |
| 247 | if atta.thumbnails: |
| 248 | for thumb in atta.thumbnails: |
nothing calls this directly
no test coverage detected