def test_do_run(self): # Normally, do_run is only called by run() if the database has # not yet meen initialized. But we can test it by calling it # directly. timestamp = get_one( self._db, Timestamp, service=u"Database Migration", service_type=Timestamp.SCRIPT_TYPE ) eq_(None, timestamp) # Remove all secret keys, should they exist, before running the # script. secret_keys = self._db.query(ConfigurationSetting).filter( ConfigurationSetting.key==Configuration.SECRET_KEY) [self._db.delete(secret_key) for secret_key in secret_keys] script = InstanceInitializationScript(_db=self._db) script.do_run(ignore_search=True) # It initializes the database. timestamp = get_one( self._db, Timestamp, service=u"Database Migration", service_type=Timestamp.SCRIPT_TYPE ) assert timestamp # It creates a secret key. eq_(1, secret_keys.count()) eq_( secret_keys.one().value, ConfigurationSetting.sitewide_secret(self._db, Configuration.SECRET_KEY) )
def setup_admin(_db=None): if getattr(app, 'manager', None) is not None: setup_admin_controllers(app.manager) _db = _db or app._db # The secret key is used for signing cookies for admin login app.secret_key = ConfigurationSetting.sitewide_secret( _db, Configuration.SECRET_KEY)
def test_run(self): timestamp = get_one( self._db, Timestamp, service=u"Database Migration", service_type=Timestamp.SCRIPT_TYPE ) eq_(None, timestamp) # Remove all secret keys, should they exist, before running the # script. secret_keys = self._db.query(ConfigurationSetting).filter( ConfigurationSetting.key==Configuration.SECRET_KEY) [self._db.delete(secret_key) for secret_key in secret_keys] script = InstanceInitializationScript(_db=self._db) script.do_run(ignore_search=True) # It initializes the database. timestamp = get_one( self._db, Timestamp, service=u"Database Migration", service_type=Timestamp.SCRIPT_TYPE ) assert timestamp # It creates a secret key. eq_(1, secret_keys.count()) eq_( secret_keys.one().value, ConfigurationSetting.sitewide_secret(self._db, Configuration.SECRET_KEY) )
def setup_admin(_db=None): if getattr(app, 'manager', None) is not None: setup_admin_controllers(app.manager) _db = _db or app._db # The secret key is used for signing cookies for admin login app.secret_key = ConfigurationSetting.sitewide_secret( _db, Configuration.SECRET_KEY )
def setup_admin(_db=None): if getattr(app, "manager", None) is not None: setup_admin_controllers(app.manager) _db = _db or app._db # The secret key is used for signing cookies for admin login app.secret_key = ConfigurationSetting.sitewide_secret(_db, Configuration.SECRET_KEY) # Create a default Local Analytics service if one does not # already exist. local_analytics = LocalAnalyticsProvider.initialize(_db)
def do_run(self, ignore_search=False): # Creates a "-current" alias on the Elasticsearch client. if not ignore_search: try: search_client = ExternalSearchIndex(self._db) except CannotLoadConfiguration as e: # Elasticsearch isn't configured, so do nothing. pass # Set a timestamp that represents the new database's version. db_init_script = DatabaseMigrationInitializationScript(_db=self._db) existing = get_one(self._db, Timestamp, service=db_init_script.name) if existing: # No need to run the script. We already have a timestamp. return db_init_script.run() # Create a secret key if one doesn't already exist. ConfigurationSetting.sitewide_secret(self._db, Configuration.SECRET_KEY)
from controller import setup_admin_controllers from templates import ( admin_sign_in_again as sign_in_again_template, ) from api.routes import ( has_library, library_route, ) import csv, codecs, cStringIO from StringIO import StringIO import urllib from datetime import timedelta # The secret key is used for signing cookies for admin login app.secret_key = ConfigurationSetting.sitewide_secret(_db, Configuration.SECRET_KEY) # An admin's session will expire after this amount of time and # the admin will have to log in again. app.permanent_session_lifetime = timedelta(hours=9) @app.before_first_request def setup_admin(): if getattr(app, 'manager', None) is not None: setup_admin_controllers(app.manager) def allows_admin_auth_setup(f): @wraps(f) def decorated(*args, **kwargs):