Skip to content

Instantly share code, notes, and snippets.



Created Apr 10, 2020
What would you like to do?
if 'details' not in item:
raise ValidationError('No details in item', item=item)
details = item['details']
if 'fields' not in details:
raise ValidationError('No fields in details for item', item=item)
if 'sections' not in details:
raise ValidationError('No sections in details for item', item=item)
fields = item["details"]["fields"]
sections = item["details"]["sections"]
username = None
password = None
token = None
for field in fields:
if 'value' not in field or 'name' not in field:
raise ValidationError('Encountered malformed field', field=field, item=item)
value = field['value']
name = field['name']
if name == 'username':
username = value
elif name == 'password':
password = value
# Other fields are allowed
if not username:
raise ValidationError('No username', item=item)
if not password:
raise ValidationError('No password', item=item)
for section in sections:
if 'title' not in section:
raise ValidationError('Section without a title', section=section, item=item)
if section['title'].lower() == 'cloudvpn':
if 'fields' not in section or not len(section['fields']) or 'v' not in section['fields'][0]:
raise ValidationError('Malformed cloudvpn section', section=section, item=item)
token = section['fields'][0]['v']
if not token:
raise ValidationError('no cloudvpn token', item=item)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.