Push a record update to the cloud. Takes a Record() object, converts to record JSON and pushes to the Keeper cloud API
(params, record, **kwargs)
| 938 | |
| 939 | |
| 940 | def update_record(params, record, **kwargs): |
| 941 | """ Push a record update to the cloud. |
| 942 | Takes a Record() object, converts to record JSON |
| 943 | and pushes to the Keeper cloud API |
| 944 | """ |
| 945 | |
| 946 | if (record and record.record_uid in params.record_cache |
| 947 | and 'version' in params.record_cache[record.record_uid] |
| 948 | and params.record_cache[record.record_uid]['version'] == 3): |
| 949 | return update_record_v3(params, record, **kwargs) |
| 950 | |
| 951 | record_rq = prepare_record(params, record) |
| 952 | if record_rq is None: |
| 953 | return |
| 954 | |
| 955 | request = { |
| 956 | 'command': 'record_update', |
| 957 | 'update_records': [record_rq] |
| 958 | } |
| 959 | response_json = communicate(params, request) |
| 960 | |
| 961 | new_revision = 0 |
| 962 | if 'update_records' in response_json: |
| 963 | for info in response_json['update_records']: |
| 964 | if info['record_uid'] == record.record_uid: |
| 965 | if info['status'] == 'success': |
| 966 | new_revision = response_json['revision'] |
| 967 | |
| 968 | if new_revision == 0: |
| 969 | logging.error('Error: Revision not updated') |
| 970 | return False |
| 971 | |
| 972 | if new_revision == record_rq['revision']: |
| 973 | logging.error('Error: Revision did not change') |
| 974 | return False |
| 975 | |
| 976 | if not kwargs.get('silent'): |
| 977 | logging.info('Update record successful for record_uid=%s, revision=%d, new_revision=%s', |
| 978 | record_rq['record_uid'], record_rq['revision'], new_revision) |
| 979 | |
| 980 | record_rq['revision'] = new_revision |
| 981 | |
| 982 | # sync down the data which updates the caches |
| 983 | sync_down(params) |
| 984 | add_record_audit_data(params, [record.record_uid]) |
| 985 | return True |
| 986 | |
| 987 | |
| 988 | def get_pb2_record_update(params, rec, **kwargs): |
no test coverage detected