Beispiel #1
0
def do_remote_automation(site, command, vars_, files=None, timeout=None):
    auto_logger.info("RUN [%s]: %s", site, command)
    auto_logger.debug("VARS: %r", vars_)

    base_url = site["multisiteurl"]
    secret = site.get("secret")
    if not secret:
        raise MKAutomationException(
            _("You are not logged into the remote site."))

    url = (
        base_url + "automation.py?" +
        URLEncoder().urlencode_vars([("command", command), ("secret", secret),
                                     ("debug", config.debug and '1' or '')]))

    response = get_url(url,
                       site.get('insecure', False),
                       data=dict(vars_),
                       files=files,
                       timeout=timeout)

    auto_logger.debug("RESPONSE: %r", response)

    if not response:
        raise MKAutomationException(_("Empty output from remote site."))

    try:
        response = ast.literal_eval(response)
    except SyntaxError:
        # The remote site will send non-Python data in case of an error.
        raise MKAutomationException("%s: <pre>%s</pre>" %
                                    (_("Got invalid data"), response))

    return response
Beispiel #2
0
def makeuri_contextless(
    request: Request,
    vars_: HTTPVariables,
    filename: Optional[str] = None,
) -> str:
    if not filename:
        filename = requested_file_name(request) + '.py'
    if vars_:
        return filename + "?" + URLEncoder.urlencode_vars(vars_)
    return filename
Beispiel #3
0
def makeuri(
    request: Request,
    addvars: HTTPVariables,
    filename: Optional[str] = None,
    remove_prefix: Optional[str] = None,
    delvars: Optional[Sequence[str]] = None,
) -> str:
    new_vars = [nv[0] for nv in addvars]
    vars_: HTTPVariables = [(v, val) for v, val in request.itervars()
                            if v[0] != "_" and v not in new_vars and (
                                not delvars or v not in delvars)]
    if remove_prefix is not None:
        vars_ = [i for i in vars_ if not i[0].startswith(remove_prefix)]
    vars_ = vars_ + addvars
    if filename is None:
        filename = URLEncoder.urlencode(requested_file_name(request)) + ".py"
    if vars_:
        return filename + "?" + URLEncoder.urlencode_vars(vars_)
    return filename
def test_urlencode(inp, out):
    result = URLEncoder().urlencode(inp)
    assert isinstance(result, str)
    assert result == out
Beispiel #5
0
 def __init__(self, endpoint: str, url_vars: Optional[HTTPVariables]):
     super().__init__(type='ajax')
     self.endpoint = endpoint if endpoint else None
     self.url_vars = URLEncoder().urlencode_vars(
         url_vars) if url_vars else None