def _get_flask_app(): for value, envvar in [ (REST_CONFIG_PATH, 'MANAGER_REST_CONFIG_PATH'), (REST_SECURITY_CONFIG_PATH, 'MANAGER_REST_SECURITY_CONFIG_PATH'), ]: if value is not None: environ[envvar] = value app = setup_flask_app() set_admin_current_user(app) return app
def setup_environment(): for value, envvar in [ (REST_CONFIG_PATH, 'MANAGER_REST_CONFIG_PATH'), (REST_SECURITY_CONFIG_PATH, 'MANAGER_REST_SECURITY_CONFIG_PATH'), ]: if value is not None: environ[envvar] = value app = setup_flask_app() with app.app_context(): config.instance.load_configuration() set_admin_current_user(app)
def _setup_current_user(): """Change the anonymous user to be admin, in order to have arbitrary access to the storage manager (which otherwise requires a valid user) """ admin_user = set_admin_current_user(server.app) login_manager = server.app.extensions['security'].login_manager login_manager.anonymous_user = MagicMock(return_value=admin_user)
def _get_storage_manager(self, tenant_name): app = flask_utils.setup_flask_app() admin = flask_utils.set_admin_current_user(app) storage_manager = get_storage_manager() tenant = flask_utils.get_tenant_by_name(tenant_name) self._set_tenant_in_app(tenant, app, storage_manager, admin) return storage_manager
def _setup_current_user(): """Change the anonymous user to be admin, in order to have arbitrary access to the storage manager (which otherwise requires a valid user) """ admin_user = set_admin_current_user(server.app) login_manager = server.app.extensions['security'].login_manager login_manager.anonymous_user = MagicMock(return_value=admin_user)
def set_ldap(config_dict): app = setup_flask_app() # Mock current user, and reload rest configuration set_admin_current_user(app) config.instance.load_from_file(CONFIG_FILE_LOCATION) # Update the config table on manager DB to include LDAP configurations config.instance.update_db(config_dict) # Restart the rest service to load the new LDAP configuration os.system('systemctl restart cloudify-restservice') # Wait for rest service to reload, up to 5 seconds end = time.time() + 5 while not time.time() > end: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) p_open = sock.connect_ex(("localhost", 80)) == 0 if p_open: break
def set_ldap(config_dict): app = setup_flask_app() # Mock current user, and reload rest configuration set_admin_current_user(app) config.instance.load_from_file(CONFIG_FILE_LOCATION) # Update the config table on manager DB to include LDAP configurations config.instance.update_db(config_dict) # Restart the rest service to load the new LDAP configuration os.system('systemctl restart cloudify-restservice') # Wait for rest service to reload, up to 5 seconds end = time.time() + 5 while not time.time() > end: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) p_open = sock.connect_ex(("localhost", 80)) == 0 if p_open: break
def setup_flask_app(tenant_name): app = flask_utils.setup_flask_app() flask_utils.set_admin_current_user(app) tenant = flask_utils.get_tenant_by_name(tenant_name) flask_utils.set_tenant_in_app(tenant)
def setup_flask_app(tenant_name): app = flask_utils.setup_flask_app() config.instance.load_configuration() flask_utils.set_admin_current_user(app) tenant = flask_utils.get_tenant_by_name(tenant_name) flask_utils.set_tenant_in_app(tenant)
def setup_flask_app(tenant_name): app = flask_utils.setup_flask_app() flask_utils.set_admin_current_user(app) tenant = flask_utils.get_tenant_by_name(tenant_name) flask_utils.set_tenant_in_app(tenant)