def create_app(): """REANA Server application factory.""" logging.basicConfig(level=REANA_LOG_LEVEL, format=REANA_LOG_FORMAT) app = Flask(__name__) app.config.from_object('reana_server.config') app.secret_key = "hyper secret key" app.session = Session Babel(app) FlaskMenu(app) InvenioDB(app) InvenioAccounts(app) FlaskOAuth(app) InvenioOAuthClient(app) # Register Invenio OAuth endpoints app.register_blueprint(blueprint_user) app.register_blueprint(blueprint_client) app.register_blueprint(blueprint_settings) # Register API routes from .rest import gitlab, ping, secrets, users, workflows # noqa app.register_blueprint(ping.blueprint, url_prefix='/api') app.register_blueprint(workflows.blueprint, url_prefix='/api') app.register_blueprint(users.blueprint, url_prefix='/api') app.register_blueprint(secrets.blueprint, url_prefix='/api') app.register_blueprint(gitlab.blueprint, url_prefix='/api') return app
def app(request): """Flask application fixture.""" app_ = Flask('testapp') app_.config.update( TESTING=True, CELERY_ALWAYS_EAGER=True, CELERY_CACHE_BACKEND="memory", CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, CELERY_RESULT_BACKEND="cache", SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI', 'sqlite://'), SQLALCHEMY_TRACK_MODIFICATIONS=False, SECRET_KEY='mysecret', SUPPORT_EMAIL='*****@*****.**', WTF_CSRF_ENABLED=False, SERVER_NAME='test.it', RECORDS_UI_ENDPOINTS=dict( recid=dict( pid_type='recid', route='/records/<pid_value>', template='invenio_records_ui/detail.html', ), recid_access_request=dict( pid_type='recid', route='/records/<pid_value>/accessrequest', template='zenodo_accessrequests/access_request.html', view_imp='zenodo_accessrequests.views.requests.access_request', methods=['GET', 'POST'], ), recid_access_request_email_confirm=dict( pid_type='recid', route='/records/<pid_value>/accessrequest/<token>/confirm', # template='invenio_records_ui/detail.html', view_imp='zenodo_accessrequests.views.requests.confirm', ), ), ) InvenioFormatter(app_) Babel(app_) InvenioDB(app_) InvenioAccounts(app_) InvenioRecords(app_) FlaskMenu(app_) Mail(app_) InvenioRecordsUI(app_) InvenioAccess(app_) ZenodoAccessRequests(app_) InvenioPIDStore(app_) app_.register_blueprint(request_blueprint) app_.register_blueprint(settings_blueprint) app_.register_blueprint(blueprint_user) app_.register_blueprint(create_blueprint_from_app(app_)) with app_.app_context(): yield app_
def base_app(request): """Flask application fixture without ShibbolethAuthenticator init.""" instance_path = tempfile.mkdtemp() base_app = Flask('testapp') base_app.config.update( TESTING=True, WTF_CSRF_ENABLED=False, LOGIN_DISABLED=False, CACHE_TYPE='simple', SHIBBOLETH_REMOTE_APPS=dict( hzdr=dict(title='HZDR Shibboleth Authentication', saml_path='data/', mappings=dict( email='email_mapping', user_unique_id='id_mapping', full_name='full_name_mapping', ))), DEBUG=False, EMAIL_BACKEND='flask_email.backends.locmem.Mail', SQLALCHEMY_TRACK_MODIFICATIONS=False, SQLALCHEMY_DATABASE_URI=os.getenv('SQLALCHEMY_DATABASE_URI', 'sqlite://'), SERVER_NAME='localhost', SECRET_KEY='TEST', SECURITY_DEPRECATED_PASSWORD_SCHEMES=[], SECURITY_PASSWORD_HASH='plaintext', SECURITY_PASSWORD_SCHEMES=['plaintext'], ) FlaskMenu(base_app) InvenioDB(base_app) InvenioAccounts(base_app) Mail(base_app) with base_app.app_context(): if str(db.engine.url) != 'sqlite://' and \ not database_exists(str(db.engine.url)): create_database(str(db.engine.url)) db.create_all() def teardown(): with base_app.app_context(): db.session.close() if str(db.engine.url) != 'sqlite://': drop_database(str(db.engine.url)) print('Path: ' + instance_path) shutil.rmtree(instance_path) request.addfinalizer(teardown) base_app.test_request_context().push() return base_app
def base_app(request): """Flask application fixture without OAuthClient initialized.""" instance_path = tempfile.mkdtemp() base_app = Flask('testapp') base_app.config.update( TESTING=True, WTF_CSRF_ENABLED=False, LOGIN_DISABLED=False, CACHE_TYPE='simple', OAUTHCLIENT_REMOTE_APPS=dict( orcid=REMOTE_APP, ), ORCID_APP_CREDENTIALS=dict( consumer_key='changeme', consumer_secret='changeme', ), # use local memory mailbox EMAIL_BACKEND='flask_email.backends.locmem.Mail', SQLALCHEMY_DATABASE_URI=os.getenv('SQLALCHEMY_DATABASE_URI', 'sqlite://'), SERVER_NAME='localhost', DEBUG=False, SECRET_KEY='TEST', SECURITY_PASSWORD_HASH='plaintext', SECURITY_PASSWORD_SCHEMES=['plaintext'], ) FlaskCLI(base_app) FlaskMenu(base_app) Babel(base_app) Mail(base_app) InvenioDB(base_app) InvenioAccounts(base_app) with base_app.app_context(): if str(db.engine.url) != 'sqlite://' and \ not database_exists(str(db.engine.url)): create_database(str(db.engine.url)) db.create_all() def teardown(): with base_app.app_context(): db.session.close() if str(db.engine.url) != 'sqlite://': drop_database(str(db.engine.url)) shutil.rmtree(instance_path) request.addfinalizer(teardown) base_app.test_request_context().push() return base_app
def create_app(config_mapping=None): """REANA Server application factory.""" logging.basicConfig(level=REANA_LOG_LEVEL, format=REANA_LOG_FORMAT, force=True) app = Flask(__name__) app.config.from_object("reana_server.config") if config_mapping: app.config.from_mapping(config_mapping) app.secret_key = "hyper secret key" app.session = Session Babel(app) FlaskMenu(app) InvenioDB(app) InvenioAccounts(app) FlaskOAuth(app) InvenioOAuthClient(app) # Register Invenio OAuth endpoints app.register_blueprint(blueprint_user) app.register_blueprint(blueprint_client) app.register_blueprint(blueprint_settings) # Register API routes from .rest import ( config, gitlab, ping, secrets, status, users, workflows, info, ) # noqa app.register_blueprint(ping.blueprint, url_prefix="/api") app.register_blueprint(workflows.blueprint, url_prefix="/api") app.register_blueprint(users.blueprint, url_prefix="/api") app.register_blueprint(secrets.blueprint, url_prefix="/api") app.register_blueprint(gitlab.blueprint, url_prefix="/api") app.register_blueprint(config.blueprint, url_prefix="/api") app.register_blueprint(status.blueprint, url_prefix="/api") app.register_blueprint(info.blueprint, url_prefix="/api") @app.teardown_appcontext def shutdown_session(response_or_exc): """Close session on app teardown.""" current_app.session.remove() return response_or_exc return app
def gen_app(config): """Generate a fresh app.""" app = Flask('testapp') app.testing = True app.config.update(**config) FlaskCLI(app) FlaskMenu(app) Babel(app) Mail(app) InvenioDB(app) InvenioAccounts(app) FlaskOAuth(app) InvenioOAuthClient(app) app.register_blueprint(blueprint_client) app.register_blueprint(blueprint_settings) with app.app_context(): db.create_all() app.test_request_context().push() datastore = app.extensions['invenio-accounts'].datastore datastore.create_user(email="*****@*****.**", password='******', active=True) datastore.create_user(email="*****@*****.**", password='******', active=True) datastore.create_user(email="*****@*****.**", password='******', active=True) datastore.commit() return app
SQLALCHEMY_ECHO=False, SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI', 'sqlite:///orcid_app_rest.db'), OAUTHCLIENT_REST_REMOTE_APPS=dict(orcid=orcid.REMOTE_SANDBOX_REST_APP, ), ORCID_APP_CREDENTIALS=ORCID_APP_CREDENTIALS, DEBUG=True, SECRET_KEY='TEST', SECURITY_PASSWORD_SALT='security-password-salt', SECURITY_LOGIN_WITHOUT_CONFIRMATION=False, USERPROFILES_EXTEND_SECURITY_FORMS=True, SQLALCHEMY_TRACK_MODIFICATIONS=False, APP_THEME=['semantic-ui'], THEME_ICONS={'semantic-ui': dict(link='linkify icon')}) Babel(app) FlaskMenu(app) Mail(app) InvenioDB(app) InvenioAccounts(app) InvenioUserProfiles(app) FlaskOAuth(app) InvenioOAuthClientREST(app) app.register_blueprint(blueprint_user) app.register_blueprint(blueprint_client) app.register_blueprint(blueprint_userprofile_api_init) app.register_blueprint(blueprint_userprofile_ui_init) @app.route('/') def index():
def base_app(request): """Flask application fixture without OAuthClient initialized.""" # allow HTTP for keycloak tests, and create the KEYCLOAK_REMOTE_APP os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1" base_url, realm = "http://localhost:8080", "test" helper = KeycloakSettingsHelper(title="Keycloak", description="", base_url=base_url, realm=realm) KEYCLOAK_REMOTE_APP = helper.remote_app instance_path = tempfile.mkdtemp() base_app = Flask('testapp') base_app.config.update( ACCOUNTS_LOCAL_LOGIN_ENABLED=True, TESTING=True, WTF_CSRF_ENABLED=False, LOGIN_DISABLED=False, CACHE_TYPE='simple', OAUTHCLIENT_SIGNUP_FORM=_create_registrationform, OAUTHCLIENT_REMOTE_APPS=dict( cern=CERN_REMOTE_APP, cern_openid=CERN_OPENID_REMOTE_APP, orcid=ORCID_REMOTE_APP, github=GITHUB_REMOTE_APP, globus=GLOBUS_REMOTE_APP, keycloak=KEYCLOAK_REMOTE_APP, ), OAUTHCLIENT_REST_REMOTE_APPS=dict( cern=CERN_REMOTE_REST_APP, cern_openid=CERN_OPENID_REMOTE_REST_APP, orcid=ORCID_REMOTE_REST_APP, github=GITHUB_REMOTE_REST_APP, globus=GLOBUS_REMOTE_REST_APP, ), OAUTHCLIENT_STATE_EXPIRES=300, GITHUB_APP_CREDENTIALS=dict( consumer_key='github_key_changeme', consumer_secret='github_secret_changeme', ), ORCID_APP_CREDENTIALS=dict( consumer_key='orcid_key_changeme', consumer_secret='orcid_secret_changeme', ), CERN_APP_CREDENTIALS=dict( consumer_key='cern_key_changeme', consumer_secret='cern_secret_changeme', ), CERN_APP_OPENID_CREDENTIALS=dict( consumer_key='cern_key_changeme', consumer_secret='cern_secret_changeme', ), GLOBUS_APP_CREDENTIALS=dict( consumer_key='globus_key_changeme', consumer_secret='globus_secret_changeme', ), TEST_APP_CREDENTIALS=dict( consumer_key='test_key_changeme', consumer_secret='test_secret_changeme', ), OAUTHCLIENT_KEYCLOAK_USER_INFO_URL=helper.user_info_url, OAUTHCLIENT_KEYCLOAK_REALM_URL=helper.realm_url, OAUTHCLIENT_KEYCLOAK_VERIFY_AUD=True, OAUTHCLIENT_KEYCLOAK_VERIFY_EXP=False, OAUTHCLIENT_KEYCLOAK_AUD="invenio", KEYCLOAK_APP_CREDENTIALS=dict( consumer_key="keycloak_key_changeme", consumer_secret="keycloak_secret_changeme", ), # use local memory mailbox EMAIL_BACKEND='flask_email.backends.locmem.Mail', SQLALCHEMY_DATABASE_URI=os.getenv('SQLALCHEMY_DATABASE_URI', 'sqlite://'), # Alembic runs all migrations in a single transaction, and in # oauthclient the useridentity table can be in state where it's created # and then deleted in the same transaction. On PostgreSQL which # supports transactional DDL therefore fails if we don't run each # migration in its own migration. ALEMBIC_CONTEXT={ 'transaction_per_migration': True, }, SERVER_NAME='localhost', DEBUG=False, SECRET_KEY='TEST', SECURITY_DEPRECATED_PASSWORD_SCHEMES=[], SQLALCHEMY_TRACK_MODIFICATIONS=False, SECURITY_PASSWORD_HASH='plaintext', SECURITY_PASSWORD_SCHEMES=['plaintext'], APP_ALLOWED_HOSTS=['localhost'], APP_THEME=['semantic-ui'], THEME_ICONS={'semantic-ui': dict(link='linkify icon')}) FlaskMenu(base_app) Babel(base_app) Mail(base_app) InvenioDB(base_app) InvenioAccounts(base_app) with base_app.app_context(): if str(db.engine.url) != 'sqlite://' and \ not database_exists(str(db.engine.url)): create_database(str(db.engine.url)) db.create_all() def teardown(): with base_app.app_context(): db.session.close() if str(db.engine.url) != 'sqlite://': drop_database(str(db.engine.url)) shutil.rmtree(instance_path) db.engine.dispose() request.addfinalizer(teardown) base_app.test_request_context().push() return base_app