def create_app(config_file=None): app = Flask(__name__) auth = HTTPDigestAuth() app.config.setdefault('PYGMENTS_STYLE', 'friendly') app.config.setdefault('PYGMENTS_LINENOS', True) app.config.setdefault('PER_PAGE', 20) app.config.setdefault('SQLALCHEMY_DATABASE_URI', 'sqlite:////tmp/ownpaste.db') app.config.setdefault('REALM', 'ownpaste') app.config.setdefault('USERNAME', 'ownpaste') app.config.setdefault('PASSWORD', auth.a1('test', app.config['USERNAME'], app.config['REALM'])) app.config.setdefault('IP_BLOCK_HITS', 10) app.config.setdefault('IP_BLOCK_TIMEOUT', 60) # in minutes app.config.setdefault('TIMEZONE', 'UTC') app.config.from_envvar('OWNPASTE_SETTINGS', True) if config_file is not None: app.config.from_pyfile(config_file) db.init_app(app) # register default error handler # based on: http://flask.pocoo.org/snippets/15/ for _exc in default_exceptions: app.error_handler_spec[None][_exc] = error_handler del _exc app.error_handler_spec[None][401] = auth.challenge app.register_blueprint(views) @app.before_first_request def before_first_request(): if (not app.debug) and app.config['PASSWORD'] == auth.a1('test'): raise RuntimeError('You should provide a password!!') return app
def run(self): auth = HTTPDigestAuth() p1 = prompt_pass('Password') p2 = prompt_pass('Retype password') if p1 != p2: print >> sys.stderr, 'Passwords didn\'t match.' return print print 'Add this to your configuration file:' print 'PASSWORD = \'%s\'' % auth.a1(p1)