mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-05-15 18:35:15 +02:00
Feature/interface descriptions (#348)
This commit is contained in:
parent
762d287a67
commit
2e24f8ca12
2 changed files with 76 additions and 16 deletions
|
|
@ -6,39 +6,81 @@
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import tabulate
|
import tabulate
|
||||||
from trustgraph.api import Api
|
from trustgraph.api import Api, ConfigKey
|
||||||
import json
|
import json
|
||||||
|
|
||||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||||
|
|
||||||
|
def get_interface(api, i):
|
||||||
|
|
||||||
|
key = ConfigKey("interface-descriptions", i)
|
||||||
|
|
||||||
|
value = api.config_get([key])[0].value
|
||||||
|
|
||||||
|
return json.loads(value)
|
||||||
|
|
||||||
|
def describe_interfaces(intdefs, flow):
|
||||||
|
|
||||||
|
intfs = flow.get("interfaces", {})
|
||||||
|
|
||||||
|
lst = []
|
||||||
|
|
||||||
|
for k, v in intdefs.items():
|
||||||
|
|
||||||
|
if intdefs[k].get("visible", False):
|
||||||
|
|
||||||
|
label = intdefs[k].get("description", k)
|
||||||
|
kind = intdefs[k].get("kind", None)
|
||||||
|
|
||||||
|
if kind == "request-response":
|
||||||
|
req = intfs[k]["request"]
|
||||||
|
resp = intfs[k]["request"]
|
||||||
|
|
||||||
|
lst.append(f"{k} request: {req}")
|
||||||
|
lst.append(f"{k} response: {resp}")
|
||||||
|
|
||||||
|
if kind == "send":
|
||||||
|
q = intfs[k]
|
||||||
|
|
||||||
|
lst.append(f"{k}: {q}")
|
||||||
|
|
||||||
|
return "\n".join(lst)
|
||||||
|
|
||||||
def show_flows(url):
|
def show_flows(url):
|
||||||
|
|
||||||
api = Api(url)
|
api = Api(url)
|
||||||
|
|
||||||
|
interface_names = api.config_list("interface-descriptions")
|
||||||
|
|
||||||
|
interface_defs = {
|
||||||
|
i: get_interface(api, i)
|
||||||
|
for i in interface_names
|
||||||
|
}
|
||||||
|
|
||||||
flow_ids = api.flow_list()
|
flow_ids = api.flow_list()
|
||||||
|
|
||||||
if len(flow_ids) == 0:
|
if len(flow_ids) == 0:
|
||||||
print("No flows.")
|
print("No flows.")
|
||||||
return
|
return
|
||||||
|
|
||||||
print(flow_ids)
|
|
||||||
|
|
||||||
flows = []
|
flows = []
|
||||||
|
|
||||||
for id in flow_ids:
|
for id in flow_ids:
|
||||||
flow = api.flow_get(id)
|
|
||||||
flows.append((
|
|
||||||
id,
|
|
||||||
flow.get("description", ""),
|
|
||||||
))
|
|
||||||
|
|
||||||
print(tabulate.tabulate(
|
flow = api.flow_get(id)
|
||||||
flows,
|
|
||||||
tablefmt="pretty",
|
table = []
|
||||||
maxcolwidths=[None, 40],
|
table.append(("id", id))
|
||||||
stralign="left",
|
table.append(("class", flow.get("class-name", "")))
|
||||||
headers = ["id", "description"],
|
table.append(("desc", flow.get("description", "")))
|
||||||
))
|
table.append(("queue", describe_interfaces(interface_defs, flow)))
|
||||||
|
|
||||||
|
print(tabulate.tabulate(
|
||||||
|
table,
|
||||||
|
tablefmt="pretty",
|
||||||
|
stralign="left",
|
||||||
|
))
|
||||||
|
print()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,9 +112,27 @@ class FlowConfig:
|
||||||
|
|
||||||
self.config["flows-active"][processor] = json.dumps(target)
|
self.config["flows-active"][processor] = json.dumps(target)
|
||||||
|
|
||||||
|
def repl_interface(i):
|
||||||
|
if isinstance(i, str):
|
||||||
|
return repl_template(i)
|
||||||
|
else:
|
||||||
|
return {
|
||||||
|
k: repl_template(v)
|
||||||
|
for k, v in i.items()
|
||||||
|
}
|
||||||
|
|
||||||
|
if "interfaces" in cls:
|
||||||
|
interfaces = {
|
||||||
|
k: repl_interface(v)
|
||||||
|
for k, v in cls["interfaces"].items()
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
interfaces = {}
|
||||||
|
|
||||||
self.config["flows"][msg.flow_id] = json.dumps({
|
self.config["flows"][msg.flow_id] = json.dumps({
|
||||||
"description": msg.description,
|
"description": msg.description,
|
||||||
"class-name": msg.class_name,
|
"class-name": msg.class_name,
|
||||||
|
"interfaces": interfaces,
|
||||||
})
|
})
|
||||||
|
|
||||||
await self.config.push()
|
await self.config.push()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue