"""Token Model. The application will generate several tokens. The tokens are responsible for allowing external events to come through. Those events can be: client events (a client is trying to reach a service on the behalf of a user), or events related to the service itself (e.g. password reset). Token contains information related to the user, the client, the type of token (if it is related to connection, password reset etc), and a revoked flag. """ from sukimu.dynamodb import IndexDynamo from sukimu.dynamodb import TableDynamo from sukimu.fields import Field from sukimu.schema import Index from sukimu.schema import Schema from auth import config from auth.connectors import dynamodb from auth.models import validators class TYPE: """Static class to store Token Types.""" CONNECTION = 1 CODE = 2 LOST_PASSWORD = 3 @staticmethod def validator(): """Validate the type.""" return validators.enum(TYPE.CONNECTION, TYPE.CODE, TYPE.LOST_PASSWORD) Token = Schema( TableDynamo(config.TABLE_TOKEN, dynamodb.connection), IndexDynamo( Index.PRIMARY, 'token', read_capacity=1, write_capacity=1), token=Field(required=True, basetype=str), type=Field(TYPE.validator(), required=True, basetype=int), # Validity of the token. date=Field(required=True, basetype=int), expires_in=Field(required=True, basetype=int), revoked=Field(basetype=bool), # Data related to auth: client and user information. client_id=Field(required=True, basetype=int), user_id=Field(required=True, basetype=str), user_login=Field(required=True, basetype=str))