mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-23 20:21:03 +02:00
Added auth token to all CLI utils args
This commit is contained in:
parent
c43f079c50
commit
d87f244872
8 changed files with 80 additions and 15 deletions
|
|
@ -9,10 +9,11 @@ from trustgraph.api import Api
|
|||
from trustgraph.api.types import ConfigValue
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
||||
|
||||
def put_config_item(url, config_type, key, value):
|
||||
def put_config_item(url, config_type, key, value, token=None):
|
||||
|
||||
api = Api(url).config()
|
||||
api = Api(url, token=token).config()
|
||||
|
||||
config_value = ConfigValue(type=config_type, key=key, value=value)
|
||||
api.put([config_value])
|
||||
|
|
@ -56,6 +57,12 @@ def main():
|
|||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-t', '--token',
|
||||
default=default_token,
|
||||
help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
|
@ -70,6 +77,7 @@ def main():
|
|||
config_type=args.type,
|
||||
key=args.key,
|
||||
value=value,
|
||||
token=args.token,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import textwrap
|
|||
import dataclasses
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Argument:
|
||||
|
|
@ -67,9 +68,10 @@ def set_tool(
|
|||
group : List[str],
|
||||
state : str,
|
||||
applicable_states : List[str],
|
||||
token : str = None,
|
||||
):
|
||||
|
||||
api = Api(url).config()
|
||||
api = Api(url, token=token).config()
|
||||
|
||||
values = api.get([
|
||||
ConfigKey(type="agent", key="tool-index")
|
||||
|
|
@ -156,6 +158,12 @@ def main():
|
|||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-t', '--token',
|
||||
default=default_token,
|
||||
help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--id',
|
||||
help=f'Unique tool identifier',
|
||||
|
|
@ -257,6 +265,7 @@ def main():
|
|||
group=args.group,
|
||||
state=args.state,
|
||||
applicable_states=args.applicable_states,
|
||||
token=args.token,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -8,10 +8,11 @@ from trustgraph.api import Api
|
|||
import json
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
||||
|
||||
def show_config(url):
|
||||
def show_config(url, token=None):
|
||||
|
||||
api = Api(url).config()
|
||||
api = Api(url, token=token).config()
|
||||
|
||||
config, version = api.all()
|
||||
|
||||
|
|
@ -31,12 +32,19 @@ def main():
|
|||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-t', '--token',
|
||||
default=default_token,
|
||||
help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
show_config(
|
||||
url=args.api_url,
|
||||
token=args.token,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ from trustgraph.api import Api, ConfigKey
|
|||
import json
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
||||
|
||||
def format_parameters(params_metadata, config_api):
|
||||
"""
|
||||
|
|
@ -57,9 +58,9 @@ def format_parameters(params_metadata, config_api):
|
|||
|
||||
return "\n".join(param_list)
|
||||
|
||||
def show_flow_classes(url):
|
||||
def show_flow_classes(url, token=None):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url, token=token)
|
||||
flow_api = api.flow()
|
||||
config_api = api.config()
|
||||
|
||||
|
|
@ -106,12 +107,19 @@ def main():
|
|||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-t', '--token',
|
||||
default=default_token,
|
||||
help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
show_flow_classes(
|
||||
url=args.api_url,
|
||||
token=args.token,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ from trustgraph.api import Api, ConfigKey
|
|||
import json
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
||||
|
||||
def get_interface(config_api, i):
|
||||
|
||||
|
|
@ -128,9 +129,9 @@ def format_parameters(flow_params, class_params_metadata, config_api):
|
|||
|
||||
return "\n".join(param_list) if param_list else "None"
|
||||
|
||||
def show_flows(url):
|
||||
def show_flows(url, token=None):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url, token=token)
|
||||
config_api = api.config()
|
||||
flow_api = api.flow()
|
||||
|
||||
|
|
@ -199,12 +200,19 @@ def main():
|
|||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-t', '--token',
|
||||
default=default_token,
|
||||
help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
show_flows(
|
||||
url=args.api_url,
|
||||
token=args.token,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -17,10 +17,11 @@ import tabulate
|
|||
import textwrap
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
||||
|
||||
def show_config(url):
|
||||
def show_config(url, token=None):
|
||||
|
||||
api = Api(url).config()
|
||||
api = Api(url, token=token).config()
|
||||
|
||||
values = api.get_values(type="tool")
|
||||
|
||||
|
|
@ -100,12 +101,19 @@ def main():
|
|||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-t', '--token',
|
||||
default=default_token,
|
||||
help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
show_config(
|
||||
url=args.api_url,
|
||||
token=args.token,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -17,10 +17,11 @@ from trustgraph.api import Api
|
|||
import json
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
||||
|
||||
def start_flow(url, class_name, flow_id, description, parameters=None):
|
||||
def start_flow(url, class_name, flow_id, description, parameters=None, token=None):
|
||||
|
||||
api = Api(url).flow()
|
||||
api = Api(url, token=token).flow()
|
||||
|
||||
api.start(
|
||||
class_name = class_name,
|
||||
|
|
@ -42,6 +43,12 @@ def main():
|
|||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-t', '--token',
|
||||
default=default_token,
|
||||
help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-n', '--class-name',
|
||||
required=True,
|
||||
|
|
@ -112,6 +119,7 @@ def main():
|
|||
flow_id = args.flow_id,
|
||||
description = args.description,
|
||||
parameters = parameters,
|
||||
token = args.token,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -9,10 +9,11 @@ from trustgraph.api import Api
|
|||
import json
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
||||
|
||||
def stop_flow(url, flow_id):
|
||||
def stop_flow(url, flow_id, token=None):
|
||||
|
||||
api = Api(url).flow()
|
||||
api = Api(url, token=token).flow()
|
||||
|
||||
api.stop(id = flow_id)
|
||||
|
||||
|
|
@ -29,6 +30,12 @@ def main():
|
|||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-t', '--token',
|
||||
default=default_token,
|
||||
help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-i', '--flow-id',
|
||||
required=True,
|
||||
|
|
@ -42,6 +49,7 @@ def main():
|
|||
stop_flow(
|
||||
url=args.api_url,
|
||||
flow_id=args.flow_id,
|
||||
token=args.token,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue