Exemplo n.º 1
0
def add_to_event_context(context: EventContext, prefix: str, param: object) -> None:
    if isinstance(param, (list, tuple)):
        if all(isinstance(p, str) for p in param):
            # TODO: Why on earth do we have these arbitrary differences? Can we unify this?
            suffix, separator = ("S", " ") if isinstance(param, list) else ("", "\t")
            add_to_event_context(context, prefix + suffix, separator.join(param))
        for nr, value in enumerate(param, start=1):
            add_to_event_context(context, f"{prefix}_{nr}", value)
    elif isinstance(param, dict):  # NOTE: We only handle Dict[str, Any].
        for key, value in param.items():
            varname = f"{prefix}_{key.upper()}"
            if varname == "PARAMETER_PROXY_URL":
                # Compatibility for 1.5 pushover explicitly configured proxy URL format
                if isinstance(value, str):
                    value = ("url", value)
                value = config.get_http_proxy(value)
                if value is None:
                    continue
            add_to_event_context(context, varname, value)
    elif isinstance(param, (str, int, float)):  # NOTE: bool is a subclass of int!
        context[prefix] = str(param)
    elif param is None:
        context[prefix] = ""
    else:
        context[prefix] = repr(param)  # Should never happen
Exemplo n.º 2
0
def get_http_proxy(http_proxy: Tuple[str, str]) -> Optional[str]:
    """Returns proxy URL to be used for HTTP requests

    Pass a value configured by the user using the HTTPProxyReference valuespec to this function
    and you will get back ether a proxy URL, an empty string to enforce no proxy usage or None
    to use the proxy configuration from the process environment.
    """
    return _config.get_http_proxy(http_proxy)
Exemplo n.º 3
0
def add_to_event_context(plugin_context, prefix, param):
    # type: (EventContext, str, Union[List, Dict]) -> None
    if isinstance(param, list):
        plugin_context[prefix + "S"] = " ".join(param)
        for nr, value in enumerate(param):
            add_to_event_context(plugin_context, "%s_%d" % (prefix, nr + 1), value)
    elif isinstance(param, dict):
        for key, value in param.items():
            varname = "%s_%s" % (prefix, key.upper())

            if varname == "PARAMETER_PROXY_URL":
                # Compatibility for 1.5 pushover explicitly configured proxy URL format
                if isinstance(value, str):
                    value = ("url", value)

                value = config.get_http_proxy(value)
                if value is None:
                    continue

            add_to_event_context(plugin_context, varname, value)
    else:
        plugin_context[prefix] = plugin_param_to_string(param)
Exemplo n.º 4
0
def get_http_proxy(http_proxy: Tuple[str, str]) -> HTTPProxyConfig:
    """Returns a proxy config object to be used for HTTP requests

    Intended to receive a value configured by the user using the HTTPProxyReference valuespec.
    """
    return _config.get_http_proxy(http_proxy)