Beispiel #1
0
 async def get_user(self, user_id: int) -> User:
     if user_id == 0:
         return User(user_id=0,
                     is_active=True,
                     quota=self.QUOTA,
                     traffic_quota=self.TRAFFIC_QUOTA)
     else:
         raise UserNotFound
Beispiel #2
0
 def _get_user(self, key: str) -> User:
     user_info = self._get(key, 'user_id', 'is_active', 'quota', 'traffic_quota')
     user_id, is_active, quota, traffic_quota = user_info
     if any(attr is None for attr in user_info):
         raise KeyError('Element not found')
     return User(user_id=int(user_id.decode('utf-8')),
                 is_active=(is_active == b'1'),
                 quota=int(quota.decode()),
                 traffic_quota=int(traffic_quota.decode()))
Beispiel #3
0
 async def auth(self, auth_header: str) -> User:
     if auth_header == 'Token {}'.format(options.dummy_auth):
         raise BypassAuth(
             User(user_id=0,
                  is_active=True,
                  quota=self.QUOTA,
                  traffic_quota=self.TRAFFIC_QUOTA))
     else:
         raise UserNotFound()
Beispiel #4
0
    async def api_request(request_data):
        request_body = json.dumps(request_data)
        response = await AccountingServerAuth.send_request(request_body)
        try:
            body = json.loads(response.body.decode('utf-8'))
        except json.JSONDecodeError as e:
            raise AuthError(e)

        try:
            return User(user_id=body['user_id'],
                        is_active=body['active'],
                        quota=body['block_quota'],
                        traffic_quota=body['monthly_traffic_quota'])
        except KeyError:
            raise UserNotFound('Invalid response from accounting server')