예제 #1
0
    def migrate_Node(self):
        old_node = self.session_old.query(self.model_from['Node']).one()
        new_node = self.model_to['Node']()

        for key in [c.key for c in new_node.__table__.columns]:
            if key == 'receipt_salt':
                new_node.receipt_salt = sha512(old_node.receipt_salt.encode('utf8'))[:32]
                continue

            setattr(new_node, key, getattr(old_node, key))

        self.session_new.add(new_node)
예제 #2
0
    def migrate_User(self):
        old_objs = self.session_old.query(self.model_from['User'])
        for old_obj in old_objs:
            new_obj = self.model_to['User']()

            for key in [c.key for c in new_obj.__table__.columns]:
                if key == 'salt':
                    new_obj.salt = sha512(old_obj.salt.encode('utf8'))[:32]
                    continue

                setattr(new_obj, key, getattr(old_obj, key))

            self.session_new.add(new_obj)
예제 #3
0
    def get_api_session(self):
        token = ''
        if b'api-token' in self.request.args:
            token = binary_type(self.request.args[b'api-token'][0])
        elif b'x-api-token' in self.request.headers:
            token = binary_type(self.request.headers[b'x-api-token'])

        # Assert the input is okay and the api_token state is acceptable
        if self.request.tid != 1 or \
           len(token) != Settings.api_token_len or \
           self.state.api_token_session is None or \
           not self.state.tenant_cache[self.request.tid].admin_api_token_digest:
            return

        stored_token_hash = self.state.tenant_cache[
            self.request.tid].admin_api_token_digest.encode()

        if constant_time.bytes_eq(sha512(token), stored_token_hash):
            return self.state.api_token_session