Flow stop, add tests and flow list

This commit is contained in:
Cyber MacGeddon 2025-04-23 11:47:49 +01:00
parent 19a66ec296
commit d14bb2aeca
6 changed files with 143 additions and 2 deletions

19
tests/test-flow-get-class Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env python3
import requests
url = "http://localhost:8088/"
resp = requests.post(
f"{url}/api/v1/flow",
json={
"operation": "get-class",
"class-name": "default",
}
)
resp = resp.json()
print(resp["class-definition"])

22
tests/test-flow-put-class Executable file

File diff suppressed because one or more lines are too long

23
tests/test-flow-start-flow Executable file
View file

@ -0,0 +1,23 @@
#!/usr/bin/env python3
import requests
import json
url = "http://localhost:8088/"
resp = requests.post(
f"{url}/api/v1/flow",
json={
"operation": "start-flow",
"flow-id": "0003",
"class-name": "default",
}
)
print(resp)
print(resp.text)
resp = resp.json()
print(resp)

22
tests/test-flow-stop-flow Executable file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env python3
import requests
import json
url = "http://localhost:8088/"
resp = requests.post(
f"{url}/api/v1/flow",
json={
"operation": "stop-flow",
"flow-id": "0003",
}
)
print(resp)
print(resp.text)
resp = resp.json()
print(resp)

View file

@ -0,0 +1,53 @@
#!/usr/bin/env python3
"""
Dumps out the current configuration
"""
import argparse
import os
from trustgraph.api import Api
import json
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
def show_flows(url):
api = Api(url)
BROKEN
config, version = api.config_all()
print("Version:", version)
print(json.dumps(config, indent=4))
def main():
parser = argparse.ArgumentParser(
prog='tg-show-config',
description=__doc__,
)
parser.add_argument(
'-u', '--api-url',
default=default_url,
help=f'API URL (default: {default_url})',
)
args = parser.parse_args()
try:
show_config(
url=args.api_url,
)
except Exception as e:
print("Exception:", e, flush=True)
main()

View file

@ -110,14 +110,16 @@ class FlowConfig:
async def handle_stop_flow(self, msg): async def handle_stop_flow(self, msg):
class_name = self.config["flows"][msg.flow_id]["class-name"]
def repl_template(tmp): def repl_template(tmp):
return tmp.replace( return tmp.replace(
"{class}", msg.class_name "{class}", class_name
).replace( ).replace(
"{id}", msg.flow_id "{id}", msg.flow_id
) )
cls = json.loads(self.config["flow-classes"][msg.class_name]) cls = json.loads(self.config["flow-classes"][class_name])
plumb = {} plumb = {}