Refined header code, added reverse recursive action
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
def buildHeaders(definition, request, outputs, resolved):
|
||||
headers = {}
|
||||
|
||||
for header_name, header_value in definition.headers.items():
|
||||
value = header_value
|
||||
|
||||
if isinstance(value, dict) and "output" in header_value:
|
||||
value = outputs[value["output"]]
|
||||
|
||||
if isinstance(value, dict) and "os" in header_value:
|
||||
value = os.environ.get(value["os"])
|
||||
|
||||
if isinstance(header_value, dict) and "prefix" in header_value:
|
||||
value = header_value["prefix"] + value
|
||||
|
||||
headers[header_name] = value
|
||||
|
||||
request["headers"] = headers
|
||||
|
||||
return headers
|
||||
@@ -1,6 +1,7 @@
|
||||
from .object import buildObject
|
||||
from .path import buildPath
|
||||
import os
|
||||
from .headers import buildHeaders
|
||||
#import os
|
||||
|
||||
def buildRequest(definition, outputs, resolved):
|
||||
path = buildPath(definition.path, outputs, resolved)
|
||||
@@ -14,22 +15,6 @@ def buildRequest(definition, outputs, resolved):
|
||||
request["object"] = buildObject(definition.keys, outputs, resolved)
|
||||
|
||||
if hasattr(definition, "headers"):
|
||||
headers = {}
|
||||
|
||||
for header_name, header_value in definition.headers.items():
|
||||
value = header_value
|
||||
|
||||
if isinstance(value, dict) and "output" in header_value:
|
||||
value = outputs[value["output"]]
|
||||
if isinstance(value, dict) and "os" in header_value:
|
||||
#value = os.environ[definition.headers[header_name]["os"]]
|
||||
value = os.environ["AS_TOKEN"]
|
||||
|
||||
if isinstance(header_value, dict) and "prefix" in header_value:
|
||||
value = header_value["prefix"] + value
|
||||
|
||||
headers[header_name] = value
|
||||
|
||||
request["headers"] = headers
|
||||
request["headers"] = buildHeaders(definition, request, outputs, resolved)
|
||||
|
||||
return request, outputs
|
||||
|
||||
Binary file not shown.
@@ -6,7 +6,13 @@ def buildAction (action, outputs):
|
||||
#outputs, resolved = buildPreRuntimeAttr(action, outputs)
|
||||
|
||||
if hasattr(action, "recursive"):
|
||||
for item in outputs[action.recursive["source"]]:
|
||||
items = outputs[action.recursive["source"]]
|
||||
reverse = action.recursive.get("reversed", False)
|
||||
|
||||
if reverse:
|
||||
items = reversed(items)
|
||||
|
||||
for item in items:
|
||||
outputs[action.recursive["label"]] = item
|
||||
outputs, resolved = buildPreRuntimeAttr(action, outputs)
|
||||
response, outputs = executeRequest(action, outputs, resolved)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
from core.execution.action.action import buildAction
|
||||
|
||||
def recursiveSet(definition, outputs):
|
||||
recursiveset = definition.recursiveset["actions"]
|
||||
for item in outputs[definition.recursiveset["source"]]:
|
||||
outputs[definition.recursiveset["outputlabel"]] = item
|
||||
#outputs["recursive"] = item
|
||||
|
||||
for job in recursiveset:
|
||||
outputs, response = buildAction(job, outputs)
|
||||
|
||||
print(outputs["profile"])
|
||||
print(outputs["messages"])
|
||||
return outputs
|
||||
|
||||
from core.execution.action.action import buildAction
|
||||
|
||||
Binary file not shown.
+29
-16
@@ -2,7 +2,7 @@ import socket
|
||||
import json
|
||||
import os
|
||||
import logging
|
||||
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
from .dispatcher import dispatchRequest
|
||||
from .createresponse import buildResponse
|
||||
|
||||
@@ -14,29 +14,42 @@ def startServer():
|
||||
server.bind(("0.0.0.0", port))
|
||||
|
||||
lifecycles = {}
|
||||
|
||||
|
||||
server.listen()
|
||||
logging.info(f"Server listening on port {port}")
|
||||
print(f"Server listening on port {port}")
|
||||
while True:
|
||||
connection, address = server.accept()
|
||||
logging.info("Accepting connections")
|
||||
print("Accepting connections")
|
||||
connection.settimeout(30)
|
||||
|
||||
while True:
|
||||
data = connection.recv(4096)
|
||||
class RequestHandler(BaseHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
print("POST request received")
|
||||
|
||||
try:
|
||||
while True:
|
||||
data = connection.recv(4096)
|
||||
|
||||
if not data:
|
||||
print("Client Disconnected")
|
||||
break
|
||||
|
||||
request = json.loads(data)
|
||||
request = json.loads(data)
|
||||
|
||||
# if not data:
|
||||
# break
|
||||
thread, lifecycles, module, mode = dispatchRequest(request, lifecycles)
|
||||
|
||||
thread, lifecycles, module, mode = dispatchRequest(request, lifecycles)
|
||||
response = buildResponse(module, thread, mode)
|
||||
|
||||
response = buildResponse(module, thread, mode)
|
||||
connection.sendall(
|
||||
json.dumps(response).encode("utf-8"),
|
||||
)
|
||||
except json.decoder.JSONDecodeError as error:
|
||||
print("Invalid JSON received", error)
|
||||
print("Closing client connection")
|
||||
except socket.timeout:
|
||||
print("Client connection timed out")
|
||||
|
||||
connection.sendall(
|
||||
json.dumps(response).encode("utf-8"),
|
||||
)
|
||||
|
||||
connection.close()
|
||||
finally:
|
||||
connection.close()
|
||||
|
||||
# server.close()
|
||||
|
||||
Reference in New Issue
Block a user