Beispiel #1
0
def user_db_to_msg(user):
    if user is None:
        return None

    return {
        'username': user['username'],
        'created_at': datetime_to_rfc2339(datetime.datetime.utcfromtimestamp(user['created_at'])),
        'last_updated': datetime_to_rfc2339(datetime.datetime.utcfromtimestamp(user['last_updated'])),
        'created_by': user['created_by']
    }
Beispiel #2
0
def account_db_to_msg(account):
    if account is None:
        return None

    return {
        'name': account['name'],
        'email': account['email'],
        'is_active': account['is_active'],
        'type': account['type'].value,
        'created_at': datetime_to_rfc2339(datetime.datetime.utcfromtimestamp(account['created_at'])),
        'last_updated': datetime_to_rfc2339(datetime.datetime.utcfromtimestamp(account['last_updated'])),
        'created_by': account['created_by']
    }
Beispiel #3
0
def credential_db_to_msg(credential):
    if credential is None:
        return None

    return {
        'type': credential['type'].value,
        'value': ''.join(['*' for _ in credential['value']]),
        'created_at': datetime_to_rfc2339(datetime.datetime.utcfromtimestamp(credential['created_at'])),
        'created_by': credential['created_by']
    }
Beispiel #4
0
 def _map_type(obj):
     if type(obj) == datetime.datetime:
         return datetime_to_rfc2339(obj)
     elif type(obj) in [list, set]:
         return [SimpleJsonModel._map_type(i) for i in obj]
     elif type(obj) == dict:
         return {k: SimpleJsonModel._map_type(v) for k, v in obj.items()}
     elif isinstance(obj, SimpleJsonModel):
         return obj.to_json()
     else:
         return obj
Beispiel #5
0
def account_db_to_msg(account):
    if account is None:
        return None

    return {
        'name':
        account['name'],
        'email':
        account['email'],
        'state':
        account['state'].value
        if type(account['state']) != str else account['state'],
        'type':
        account['type']
        if type(account['type']) == str else account['type'].value,
        'created_at':
        datetime_to_rfc2339(
            datetime.datetime.utcfromtimestamp(account['created_at'])),
        'last_updated':
        datetime_to_rfc2339(
            datetime.datetime.utcfromtimestamp(account['last_updated']))
    }