(params, record, skip_extra=False)
| 220 | |
| 221 | |
| 222 | def update_record(params, record, skip_extra=False): |
| 223 | # type: (KeeperParams, vault.KeeperRecord, bool) -> None |
| 224 | storage_record = params.record_cache.get(record.record_uid) |
| 225 | if not storage_record: |
| 226 | raise Exception(f'Record Update: {record.record_uid} not found.') |
| 227 | |
| 228 | existing_record = vault.KeeperRecord.load(params, storage_record) |
| 229 | if type(existing_record) != type(record): |
| 230 | raise Exception(f'Record {record.record_uid}: Invalid record type.') |
| 231 | |
| 232 | record_change_status = compare_records(record, existing_record) |
| 233 | |
| 234 | if isinstance(record, vault.PasswordRecord) and isinstance(existing_record, vault.PasswordRecord): |
| 235 | record_object = { |
| 236 | 'record_uid': record.record_uid, |
| 237 | 'version': 2, |
| 238 | 'revision': existing_record.revision, |
| 239 | 'client_modified_time': utils.current_milli_time(), |
| 240 | } |
| 241 | path = api.resolve_record_write_path(params, record.record_uid) |
| 242 | if path: |
| 243 | record_object.update(path) |
| 244 | |
| 245 | data = vault_extensions.extract_password_record_data(record) |
| 246 | decrypted_data = json.dumps(data).encode() |
| 247 | encrypted_data = crypto.encrypt_aes_v1(decrypted_data, record.record_key) |
| 248 | record_object['data'] = utils.base64_url_encode(encrypted_data) |
| 249 | |
| 250 | decrypted_extra = None |
| 251 | encrypted_extra = None |
| 252 | if not skip_extra: |
| 253 | existing_extra = None |
| 254 | try: |
| 255 | if 'extra_unencrypted' in storage_record: |
| 256 | existing_extra = json.loads(storage_record['extra_unencrypted']) |
| 257 | except Exception as e: |
| 258 | logging.warning('Decrypt record %s extra error: %s', record.record_uid, e) |
| 259 | |
| 260 | extra = vault_extensions.extract_password_record_extras(record, existing_extra) |
| 261 | extra_str = json.dumps(extra) |
| 262 | decrypted_extra = extra_str.encode('utf-8') |
| 263 | encrypted_extra = crypto.encrypt_aes_v1(decrypted_extra, record.record_key) |
| 264 | record_object['extra'] = utils.base64_url_encode(encrypted_extra) |
| 265 | |
| 266 | if 'udata' in storage_record: |
| 267 | u = storage_record['udata'] |
| 268 | if isinstance(u, dict): |
| 269 | udata = u |
| 270 | elif isinstance(u, (str, bytes)): |
| 271 | udata = json.loads(u) |
| 272 | else: |
| 273 | udata = {} |
| 274 | else: |
| 275 | udata = {} |
| 276 | |
| 277 | file_ids = [] |
| 278 | udata['file_ids'] = file_ids |
| 279 | if record.attachments: |
nothing calls this directly
no test coverage detected