Fixing poc.
This commit is contained in:
+3
-1
@@ -149,7 +149,9 @@ disable=print-statement,
|
||||
unused-argument,
|
||||
no-value-for-parameter,
|
||||
missing-docstring,
|
||||
fixme
|
||||
fixme,
|
||||
broad-except,
|
||||
redefined-builtin
|
||||
|
||||
|
||||
# Enable the message, report, category or checker with the given id(s). You can
|
||||
|
||||
+8
-4
@@ -14,17 +14,21 @@ def kroute():
|
||||
@click.option("-X", "--method", default="GET")
|
||||
@click.option("--url", envvar='KAPOW_URL')
|
||||
@click.argument("url_pattern", nargs=1)
|
||||
@click.argument("command_file")
|
||||
@click.argument("command_file", required=False)
|
||||
def add(url_pattern, entrypoint, command, method, url, command_file):
|
||||
if command:
|
||||
# Command is given inline
|
||||
source = command
|
||||
elif command_file is None:
|
||||
# No command
|
||||
source = ""
|
||||
elif command_file == '-':
|
||||
# Read commands from stdin
|
||||
source = sys.stdin.read()
|
||||
elif command_file is not None:
|
||||
else:
|
||||
# Read commands from a file
|
||||
with open(command_file, 'r', encoding='utf-8') as handler:
|
||||
source = handler.read()
|
||||
else:
|
||||
source = ""
|
||||
|
||||
response = requests.post(f"{url}/routes",
|
||||
json={"method": method,
|
||||
|
||||
@@ -1,30 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
touch input
|
||||
touch output
|
||||
tail -F input | tr '[:lower:]' '[:upper:]' > output &
|
||||
kroute add -X POST --entrypoint ./topdf '/convert/{from}/pdf'
|
||||
|
||||
|
||||
kroute add -X POST --entrypoint /home/nil/Project/kapow/kapow2/examples/topdf '/convert/{from}/pdf'
|
||||
|
||||
|
||||
kroute add -X POST --entrypoint /bin/zsh '/convert/{from}/{to}' - <<-'EOF'
|
||||
kroute add -X POST --entrypoint '/bin/zsh -c' '/convert/{from}/{to}' - <<-'EOF'
|
||||
pandoc --from=$(request /match/from) --to=$(request /match/to) --output=>(response /body) =(request /body)
|
||||
EOF
|
||||
|
||||
kroute add -X GET '/formats/input' - <<-EOF
|
||||
kroute add -X GET '/formats/input' - <<-'EOF'
|
||||
pandoc --list-input-formats | response /body
|
||||
EOF
|
||||
|
||||
kroute add '/formats/output' - <<-EOF
|
||||
pandoc --list-output-formats | grep -v pdf | response /body
|
||||
EOF
|
||||
|
||||
kroute add '/tail' - <<-EOF
|
||||
tail -f /tmp/mispelotas | response /stream
|
||||
EOF
|
||||
|
||||
kroute add -X POST '/tr' --command '
|
||||
request /body >> input
|
||||
tail -n1 output | response /body
|
||||
'
|
||||
kroute add -X GET '/formats/output' -c 'pandoc --list-output-formats | grep -v pdf | response /body'
|
||||
|
||||
@@ -161,18 +161,18 @@ def handle_route(entrypoint, command):
|
||||
connection = CONNECTIONS[id] = ConnectionHandler(request)
|
||||
|
||||
executable, *params = shlex.split(entrypoint)
|
||||
args = ' '.join([shlex.quote(token) for token in params] + [shlex.quote(command)])
|
||||
args = ' '.join([executable] + [shlex.quote(token) for token in params] + [shlex.quote(command)])
|
||||
|
||||
# Run the source
|
||||
shell_task = await asyncio.create_subprocess_exec(
|
||||
shell_task = await asyncio.create_subprocess_shell(
|
||||
args,
|
||||
executable=executable,
|
||||
env={**os.environ,
|
||||
"KAPOW_URL": "http://localhost:8080/kapow",
|
||||
"KAPOW_CONNECTION": id,
|
||||
"PATH": ":".join([os.path.join(os.path.dirname(os.path.realpath(__file__)), "bin"),
|
||||
os.environ["PATH"]]),
|
||||
},
|
||||
shell=False)
|
||||
stdin=asyncio.subprocess.DEVNULL)
|
||||
await shell_task.wait()
|
||||
|
||||
del CONNECTIONS[id]
|
||||
@@ -193,7 +193,6 @@ async def get_routes(request):
|
||||
async def create_route(request):
|
||||
request.app.router._frozen = False
|
||||
content = await request.json()
|
||||
print(f'Defined new route {content["method"]} {content["url_pattern"]}')
|
||||
name = "ROUTE_" + str(uuid4()).replace('-', '_')
|
||||
request.app.router.add_route(content["method"],
|
||||
content["url_pattern"],
|
||||
@@ -215,13 +214,7 @@ async def delete_route(request):
|
||||
########################################################################
|
||||
|
||||
async def run_init_script():
|
||||
if len(sys.argv) > 1:
|
||||
# Script given
|
||||
# with open(sys.argv[1], 'r') as scriptfile:
|
||||
# script = scriptfile.read()
|
||||
pass
|
||||
else:
|
||||
# script = sys.stdin.read()
|
||||
if len(sys.argv) < 2:
|
||||
raise RuntimeError("Script file is mandatory.")
|
||||
|
||||
shell_task = await asyncio.create_subprocess_shell(
|
||||
|
||||
Reference in New Issue
Block a user