MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / validate_record_data

Method validate_record_data

keepercommander/record.py:400–429  ·  view source on GitHub ↗
(cls, data, extra, udata)

Source from the content-addressed store, hash-verified

398
399 @classmethod
400 def validate_record_data(cls, data, extra, udata):
401 # data - always present (UID, Title, ...)
402 if data:
403 data_types = {
404 'folder': {'field': 'folder', 'name': 'folder', 'type': ''},
405 'title': {'field': 'title', 'name': 'title', 'type': ''},
406 'secret1': {'field': 'secret1', 'name': 'login', 'type': ''},
407 'secret2': {'field': 'secret2', 'name': 'password', 'type': ''},
408 'link': {'field': 'link', 'name': 'url', 'type': ''},
409 'notes': {'field': 'notes', 'name': 'notes', 'type': ''},
410 'custom': {'field': 'custom', 'name': 'custom', 'type': []}
411 }
412
413 for item in data_types:
414 if item in data and type(data.get(item)) != type(data_types[item].get('type')):
415 raise ValueError('Error validating record data - "' + data_types[item].get('name') + '" is invalid!')
416
417 if 'custom' in data and isinstance(data['custom'], list):
418 invalid = [x for x in data['custom'] if not(x)]
419 if invalid:
420 raise ValueError('Error validating record data - Invalid custom fields! ' + str(invalid))
421 else:
422 raise Exception('Record is empty!')
423
424 # extra and udata sections are optional
425 if extra:
426 fields = extra.get('fields') or []
427 invalid = [x for x in fields if not(x)]
428 if invalid:
429 raise ValueError('Error validating record extra data - Invalid extra fields! ' + str(invalid))

Callers 2

prepare_recordFunction · 0.80
executeMethod · 0.80

Calls 1

getMethod · 0.80

Tested by

no test coverage detected