def validate_plugin_config(plugin: PluginRef, name, value, project: Project, settings: PluginSettingsService): setting_def = settings.find_setting(plugin, name) # we want to prevent the edition of protected settings from the UI if setting_def.protected: logging.warning("Cannot set a 'protected' configuration externally.") return False if setting_def.kind == "file" and value and value != "": uploads_directory = project.extract_dir(plugin.full_name) resolved_file_path = project.root_dir(value).resolve() if not str(resolved_file_path).startswith( str(uploads_directory) + "/"): logging.warning( "Cannot set a file configuration to a path outside the project directory" ) return False old_value, source = settings.get_value(db.session, plugin, name) if source in (PluginSettingValueSource.ENV, PluginSettingValueSource.MELTANO_YML): logging.warning( "Cannot override a configuration set in the environment or meltano.yml." ) return False return True
def save_plugin_configuration(plugin_ref) -> Response: """ endpoint for persisting a plugin configuration """ project = Project.find() payload = request.get_json() settings = PluginSettingsService(project) for name, value in payload.items(): # we want to prevent the edition of protected settings from the UI if settings.find_setting(plugin_ref, name).get("protected"): logging.warning( "Cannot set a 'protected' configuration externally.") continue if value == "": settings.unset(db.session, plugin_ref, name) else: settings.set(db.session, plugin_ref, name, value) return jsonify(settings.as_config(db.session, plugin_ref, redacted=True))
def validate_plugin_config(plugin: PluginRef, name, value, project: Project, settings: PluginSettingsService): setting_def = settings.find_setting(name) # we want to prevent the edition of protected settings from the UI if setting_def.protected: logging.warning("Cannot set a 'protected' setting externally.") return False if setting_def.kind == "file" and value and value != "": uploads_directory = project.extract_dir(plugin.name) resolved_file_path = project.root_dir(value).resolve() if not str(resolved_file_path).startswith( str(uploads_directory) + "/"): logging.warning( "Cannot set a file configuration to a path outside the project directory" ) return False old_value, metadata = settings.get_with_metadata(name, session=db.session) if not metadata["overwritable"]: logging.warning("Cannot overwrite this setting.") return False return True