Example #1
0
 def inject_message(self, message):
     """
     Здесь должен происходить некоторый роутинг
     :type message: bouser.simargl.message.Message
     :param message:
     :return:
     """
     get_json(self.api_url, json=message)
 def inject_message(self, message):
     """
     Здесь должен происходить некоторый роутинг
     :type message: bouser.simargl.message.Message
     :param message:
     :return:
     """
     get_json(self.api_url, json=message)
Example #3
0
 def get_user_id(self, token):
     def _cb(j):
         if j['success']:
             return j['user_id']
         return defer.fail(EExpiredToken(token))
     return get_json(
         self.cas_url + 'get_user_id',
         json={'token': token.encode('hex')}
     ).addCallback(_cb)
Example #4
0
 def prolong_token(self, token):
     def _cb(j):
         if j['success']:
             return True, j['deadline']
         return defer.fail(EExpiredToken(token))
     return get_json(
         self.cas_url + 'prolong',
         json={'token': token}
     ).addCallback(_cb)
Example #5
0
    def prolong_token(self, token):
        def _cb(j):
            if j['success']:
                return True, j['deadline']
            return defer.fail(EExpiredToken(token))

        return get_json(self.cas_url + 'prolong', json={
            'token': token
        }).addCallback(_cb)
Example #6
0
    def release_token(self, token):
        def _cb(j):
            if j['success']:
                return True
            return defer.fail(EExpiredToken(token))

        return get_json(self.cas_url + 'release', json={
            'token': token
        }).addCallback(_cb)
Example #7
0
    def release_token(self, token):
        def _cb(j):
            if j['success']:
                return True
            return defer.fail(EExpiredToken(token))

        return get_json(
            self.cas_url + 'release',
            json={'token': token}
        ).addCallback(_cb)
Example #8
0
    def get_user_id(self, token):
        def _cb(j):
            if j['success']:
                return j['user_id']
            return defer.fail(EExpiredToken(token))

        return get_json(self.cas_url + 'get_user_id',
                        json={
                            'token': token.encode('hex')
                        }).addCallback(_cb)
Example #9
0
    def check_token(self, token, prolong=False):
        def _cb(j):
            if j['success']:
                return j['user_id'], j['deadline']
            return defer.fail(EExpiredToken(token))

        send = {'token': token.encode('hex')}
        if prolong:
            send['prolong'] = True

        return get_json(self.cas_url + 'check', json=send).addCallback(_cb)
Example #10
0
    def check_token(self, token, prolong=False):
        def _cb(j):
            if j['success']:
                return j['user_id'], j['deadline']
            return defer.fail(EExpiredToken(token))

        send = {'token': token.encode('hex')}
        if prolong:
            send['prolong'] = True

        return get_json(
            self.cas_url + 'check', json=send
        ).addCallback(_cb)
Example #11
0
    def acquire_token(self, login, password):
        def _cb(j):
            if j['success']:
                return AuthTokenObject(j['user'], j['deadline'], j['token'])
            exception = j['exception']
            if exception == 'EInvalidCredentials':
                raise EInvalidCredentials
            raise Exception(j)

        return get_json(
            self.cas_url + 'acquire',
            json={'login': login, 'password': password}
        ).addCallback(_cb)
Example #12
0
    def acquire_token(self, login, password):
        def _cb(j):
            if j['success']:
                return AuthTokenObject(j['user'], j['deadline'], j['token'])
            exception = j['exception']
            if exception == 'EInvalidCredentials':
                raise EInvalidCredentials
            raise Exception(j)

        return get_json(self.cas_url + 'acquire',
                        json={
                            'login': login,
                            'password': password
                        }).addCallback(_cb)
Example #13
0
 def on_amqp_message(self, msg):
     """
     Когда из очереди RabbitMQ валится сообщение, оно должно быть разобрано и отправлено в РИСАР.
     Урлы, на которые надо ходить в РИСАР, должны определяться здесь (можно вынести куда-то).
     @param msg:
     @return:
     """
     if msg and msg.content:
         content = json.loads(msg.content)
         # content здесь надо разобрать согласно формату сообщений (заголовки, вся фигня) и отдать в REST
         # То есть здесь должно быть много-много if-elif-else и много-много разных урлов
         result = yield get_json(self.url_root + '/1/echo',
                                 json=content,
                                 method='POST')
         defer.returnValue(result)
Example #14
0
def make_config(filename, fmt=None):
    config = {}
    if re_usagi_config.match(filename):
        from bouser.helpers.api_helpers import get_json
        config = yield get_json(filename)
        config = config['result']
    elif re_local_config.match(filename):
        if fmt is None:
            _, ext = os.path.splitext(os.path.basename(filename))
            ext = ext[1:]
            if ext.lower() in ('yaml', 'yml'):
                fmt = 'yaml'
            else:
                fmt = 'conf'
        if fmt == 'yaml':
            import yaml
            with open(filename, 'rb') as cfg_file:
                config.update(yaml.load(cfg_file))
        else:
            with open(filename, 'rt') as cfg_file:
                config.update(parse_config(cfg_file))
    defer.returnValue(config)