Exemple #1
0
def dummy_data():
    # Dummy test users
    User.new_user('*****@*****.**')

    for i in xrange(4):
        PulseUser.new_user(
            username='******'.format(i),
            password='******',
            owner=User.query.first(),
            management_api=pulse_management)

    pulse_users = PulseUser.query.all()

    # And some dummy queues
    dummy_queue = Queue(name='dummy-empty-queue', size=0, owner=pulse_users[0])
    db_session.add(dummy_queue)
    db_session.commit()

    dummy_queue = Queue(name='dummy-non-empty-queue', size=config.warn_queue_size/5, owner=pulse_users[0])
    db_session.add(dummy_queue)
    db_session.commit()

    dummy_queue = Queue(name='dummy-warning-queue', size=config.warn_queue_size + 1, owner=pulse_users[1])
    db_session.add(dummy_queue)
    db_session.commit()

    dummy_queue = Queue(name='dummy-deletion-queue', size=int(config.del_queue_size * 1.2), owner=pulse_users[2])
    db_session.add(dummy_queue)
    db_session.commit()

    # Test admin user
    User.new_user('*****@*****.**', admin=True)

    logger.info('Finished generating dummy data.')
Exemple #2
0
def register_handler():
    username = request.form['username']
    password = request.form['password']
    password_verification = request.form['password-verification']
    email = session['email']
    errors = []

    if password != password_verification:
        errors.append("Password verification doesn't match the password.")
    elif not PulseUser.strong_password(password):
        errors.append("Your password must contain a mix of letters and "
                      "numerical characters and be at least 6 characters long.")

    if not re.match('^[a-zA-Z][a-zA-Z0-9._-]*$', username):
        errors.append("The submitted username must start with an "
                      "alphabetical character and contain only alphanumeric "
                      "characters, periods, underscores, and hyphens.")

    # Checking if a user exists in RabbitMQ OR in our db
    try:
        user_response = pulse_management.user(username=username)
        in_rabbitmq = True
    except PulseManagementException:
        in_rabbitmq = False
    else:
        if 'error' in user_response:
            in_rabbitmq = False

    if (in_rabbitmq or
        PulseUser.query.filter(PulseUser.username == username).first()):
        errors.append("A user with the same username already exists.")

    if errors:
        return render_template('register.html', email=email,
                               signup_errors=errors)

    PulseUser.new_user(username, password, g.user, pulse_management)

    return redirect('/profile')
Exemple #3
0
    def update_queue_information(self, queue_data):
        if not "messages" in queue_data:
            # FIXME: We should do something here, probably delete the queue,
            # as it's in a weird state.  More investigation is required.
            # See bug 1066338.
            return None

        q_size, q_name, q_durable = (queue_data["messages"], queue_data["name"], queue_data["durable"])
        queue = Queue.query.filter(Queue.name == q_name).first()

        # If the queue doesn't exist in the db, create it.
        if queue is None:
            m = re.match("queue/([^/]+)/", q_name)
            logging.info("New queue '{0}' encountered. " "Adding to the database.".format(q_name))
            if m:
                owner_name = m.group(1)
                owner = PulseUser.query.filter(PulseUser.username == owner_name).first()

                # If the queue was created by a user that isn't in the
                # pulseguardian database, skip the queue.
                if owner is None:
                    logging.info(
                        "Queue '{0}' owner, {1}, isn't in the db. Creating " "the user.".format(q_name, owner_name)
                    )
                    owner = PulseUser.new_user(owner_name)

                # Assign the user to the queue.
                logging.info("Assigning queue '{0}' to user " "{1}.".format(q_name, owner))
            else:
                logging.warn("'{0}' is not a standard queue name.".format(q_name))
                owner = None
            queue = Queue(name=q_name, owner=owner)

        # Update the saved queue size.
        queue.size = q_size
        queue.durable = q_durable
        db_session.add(queue)
        db_session.commit()
        return queue