async def add_module(request): """Creates a new routing rule and forwards the user to the rule edit page.""" try: config.read_config() except: return PlainTextResponse( "Configuration is being updated. Try again in a minute.") form = dict(await request.form()) name = form.get("name", "") if name in config.mercure["modules"]: return PlainTextResponse("Name already exists.") config.mercure["modules"][name] = { "url": form.get("url", ""), "docker_tag": form.get("docker_tag", None) } try: config.save_config() except: return PlainTextResponse( "ERROR: Unable to write configuration. Try again.") # logger.info(f'Created rule {newrule}') # monitor.send_webgui_event(monitor.w_events.RULE_CREATE, request.user.display_name, newrule) return RedirectResponse(url="/modules/", status_code=303)
async def targes_edit_post(request): """Updates the given target using the form values posted with the request.""" try: config.read_config() except: return PlainTextResponse( 'Configuration is being updated. Try again in a minute.') edittarget = request.path_params["target"] form = dict(await request.form()) if not edittarget in config.mercure["targets"]: return PlainTextResponse('Target does not exist anymore.') config.mercure["targets"][edittarget]["ip"] = form["ip"] config.mercure["targets"][edittarget]["port"] = form["port"] config.mercure["targets"][edittarget]["aet_target"] = form["aet_target"] config.mercure["targets"][edittarget]["aet_source"] = form["aet_source"] config.mercure["targets"][edittarget]["contact"] = form["contact"] try: config.save_config() except: return PlainTextResponse( 'ERROR: Unable to write configuration. Try again.') logger.info(f'Edited target {edittarget}') monitor.send_webgui_event(monitor.w_events.TARGET_EDIT, request.user.display_name, edittarget) return RedirectResponse(url='/targets', status_code=303)
async def add_rule(request): """Creates a new routing rule and forwards the user to the rule edit page.""" try: config.read_config() except: return PlainTextResponse( 'Configuration is being updated. Try again in a minute.') form = dict(await request.form()) newrule = form.get("name", "") if newrule in config.mercure["rules"]: return PlainTextResponse('Rule already exists.') config.mercure["rules"][newrule] = {"rule": "False"} try: config.save_config() except: return PlainTextResponse( 'ERROR: Unable to write configuration. Try again.') logger.info(f'Created rule {newrule}') monitor.send_webgui_event(monitor.w_events.RULE_CREATE, request.user.display_name, newrule) return RedirectResponse(url='/rules/edit/' + newrule, status_code=303)
async def add_target(request): """Creates a new target.""" try: config.read_config() except: return PlainTextResponse( 'Configuration is being updated. Try again in a minute.') form = dict(await request.form()) newtarget = form.get("name", "") if newtarget in config.mercure["targets"]: return PlainTextResponse('Target already exists.') config.mercure["targets"][newtarget] = {"ip": "", "port": ""} try: config.save_config() except: return PlainTextResponse( 'ERROR: Unable to write configuration. Try again.') logger.info(f'Created target {newtarget}') monitor.send_webgui_event(monitor.w_events.TARGET_CREATE, request.user.display_name, newtarget) return RedirectResponse(url='/targets/edit/' + newtarget, status_code=303)
async def rules_edit_post(request): """Updates the settings for the given routing rule.""" try: config.read_config() except: return PlainTextResponse( "Configuration is being updated. Try again in a minute.") editrule = request.path_params["rule"] form = dict(await request.form()) if not editrule in config.mercure["rules"]: return PlainTextResponse("Rule does not exist anymore.") config.mercure["rules"][editrule]["rule"] = form.get("rule", "False") config.mercure["rules"][editrule]["target"] = form.get("target", "") config.mercure["rules"][editrule]["disabled"] = form.get( "status_disabled", "False") config.mercure["rules"][editrule]["fallback"] = form.get( "status_fallback", "False") config.mercure["rules"][editrule]["contact"] = form.get("contact", "") config.mercure["rules"][editrule]["comment"] = form.get("comment", "") config.mercure["rules"][editrule]["tags"] = form.get("tags", "") config.mercure["rules"][editrule]["action"] = form.get("action", "route") config.mercure["rules"][editrule]["action_trigger"] = form.get( "action_trigger", "series") config.mercure["rules"][editrule]["study_trigger_condition"] = form.get( "study_trigger_condition", "timeout") config.mercure["rules"][editrule]["study_trigger_series"] = form.get( "study_trigger_series", "") config.mercure["rules"][editrule]["priority"] = form.get( "priority", "normal") config.mercure["rules"][editrule]["processing_module"] = form.get( "processing_module", "") config.mercure["rules"][editrule]["processing_settings"] = form.get( "processing_settings", "") config.mercure["rules"][editrule]["notification_webhook"] = form.get( "notification_webhook", "") config.mercure["rules"][editrule]["notification_payload"] = form.get( "notification_payload", "") config.mercure["rules"][editrule][ "notification_trigger_reception"] = form.get( "notification_trigger_reception", "False") config.mercure["rules"][editrule][ "notification_trigger_completion"] = form.get( "notification_trigger_completion", "False") config.mercure["rules"][editrule]["notification_trigger_error"] = form.get( "notification_trigger_error", "False") try: config.save_config() except: return PlainTextResponse( "ERROR: Unable to write configuration. Try again.") logger.info(f"Edited rule {editrule}") monitor.send_webgui_event(monitor.w_events.RULE_EDIT, request.user.display_name, editrule) return RedirectResponse(url="/rules", status_code=303)
def delete_repository(name): """ Deletes a configured Maven repository. """ config = load_config() section_name = repo_section_name(name) if config.has_section(section_name): config.remove_section(section_name) save_config(config)
def set_stagedir(path): """ Sets the output directory where dependencies will be staged. :param path: path where the downloaded mvnfeed will be staged """ config = load_config() if "general" not in config: config.add_section("general") config.set("general", STAGE_DIR_CONFIGNAME, path) save_config(config)
async def save_module(form, name): """We already read the config by this time""" config.mercure["modules"][name] = { "url": form.get("url", ""), "docker_tag": form.get("docker_tag", None), "additional_volumes": form.get("additional_volumes", None), "environment": form.get("environment", None), "docker_arguments": form.get("docker_arguments", None) } try: config.save_config() except: return PlainTextResponse( "ERROR: Unable to write configuration. Try again.") return RedirectResponse(url="/modules/", status_code=303)
async def delete_module(request): """Creates a new routing rule and forwards the user to the rule edit page.""" try: config.read_config() except: return PlainTextResponse( "Configuration is being updated. Try again in a minute.") name = request.path_params["module"] if name in config.mercure["modules"]: del config.mercure["modules"][name] try: config.save_config() except: return PlainTextResponse( "ERROR: Unable to write configuration. Try again.") # logger.info(f'Created rule {newrule}') # monitor.send_webgui_event(monitor.w_events.RULE_CREATE, request.user.display_name, newrule) return RedirectResponse(url="/modules/", status_code=303)
async def targets_delete_post(request): """Deletes the given target.""" try: config.read_config() except: return PlainTextResponse("Configuration is being updated. Try again in a minute.") deletetarget = request.path_params["target"] if deletetarget in config.mercure["targets"]: del config.mercure["targets"][deletetarget] try: config.save_config() except: return PlainTextResponse("ERROR: Unable to write configuration. Try again.") logger.info(f"Deleted target {deletetarget}") monitor.send_webgui_event(monitor.w_events.TARGET_DELETE, request.user.display_name, deletetarget) return RedirectResponse(url="/targets", status_code=303)
async def rules_delete_post(request): """Deletes the given routing rule""" try: config.read_config() except: return PlainTextResponse("Configuration is being updated. Try again in a minute.") deleterule = request.path_params["rule"] if deleterule in config.mercure["rules"]: del config.mercure["rules"][deleterule] try: config.save_config() except: return PlainTextResponse("ERROR: Unable to write configuration. Try again.") logger.info(f"Deleted rule {deleterule}") monitor.send_webgui_event(monitor.w_events.RULE_DELETE, request.user.display_name, deleterule) return RedirectResponse(url="/rules", status_code=303)
def add_repository(name, username, url=None): """ Adds an external Maven repository. :param name: internal name of the repository :param username: name of the user for the basic authentication to the repository :param url: url of the repository """ if username is None: raise ValueError("Username must be defined") if url is None: raise ValueError("Url must be defined") password = getpass.getpass() encoded = base64.b64encode((username + ":" + password).encode("utf-8")) authorization = "Basic " + encoded.decode("utf-8") config = load_config() config[repo_section_name(name)] = { URL: _default_value(url), AUTHORIZATION: _default_value(authorization), } save_config(config)