mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-26 00:46:22 +02:00
Feature/flow management cli (#346)
Flow management API + various flow management commands trustgraph-cli/scripts/tg-delete-flow-class trustgraph-cli/scripts/tg-get-flow-class trustgraph-cli/scripts/tg-put-flow-class trustgraph-cli/scripts/tg-show-flow-classes trustgraph-cli/scripts/tg-show-flows trustgraph-cli/scripts/tg-start-flow trustgraph-cli/scripts/tg-stop-flow
This commit is contained in:
parent
31328317fd
commit
77e933cea3
39 changed files with 1706 additions and 335 deletions
52
trustgraph-cli/scripts/tg-delete-flow-class
Executable file
52
trustgraph-cli/scripts/tg-delete-flow-class
Executable file
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import tabulate
|
||||
from trustgraph.api import Api
|
||||
import json
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
|
||||
def delete_flow_class(url, class_name):
|
||||
|
||||
api = Api(url)
|
||||
|
||||
class_names = api.flow_delete_class(class_name)
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-delete-flow-class',
|
||||
description=__doc__,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-u', '--api-url',
|
||||
default=default_url,
|
||||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-n', '--class-name',
|
||||
help=f'Flow class name',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
delete_flow_class(
|
||||
url=args.api_url,
|
||||
class_name=args.class_name,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Exception:", e, flush=True)
|
||||
|
||||
main()
|
||||
|
||||
56
trustgraph-cli/scripts/tg-get-flow-class
Executable file
56
trustgraph-cli/scripts/tg-get-flow-class
Executable file
|
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Dumps out the current configuration
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import tabulate
|
||||
from trustgraph.api import Api
|
||||
import json
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
|
||||
def get_flow_class(url, class_name):
|
||||
|
||||
api = Api(url)
|
||||
|
||||
cls = api.flow_get_class(class_name)
|
||||
|
||||
print(json.dumps(cls, indent=4))
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-get-flow-class',
|
||||
description=__doc__,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-u', '--api-url',
|
||||
default=default_url,
|
||||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-n', '--class-name',
|
||||
required=True,
|
||||
help=f'Flow class name',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
get_flow_class(
|
||||
url=args.api_url,
|
||||
class_name=args.class_name,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Exception:", e, flush=True)
|
||||
|
||||
main()
|
||||
|
||||
59
trustgraph-cli/scripts/tg-put-flow-class
Executable file
59
trustgraph-cli/scripts/tg-put-flow-class
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Dumps out the current configuration
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import tabulate
|
||||
from trustgraph.api import Api
|
||||
import json
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
|
||||
def put_flow_class(url, class_name, config):
|
||||
|
||||
api = Api(url)
|
||||
|
||||
class_names = api.flow_put_class(class_name, config)
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-put-flow-class',
|
||||
description=__doc__,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-u', '--api-url',
|
||||
default=default_url,
|
||||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-n', '--class-name',
|
||||
help=f'Flow class name',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-c', '--config',
|
||||
help=f'Initial configuration to load',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
put_flow_class(
|
||||
url=args.api_url,
|
||||
class_name=args.class_name,
|
||||
config=json.loads(args.config),
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Exception:", e, flush=True)
|
||||
|
||||
main()
|
||||
|
||||
64
trustgraph-cli/scripts/tg-show-flow-classes
Executable file
64
trustgraph-cli/scripts/tg-show-flow-classes
Executable file
|
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import tabulate
|
||||
from trustgraph.api import Api
|
||||
import json
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
|
||||
def show_flow_classes(url):
|
||||
|
||||
api = Api(url)
|
||||
|
||||
class_names = api.flow_list_classes()
|
||||
|
||||
classes = []
|
||||
|
||||
for class_name in class_names:
|
||||
cls = api.flow_get_class(class_name)
|
||||
classes.append((
|
||||
class_name,
|
||||
cls.get("description", ""),
|
||||
", ".join(cls.get("tags", [])),
|
||||
))
|
||||
|
||||
print(tabulate.tabulate(
|
||||
classes,
|
||||
tablefmt="pretty",
|
||||
maxcolwidths=[None, 40, 20],
|
||||
stralign="left",
|
||||
headers = ["flow class", "description", "tags"],
|
||||
))
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-show-flow-classes',
|
||||
description=__doc__,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-u', '--api-url',
|
||||
default=default_url,
|
||||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
show_flow_classes(
|
||||
url=args.api_url,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Exception:", e, flush=True)
|
||||
|
||||
main()
|
||||
|
||||
65
trustgraph-cli/scripts/tg-show-flows
Executable file
65
trustgraph-cli/scripts/tg-show-flows
Executable file
|
|
@ -0,0 +1,65 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import tabulate
|
||||
from trustgraph.api import Api
|
||||
import json
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
|
||||
def show_flows(url):
|
||||
|
||||
api = Api(url)
|
||||
|
||||
flow_ids = api.flow_list()
|
||||
|
||||
print(flow_ids)
|
||||
|
||||
flows = []
|
||||
|
||||
for id in flow_ids:
|
||||
flow = api.flow_get(id)
|
||||
flows.append((
|
||||
id,
|
||||
flow.get("description", ""),
|
||||
))
|
||||
|
||||
print(tabulate.tabulate(
|
||||
flows,
|
||||
tablefmt="pretty",
|
||||
maxcolwidths=[None, 40],
|
||||
stralign="left",
|
||||
headers = ["id", "description"],
|
||||
))
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-show-flows',
|
||||
description=__doc__,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-u', '--api-url',
|
||||
default=default_url,
|
||||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
show_flows(
|
||||
url=args.api_url,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Exception:", e, flush=True)
|
||||
|
||||
main()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue