Пример #1
0
def delete_rabbitmq_account(rabbitmq_username):
    rabbitmq_account = RabbitMQAccount.query.filter(
        RabbitMQAccount.username == rabbitmq_username).first()

    if rabbitmq_account and (g.user.admin
                             or g.user in rabbitmq_account.owners):
        details = {
            'username': g.user.email,
            'rabbitmqusername': rabbitmq_username,
        }
        try:
            pulse_management.delete_user(rabbitmq_account.username)
        except pulse_management.PulseManagementException as e:
            details['message'] = str(e)
            mozdef.log(
                mozdef.ERROR,
                mozdef.OTHER,
                'Error deleting RabbitMQ account',
                details=details,
            )
            return jsonify(ok=False)

        mozdef.log(
            mozdef.NOTICE,
            mozdef.OTHER,
            'RabbitMQ account deleted',
            details=details,
        )
        db_session.delete(rabbitmq_account)
        db_session.commit()
        return jsonify(ok=True)

    return jsonify(ok=False)
Пример #2
0
def delete_pulse_user(pulse_username):
    pulse_user = PulseUser.query.filter(
        PulseUser.username == pulse_username).first()

    if pulse_user and (g.user.admin or g.user in pulse_user.owners):
        details = {
            'username': g.user.email,
            'pulseusername': pulse_username,
        }
        try:
            pulse_management.delete_user(pulse_user.username)
        except pulse_management.PulseManagementException as e:
            details['message'] = str(e)
            mozdef.log(
                mozdef.ERROR,
                mozdef.OTHER,
                'Error deleting Pulse user',
                details=details,
            )
            return jsonify(ok=False)

        mozdef.log(
            mozdef.NOTICE,
            mozdef.OTHER,
            'Pulse user deleted',
            details=details,
        )
        db_session.delete(pulse_user)
        db_session.commit()
        return jsonify(ok=True)

    return jsonify(ok=False)
Пример #3
0
def delete_rabbitmq_account(rabbitmq_username):
    rabbitmq_account = RabbitMQAccount.query.filter(
        RabbitMQAccount.username == rabbitmq_username).first()

    if rabbitmq_account and (g.user.admin or g.user in
                             rabbitmq_account.owners):
        details = {
            'username': g.user.email,
            'rabbitmqusername': rabbitmq_username,
        }
        try:
            pulse_management.delete_user(rabbitmq_account.username)
        except pulse_management.PulseManagementException as e:
            details['message'] = str(e)
            mozdef.log(
                mozdef.ERROR,
                mozdef.OTHER,
                'Error deleting RabbitMQ account',
                details=details,
            )
            return jsonify(ok=False)

        mozdef.log(
            mozdef.NOTICE,
            mozdef.OTHER,
            'RabbitMQ account deleted',
            details=details,
        )
        db_session.delete(rabbitmq_account)
        db_session.commit()
        return jsonify(ok=True)

    return jsonify(ok=False)
Пример #4
0
    def change_password(self, new_password):
        """"Changes" a user's password by deleting his rabbitmq account
        and recreating it with the new password.
        """
        try:
            pulse_management.delete_user(self.username)
        except pulse_management.PulseManagementException:
            pass

        self._create_user(new_password)
        self._set_permissions()

        db_session.add(self)
        db_session.commit()
Пример #5
0
    def change_password(self, new_password):
        """"Changes" a user's password by deleting his rabbitmq account
        and recreating it with the new password.
        """
        try:
            pulse_management.delete_user(self.username)
        except pulse_management.PulseManagementException:
            pass

        self._create_user(new_password)
        self._set_permissions()

        db_session.add(self)
        db_session.commit()
Пример #6
0
def delete_pulse_user(pulse_username):
    logging.info('Request to delete Pulse user "{0}".'.format(pulse_username))
    pulse_user = PulseUser.query.filter(PulseUser.username == pulse_username).first()

    if pulse_user and (g.user.admin or pulse_user.owner == g.user):
        try:
            pulse_management.delete_user(pulse_user.username)
        except pulse_management.PulseManagementException as e:
            logging.warning("Couldn't delete user '{0}' on "
                               "rabbitmq: {1}".format(pulse_username, e))
            return jsonify(ok=False)
        logging.info('Pulse user "{0}" deleted.'.format(pulse_username))
        db_session.delete(pulse_user)
        db_session.commit()
        return jsonify(ok=True)

    return jsonify(ok=False)
Пример #7
0
def delete_pulse_user(pulse_username):
    logging.info('Request to delete Pulse user "{0}".'.format(pulse_username))
    pulse_user = PulseUser.query.filter(
        PulseUser.username == pulse_username).first()

    if pulse_user and (g.user.admin or pulse_user.owner == g.user):
        try:
            pulse_management.delete_user(pulse_user.username)
        except pulse_management.PulseManagementException as e:
            logging.warning("Couldn't delete user '{0}' on "
                            "rabbitmq: {1}".format(pulse_username, e))
            return jsonify(ok=False)
        logging.info('Pulse user "{0}" deleted.'.format(pulse_username))
        db_session.delete(pulse_user)
        db_session.commit()
        return jsonify(ok=True)

    return jsonify(ok=False)
Пример #8
0
def init_and_clear_db():
    # Initialize the database schema.
    init_db()

    # Remove all users and pulse users created by the web app.
    for rabbitmq_account in RabbitMQAccount.query.all():
        try:
            pulse_management.delete_user(rabbitmq_account.username)
        except pulse_management.PulseManagementException:
            pass

    # Clear the database of old data.
    for queue in Queue.query.all():
        db_session.delete(queue)
    for binding in Binding.query.all():
        db_session.delete(binding)
    for rabbitmq_account in RabbitMQAccount.query.all():
        db_session.delete(rabbitmq_account)
    for user in User.query.all():
        db_session.delete(user)

    db_session.commit()

    logger.info('Finished initializing database.')
Пример #9
0
def init_and_clear_db():
    # Initialize the database schema.
    init_db()

    # Remove all users and pulse users created by the web app.
    for rabbitmq_account in RabbitMQAccount.query.all():
        try:
            pulse_management.delete_user(rabbitmq_account.username)
        except pulse_management.PulseManagementException:
            pass

    # Clear the database of old data.
    for queue in Queue.query.all():
        db_session.delete(queue)
    for binding in Binding.query.all():
        db_session.delete(binding)
    for rabbitmq_account in RabbitMQAccount.query.all():
        db_session.delete(rabbitmq_account)
    for user in User.query.all():
        db_session.delete(user)

    db_session.commit()

    logger.info('Finished initializing database.')