Commits

Tim Flink committed e3f7f23 Merge

Merged in ralphbean/resultsdb_frontend/no-more-authn (pull request #5)

Remove sqlalchemy and login from everywhere.

  • Participants
  • Parent commits 6215768, bccd921

Comments (0)

Files changed (15)

conf/resultsdb_frontend.wsgi

 # This is required for running on EL6
 import __main__
-__main__.__requires__ = ['SQLAlchemy >= 0.7', 'Flask >= 0.9', 'jinja2 >= 2.6']
+__main__.__requires__ = ['Flask >= 0.9', 'jinja2 >= 2.6']
 import pkg_resources
 
 #activate_this = '/var/www/resultsdb_frontend/env/bin/activate_this.py'

conf/settings.py.example

 # cli to generate a config file
 RDB_URL = 'http://localhost:5000/api/v1.0'
 SECRET_KEY = 'not-really-a-secret'
-SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://dbuser:dbpassword@dbhost:dbport/dbname'
 FILE_LOGGING = False
 LOGFILR = '/var/log/resultsdb_frontend/resultsdb_frontend.log'
 SYSLOG_LOGGING = False

init_db.sh

-#!/usr/bin/bash
-# this is a simple script to aid in the setup of a new db for F18
-
-# init db
-python run_cli.py init_db
-
-# insert mock data
-python run_cli.py mock_data
 Flask>=0.9
-Flask-SQLAlchemy>=0.16
-SQLAlchemy>= 0.7
 WTForms>1.0
 #FIXME: change Flask-WTF to >= 0.8 (?) there seems to be a bug now (see below), or it might be connected to the Flask version - find out!
 # File "/home/jskladan/flask_virtualenv/lib/python2.7/site-packages/Flask_WTF-0.9.0-py2.7.egg/flask_wtf/recaptcha/widgets.py", line 5, in <module>
 #     from flask.json import dumps, JSONEncoder
 Flask-WTF==0.8
-Flask-Login>=0.2.2
 resultsdb_api

resultsdb_frontend.spec

 BuildArch:      noarch
 
 Requires:       python-flask
-Requires:       python-flask-sqlalchemy
-Requires:       MySQL-python
 Requires:       python-flask-wtf
-Requires:       python-flask-login
 Requires:       python-flask-restful
 Requires:       python-six
 Requires:       python-iso8601

resultsdb_frontend/__init__.py

 
 
 from flask import Flask, render_template
-from flask.ext.login import LoginManager
-from flask.ext.sqlalchemy import SQLAlchemy
 
 import logging
 import os
 
 setup_logging()
 
-app.logger.debug('using DBURI: %s' % app.config['SQLALCHEMY_DATABASE_URI'])
-
-# database
-db = SQLAlchemy(app)
-
-# setup login manager
-login_manager = LoginManager()
-login_manager.setup_app(app)
-login_manager.login_view = 'login_page.login'
-
 # register blueprints
 from resultsdb_frontend.controllers.main import main
 app.register_blueprint(main)
-
-from resultsdb_frontend.controllers.login_page import login_page
-app.register_blueprint(login_page)
-
-from resultsdb_frontend.controllers.admin import admin
-app.register_blueprint(admin)

resultsdb_frontend/cli.py

-# Copyright 2013, Red Hat, Inc
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Authors:
-#   Josef Skladanka <jskladan@redhat.com>
-
-# This is required for running on EL6
-import __main__
-__main__.__requires__ = ['SQLAlchemy >= 0.7', 'Flask >= 0.9', 'jinja2 >= 2.6']
-import pkg_resources
-
-
-from optparse import OptionParser
-import sys
-
-from resultsdb_frontend import db
-from resultsdb_frontend.models.user import User
-
-
-def initialize_db():
-    print "Initializing Database"
-    db.drop_all()
-    db.create_all()
-
-def mock_data():
-    data = [('admin', 'admin'), ('user', 'user')]
-
-    for d in data:
-        u = User(*d)
-        db.session.add(u)
-    db.session.commit()
-
-
-
-if __name__ == '__main__':
-
-    possible_commands = ['init_db', 'mock_data']
-
-    usage = 'usage: [DEV=true] %prog ' + "(%s)" % ' | '.join(possible_commands)
-    parser = OptionParser(usage=usage)
-
-    (options, args) = parser.parse_args()
-
-    if len(args) < 1:
-        print usage
-        print
-        print 'Please use one of the following commands: %s' % str(possible_commands)
-        sys.exit(1)
-
-
-    command = args[0]
-    if not command in possible_commands:
-        print 'Invalid command: %s' % command
-        print 'Please use one of the following commands: %s' % str(possible_commands)
-        sys.exit(1)
-
-
-    if command == 'init_db':
-        initialize_db()
-    elif command == 'mock_data':
-        mock_data()
-
-    sys.exit(0)

resultsdb_frontend/config.py

 
 class Config(object):
     DEBUG = True
-    SQLALCHEMY_DATABASE_URI = 'sqlite://'
 
     RDB_URL = 'http://localhost:5000/api/v1.0'
 
 
 class DevelopmentConfig(Config):
     TRAP_BAD_REQUEST_ERRORS = True
-    SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/resultsdb_frontend_db.sqlite'
     HOST = '0.0.0.0'
     PORT = 5001
 

resultsdb_frontend/controllers/admin.py

-# Copyright 2013, Red Hat, Inc
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Authors:
-#   Josef Skladanka <jskladan@redhat.com>
-
-from flask import Blueprint, render_template, flash, url_for
-from flask.ext.login import login_required
-
-
-admin = Blueprint('admin', __name__)
-
-@admin.route('/admin')
-@admin.route('/admin/')
-@login_required
-def admin_index():
-    return render_template('admin/index.html')
-

resultsdb_frontend/controllers/login_page.py

-# Copyright 2013, Red Hat, Inc
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Authors:
-#   Josef Skladanka <jskladan@redhat.com>
-
-from flask import Blueprint, render_template, redirect, flash, url_for, request
-from flask.ext.wtf import Form, TextField, PasswordField, HiddenField
-from flask.ext.wtf import Required
-from flask.ext.login import login_user, logout_user, login_required, current_user, AnonymousUserMixin
-
-
-from resultsdb_frontend import app, login_manager
-from resultsdb_frontend.models.user import User
-
-login_page = Blueprint('login_page', __name__)
-
-
-class LoginForm(Form):
-    username = TextField(u'Username', validators = [Required()])
-    password = PasswordField(u'Password', validators = [Required()])
-    next_page = HiddenField()
-
-
-# handle login stuff
-@login_manager.user_loader
-def load_user(userid):
-    app.logger.debug("getting info for user %s" % str(userid))
-    user = User.query.get(userid)
-    if user:
-        return user
-    else:
-        return AnonymousUserMixin
-
-
-@login_page.route('/login', methods=['GET', 'POST'])
-def login():
-    login_form = LoginForm()
-
-    if login_form.validate_on_submit():
-        user = User.query.filter_by(username = login_form.username.data).first()
-        if user and user.check_password(login_form.password.data):
-            login_user(user)
-
-            app.logger.info('Successful login for user %s' % login_form.username.data)
-            flash('Logged In Successfully!')
-
-            return redirect(login_form.next_page.data)
-        else:
-            app.logger.info('FAILED login for user %s' % login_form.username.data)
-            flash('Login Failed! Please Try again!')
-
-    login_form.next_page.data = request.args.get('next') or url_for('main.index')
-    return render_template('login.html', form = login_form)
-
-
-@login_page.route('/logout')
-@login_required
-def logout():
-    app.logger.info('logout for user %s' % current_user.username)
-    logout_user()
-    flash('Logged Out Successfully!')
-    return redirect(url_for('main.index'))
-
-
-

resultsdb_frontend/models/__init__.py

-#
-# __init__.py - base model classes
-#
-

resultsdb_frontend/models/user.py

-# Copyright 2013, Red Hat, Inc
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Authors:
-#   Josef Skladanka <jskladan@redhat.com>
-
-
-from resultsdb_frontend import db
-from flask.ext.login import UserMixin
-from werkzeug.security import generate_password_hash, check_password_hash
-
-class User(db.Model, UserMixin):
-
-    id = db.Column(db.Integer, primary_key=True)
-    username = db.Column(db.String(80), unique=True)
-    pw_hash = db.Column(db.String(120), unique=False)
-
-    def __init__(self, username, password):
-        self.username = username
-        self.set_password(password)
-
-    def __repr__(self):
-        return '<User %r>' % self.username
-
-    def set_password(self, password):
-        self.pw_hash = generate_password_hash(password)
-
-    def check_password(self, password):
-        return check_password_hash(self.pw_hash, password)
-

resultsdb_frontend/templates/login.html

-{% extends "layout.html" %}
-
-{% from "_formhelpers.html" import form_field %}
-
-{% block body %}
-
-<div class="row">
-<div class="col-md-4">
-<form method="post" action="login">
-    {{ form.csrf_token }}
-    {{ form.next_page }}
-    {{ form_field(form.username) }}
-    {{ form_field(form.password) }}
-    <input type="submit" class="btn btn-success" value="Login"/>
-</form>
-</div>
-</div>
-
-{% endblock %}

run_cli.py

-import sys
-from resultsdb_frontend import cli
-
-if __name__ == '__main__':
-    exit = cli.main()
-    if exit:
-        sys.exit(exit)
-
       author='Josef Skladanka',
       author_email='jskladan@redhat.com',
       license='GPLv2+',
-      packages=['resultsdb_frontend', 'resultsdb_frontend.controllers', 'resultsdb_frontend.models'],
+      packages=['resultsdb_frontend', 'resultsdb_frontend.controllers'],
       package_dir={'resultsdb_frontend':'resultsdb_frontend'},
-      entry_points=dict(console_scripts=['resultsdb_frontend=resultsdb_frontend.cli:main']),
       include_package_data=True,
      )