cmdbox 0.6.2.4__py3-none-any.whl → 0.6.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cmdbox/app/common.py +28 -12
- cmdbox/app/features/cli/cmdbox_client_http.py +154 -0
- cmdbox/app/features/cli/cmdbox_cmd_list.py +11 -7
- cmdbox/app/mcp.py +222 -124
- cmdbox/app/options.py +2 -1
- cmdbox/app/web.py +2 -2
- cmdbox/extensions/features.yml +3 -0
- cmdbox/extensions/sample_project/sample/extensions/features.yml +3 -12
- cmdbox/version.py +2 -2
- cmdbox/web/assets/cmdbox/view_result.js +2 -1
- {cmdbox-0.6.2.4.dist-info → cmdbox-0.6.3.dist-info}/METADATA +1 -1
- {cmdbox-0.6.2.4.dist-info → cmdbox-0.6.3.dist-info}/RECORD +16 -15
- {cmdbox-0.6.2.4.dist-info → cmdbox-0.6.3.dist-info}/LICENSE +0 -0
- {cmdbox-0.6.2.4.dist-info → cmdbox-0.6.3.dist-info}/WHEEL +0 -0
- {cmdbox-0.6.2.4.dist-info → cmdbox-0.6.3.dist-info}/entry_points.txt +0 -0
- {cmdbox-0.6.2.4.dist-info → cmdbox-0.6.3.dist-info}/top_level.txt +0 -0
cmdbox/app/common.py
CHANGED
|
@@ -13,6 +13,7 @@ import asyncio
|
|
|
13
13
|
import datetime
|
|
14
14
|
import logging
|
|
15
15
|
import logging.config
|
|
16
|
+
import locale
|
|
16
17
|
import hashlib
|
|
17
18
|
import inspect
|
|
18
19
|
import json
|
|
@@ -498,19 +499,23 @@ def print_format(data:dict, format:bool, tm:float, output_json:str=None, output_
|
|
|
498
499
|
Returns:
|
|
499
500
|
str: 生成された文字列
|
|
500
501
|
"""
|
|
501
|
-
|
|
502
|
+
is_data_dict = isinstance(data, dict)
|
|
503
|
+
in_data_success = is_data_dict and 'success' in data
|
|
504
|
+
is_success_dict = in_data_success and isinstance(data['success'], dict)
|
|
505
|
+
is_data_list = isinstance(data, list)
|
|
506
|
+
if is_success_dict and "performance" in data["success"] and isinstance(data["success"]["performance"], list) and pf is not None:
|
|
502
507
|
data["success"]["performance"] += pf
|
|
503
508
|
txt = ''
|
|
504
509
|
if format:
|
|
505
|
-
if
|
|
506
|
-
|
|
507
|
-
if
|
|
508
|
-
txt = tabulate(
|
|
509
|
-
elif
|
|
510
|
-
txt = tabulate([
|
|
510
|
+
if is_success_dict:
|
|
511
|
+
_data = data['success']['data'] if 'data' in data['success'] else data['success']
|
|
512
|
+
if isinstance(_data, list):
|
|
513
|
+
txt = tabulate(_data, headers='keys', tablefmt=tablefmt)
|
|
514
|
+
elif isinstance(_data, dict):
|
|
515
|
+
txt = tabulate([_data], headers='keys', tablefmt=tablefmt)
|
|
511
516
|
else:
|
|
512
|
-
txt = str(
|
|
513
|
-
elif
|
|
517
|
+
txt = str(_data)
|
|
518
|
+
elif is_data_list:
|
|
514
519
|
txt = tabulate(data, headers='keys', tablefmt=tablefmt)
|
|
515
520
|
else:
|
|
516
521
|
txt = tabulate([data], headers='keys', tablefmt=tablefmt)
|
|
@@ -521,13 +526,13 @@ def print_format(data:dict, format:bool, tm:float, output_json:str=None, output_
|
|
|
521
526
|
except BrokenPipeError:
|
|
522
527
|
pass
|
|
523
528
|
else:
|
|
524
|
-
if
|
|
529
|
+
if is_success_dict:
|
|
525
530
|
if "performance" not in data["success"]:
|
|
526
531
|
data["success"]["performance"] = []
|
|
527
532
|
performance = data["success"]["performance"]
|
|
528
533
|
performance.append(dict(key="app_proc", val=f"{time.perf_counter() - tm:.03f}s"))
|
|
529
534
|
try:
|
|
530
|
-
if
|
|
535
|
+
if is_data_dict:
|
|
531
536
|
txt = json.dumps(data, default=default_json_enc, ensure_ascii=False)
|
|
532
537
|
else:
|
|
533
538
|
txt = data
|
|
@@ -685,6 +690,17 @@ def chopdq(target:str):
|
|
|
685
690
|
return target
|
|
686
691
|
return target[1:-1] if target.startswith('"') and target.endswith('"') else target
|
|
687
692
|
|
|
693
|
+
def is_japan() -> bool:
|
|
694
|
+
"""
|
|
695
|
+
日本語環境かどうかを判定します
|
|
696
|
+
|
|
697
|
+
Returns:
|
|
698
|
+
bool: 日本語環境ならTrue、そうでなければFalse
|
|
699
|
+
"""
|
|
700
|
+
language, _ = locale.getlocale()
|
|
701
|
+
is_japan = language.find('Japan') >= 0 or language.find('ja_JP') >= 0
|
|
702
|
+
return is_japan
|
|
703
|
+
|
|
688
704
|
def is_event_loop_running() -> bool:
|
|
689
705
|
"""
|
|
690
706
|
イベントループが実行中かどうかを取得します。
|
|
@@ -721,7 +737,7 @@ def exec_sync(apprun, logger:logging.Logger, args:argparse.Namespace, tm:float,
|
|
|
721
737
|
th.start()
|
|
722
738
|
th.join()
|
|
723
739
|
result = ctx[0] if ctx else None
|
|
724
|
-
return
|
|
740
|
+
return result
|
|
725
741
|
return asyncio.run(apprun(logger, args, tm, pf))
|
|
726
742
|
return apprun(logger, args, tm, pf)
|
|
727
743
|
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from cmdbox.app import common, client, feature, filer
|
|
2
|
+
from cmdbox.app.commons import convert, redis_client
|
|
3
|
+
from cmdbox.app.options import Options
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Any, Tuple, List, Union
|
|
6
|
+
import argparse
|
|
7
|
+
import logging
|
|
8
|
+
import requests
|
|
9
|
+
import urllib.parse
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ClientHttp(feature.ResultEdgeFeature):
|
|
13
|
+
def get_mode(self) -> Union[str, List[str]]:
|
|
14
|
+
"""
|
|
15
|
+
この機能のモードを返します
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
Union[str, List[str]]: モード
|
|
19
|
+
"""
|
|
20
|
+
return 'client'
|
|
21
|
+
|
|
22
|
+
def get_cmd(self):
|
|
23
|
+
"""
|
|
24
|
+
この機能のコマンドを返します
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
str: コマンド
|
|
28
|
+
"""
|
|
29
|
+
return 'http'
|
|
30
|
+
|
|
31
|
+
def get_option(self):
|
|
32
|
+
"""
|
|
33
|
+
この機能のオプションを返します
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
Dict[str, Any]: オプション
|
|
37
|
+
"""
|
|
38
|
+
return dict(
|
|
39
|
+
use_redis=self.USE_REDIS_MEIGHT, nouse_webmode=False,
|
|
40
|
+
description_ja="HTTPサーバーに対してリクエストを送信し、レスポンスを取得します。",
|
|
41
|
+
description_en="Sends a request to the HTTP server and gets a response.",
|
|
42
|
+
choice=[
|
|
43
|
+
dict(opt="url", type=Options.T_STR, default=None, required=True, multi=False, hide=False, choice=None,
|
|
44
|
+
description_ja="リクエスト先URLを指定します。",
|
|
45
|
+
description_en="Specify the URL to request."),
|
|
46
|
+
dict(opt="proxy", type=Options.T_STR, default="no", required=False, multi=False, hide=False, choice=['no', 'yes'],
|
|
47
|
+
choice_show=dict(no=["send_method", "send_content_type", "send_apikey", "send_header",],
|
|
48
|
+
yes=[]),
|
|
49
|
+
description_ja="webモードで呼び出された場合、受信したリクエストパラメータをリクエスト先URLに送信するかどうかを指定します。",
|
|
50
|
+
description_en="Specifies whether or not to send the received request parameters to the destination URL when invoked in web mode."),
|
|
51
|
+
dict(opt="send_method", type=Options.T_STR, default="GET", required=True, multi=False, hide=False,
|
|
52
|
+
choice=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'],
|
|
53
|
+
description_ja="リクエストメソッドを指定します。",
|
|
54
|
+
description_en="Specifies the request method."),
|
|
55
|
+
dict(opt="send_content_type", type=Options.T_STR, default=None, required=False, multi=False, hide=False,
|
|
56
|
+
choice=['', 'application/octet-stream', 'application/json', 'multipart/form-data'],
|
|
57
|
+
choice_show={'application/octet-stream':["send_param", "send_data",],
|
|
58
|
+
'application/json':["send_data",],
|
|
59
|
+
'multipart/form-data':["send_param",],},
|
|
60
|
+
description_ja="送信するデータのContent-Typeを指定します。",
|
|
61
|
+
description_en="Specifies the Content-Type of the data to be sent."),
|
|
62
|
+
dict(opt="send_apikey", type=Options.T_TEXT, default=None, required=False, multi=False, hide=False, choice=None,
|
|
63
|
+
description_ja="リクエスト先の認証で使用するAPIキーを指定します。",
|
|
64
|
+
description_en="Specify the API key to be used for authentication of the request destination."),
|
|
65
|
+
dict(opt="send_header", type=Options.T_DICT, default=None, required=False, multi=True, hide=False, choice=None,
|
|
66
|
+
description_ja="リクエストヘッダーを指定します。",
|
|
67
|
+
description_en="Specifies the request header."),
|
|
68
|
+
dict(opt="send_param", type=Options.T_DICT, default=None, required=False, multi=True, hide=False, choice=None,
|
|
69
|
+
description_ja="送信するパラメータを指定します。",
|
|
70
|
+
description_en="Specifies parameters to be sent."),
|
|
71
|
+
dict(opt="send_data", type=Options.T_TEXT, default=None, required=False, multi=False, hide=False, choice=None,
|
|
72
|
+
description_ja="送信するデータを指定します。",
|
|
73
|
+
description_en="Specifies the data to be sent."),
|
|
74
|
+
dict(opt="send_verify", type=Options.T_BOOL, default=False, required=False, multi=False, hide=True, choice=[False, True],
|
|
75
|
+
description_ja="レスポンスを受け取るまでのタイムアウトを指定します。",
|
|
76
|
+
description_en="Specifies the timeout before a response is received."),
|
|
77
|
+
dict(opt="send_timeout", type=Options.T_INT, default=30, required=False, multi=False, hide=True, choice=None,
|
|
78
|
+
description_ja="レスポンスを受け取るまでのタイムアウトを指定します。",
|
|
79
|
+
description_en="Specifies the timeout before a response is received."),
|
|
80
|
+
dict(opt="stdout_log", type=Options.T_BOOL, default=True, required=False, multi=False, hide=True, choice=[True, False],
|
|
81
|
+
description_ja="GUIモードでのみ使用可能です。コマンド実行時の標準出力をConsole logに出力します。",
|
|
82
|
+
description_en="Available only in GUI mode. Outputs standard output during command execution to Console log."),
|
|
83
|
+
dict(opt="capture_stdout", type=Options.T_BOOL, default=True, required=False, multi=False, hide=True, choice=[True, False],
|
|
84
|
+
description_ja="GUIモードでのみ使用可能です。コマンド実行時の標準出力をキャプチャーし、実行結果画面に表示します。",
|
|
85
|
+
description_en="Available only in GUI mode. Captures standard output during command execution and displays it on the execution result screen."),
|
|
86
|
+
dict(opt="capture_maxsize", type=Options.T_INT, default=self.DEFAULT_CAPTURE_MAXSIZE, required=False, multi=False, hide=True, choice=None,
|
|
87
|
+
description_ja="GUIモードでのみ使用可能です。コマンド実行時の標準出力の最大キャプチャーサイズを指定します。",
|
|
88
|
+
description_en="Available only in GUI mode. Specifies the maximum capture size of standard output when executing commands."),
|
|
89
|
+
]
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
async def apprun(self, logger:logging.Logger, args:argparse.Namespace, tm:float, pf:List[Dict[str, float]]=[]) -> Tuple[int, Dict[str, Any], Any]:
|
|
93
|
+
"""
|
|
94
|
+
この機能の実行を行います
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
logger (logging.Logger): ロガー
|
|
98
|
+
args (argparse.Namespace): 引数
|
|
99
|
+
tm (float): 実行開始時間
|
|
100
|
+
pf (List[Dict[str, float]]): 呼出元のパフォーマンス情報
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
Tuple[int, Dict[str, Any], Any]: 終了コード, 結果, オブジェクト
|
|
104
|
+
"""
|
|
105
|
+
if args.url is None:
|
|
106
|
+
msg = dict(warn=f"Please specify the --url option.")
|
|
107
|
+
common.print_format(msg, args.format, tm, None, False, pf=pf)
|
|
108
|
+
return 1, msg, None
|
|
109
|
+
query_param = {}
|
|
110
|
+
if args.proxy == 'yes':
|
|
111
|
+
from cmdbox.app.auth import signin
|
|
112
|
+
from fastapi import Request
|
|
113
|
+
scope = signin.get_request_scope()
|
|
114
|
+
if scope is None:
|
|
115
|
+
msg = dict(warn=f"Request scope is not set. Please set the request scope.")
|
|
116
|
+
common.print_format(msg, args.format, tm, None, False, pf=pf)
|
|
117
|
+
return 1, msg, None
|
|
118
|
+
req:Request = scope['req']
|
|
119
|
+
args.send_method = req.method
|
|
120
|
+
args.send_content_type = req.headers.get('Content-Type', None)
|
|
121
|
+
args.send_apikey = req.headers.get('Authorization', '').replace('Bearer ', '')
|
|
122
|
+
args.send_header = {k:v for k, v in req.headers.items() \
|
|
123
|
+
if k.lower() not in ['connection', 'proxy-authorization', 'proxy-connection', 'keep-alive',
|
|
124
|
+
'transfer-encoding', 'te', 'trailer', 'upgrade', 'content-length']}
|
|
125
|
+
query_param = {k:v for k, v in req.query_params.items()}
|
|
126
|
+
args.send_data = await req.body()
|
|
127
|
+
|
|
128
|
+
url = urllib.parse.urlparse(args.url)
|
|
129
|
+
query = urllib.parse.parse_qs(url.query)
|
|
130
|
+
query = {**query, **query_param} if query else query_param
|
|
131
|
+
args.url = urllib.parse.urlunparse((url.scheme, url.netloc, url.path, url.params, urllib.parse.urlencode(query), url.fragment))
|
|
132
|
+
args.send_header = {**args.send_header, 'Authorization':f'Bearer {args.send_apikey}'} if args.send_apikey else args.send_header
|
|
133
|
+
res = requests.request(method=args.send_method, url=args.url, headers=args.send_header,
|
|
134
|
+
verify=args.send_verify, timeout=args.send_timeout, allow_redirects=True,
|
|
135
|
+
data=args.send_data, params=args.send_param)
|
|
136
|
+
if res.status_code != 200:
|
|
137
|
+
msg = dict(error=f"Request failed with status code {res.status_code}.")
|
|
138
|
+
common.print_format(msg, False, tm, None, False, pf=pf)
|
|
139
|
+
return 1, msg, None
|
|
140
|
+
content_type = res.headers.get('Content-Type', '')
|
|
141
|
+
if content_type.startswith('application/json'):
|
|
142
|
+
try:
|
|
143
|
+
msg = res.json()
|
|
144
|
+
except ValueError as e:
|
|
145
|
+
msg = res.text
|
|
146
|
+
common.print_format(msg, False, tm, None, False, pf=pf)
|
|
147
|
+
return 0, msg, None
|
|
148
|
+
elif content_type.startswith('text/'):
|
|
149
|
+
msg = res.text
|
|
150
|
+
common.print_format(msg, False, tm, None, False, pf=pf)
|
|
151
|
+
return 0, msg, None
|
|
152
|
+
common.print_format(res.content, False, tm, None, False, pf=pf)
|
|
153
|
+
|
|
154
|
+
return 0, res.content, None
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from cmdbox.app import common, feature
|
|
1
|
+
from cmdbox.app import common, feature, options
|
|
2
2
|
from cmdbox.app.auth import signin
|
|
3
3
|
from cmdbox.app.options import Options
|
|
4
4
|
from pathlib import Path
|
|
@@ -45,10 +45,10 @@ class CmdList(feature.OneshotResultEdgeFeature):
|
|
|
45
45
|
dict(opt="kwd", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=None,
|
|
46
46
|
description_ja=f"検索したいコマンド名を指定します。中間マッチで検索します。",
|
|
47
47
|
description_en=f"Specify the name of the command you want to search. Search with intermediate matches."),
|
|
48
|
-
dict(opt="signin_file", type=Options.T_FILE, default=f".{self.ver.__appid__}/user_list.yml", required=False, multi=False, hide=
|
|
48
|
+
dict(opt="signin_file", type=Options.T_FILE, default=f".{self.ver.__appid__}/user_list.yml", required=False, multi=False, hide=False, choice=None, fileio="in",
|
|
49
49
|
description_ja="サインイン可能なユーザーとパスワードを記載したファイルを指定します。",
|
|
50
50
|
description_en="Specify a file containing users and passwords with which they can signin."),
|
|
51
|
-
dict(opt="groups", type=Options.T_STR, default=None, required=False, multi=True, hide=
|
|
51
|
+
dict(opt="groups", type=Options.T_STR, default=None, required=False, multi=True, hide=False, choice=None,
|
|
52
52
|
description_ja="`signin_file` を指定した場合に、このユーザーグループに許可されているコマンドリストを返すように指定します。",
|
|
53
53
|
description_en="Specifies that `signin_file`, if specified, should return the list of commands allowed for this user group."),
|
|
54
54
|
dict(opt="output_json", short="o", type=Options.T_FILE, default=None, required=False, multi=False, hide=True, choice=None, fileio="out",
|
|
@@ -92,11 +92,15 @@ class CmdList(feature.OneshotResultEdgeFeature):
|
|
|
92
92
|
if not hasattr(self, 'signin_file_data') or self.signin_file_data is None:
|
|
93
93
|
self.signin_file_data = signin.Signin.load_signin_file(args.signin_file, None, self=self)
|
|
94
94
|
paths = glob.glob(str(Path(args.data) / ".cmds" / f"cmd-{kwd}.json"))
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
cmd_list = [common.loadopt(path, True) for path in paths]
|
|
96
|
+
cmd_list = sorted(cmd_list, key=lambda cmd: cmd["title"])
|
|
97
|
+
is_japan = common.is_japan()
|
|
98
|
+
options = Options.getInstance()
|
|
99
|
+
cmd_list = [dict(title=r.get('title',''), mode=r['mode'], cmd=r['cmd'],
|
|
100
|
+
description=r.get('description','') + options.get_cmd_attr(r['mode'], r['cmd'], 'description_ja' if is_japan else 'description_en'),
|
|
101
|
+
tag=r.get('tag','')) for r in cmd_list \
|
|
98
102
|
if signin.Signin._check_cmd(self.signin_file_data, args.groups, r['mode'], r['cmd'], logger)]
|
|
99
|
-
ret = dict(success=
|
|
103
|
+
ret = dict(success=cmd_list)
|
|
100
104
|
|
|
101
105
|
common.print_format(ret, args.format, tm, args.output_json, args.output_json_append, pf=pf)
|
|
102
106
|
|
cmdbox/app/mcp.py
CHANGED
|
@@ -4,6 +4,7 @@ from cmdbox.app.auth import signin
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
from typing import Callable, List, Dict, Any, Tuple
|
|
6
6
|
import argparse
|
|
7
|
+
import glob
|
|
7
8
|
import logging
|
|
8
9
|
import locale
|
|
9
10
|
import json
|
|
@@ -35,15 +36,14 @@ class Mcp:
|
|
|
35
36
|
self.ver = ver
|
|
36
37
|
self.signin = sign
|
|
37
38
|
|
|
38
|
-
def create_mcpserver(self, logger:logging.Logger, args:argparse.Namespace, tools
|
|
39
|
+
def create_mcpserver(self, logger:logging.Logger, args:argparse.Namespace, tools) -> Any:
|
|
39
40
|
"""
|
|
40
41
|
mcpserverを作成します
|
|
41
42
|
|
|
42
43
|
Args:
|
|
43
44
|
logger (logging.Logger): ロガー
|
|
44
45
|
args (argparse.Namespace): 引数
|
|
45
|
-
tools (List[
|
|
46
|
-
web (Any): Web関連のオブジェクト
|
|
46
|
+
tools (List[Callable]): ツールのリスト
|
|
47
47
|
|
|
48
48
|
Returns:
|
|
49
49
|
Any: FastMCP
|
|
@@ -61,85 +61,12 @@ class Mcp:
|
|
|
61
61
|
issuer=issuer,
|
|
62
62
|
audience=audience
|
|
63
63
|
)
|
|
64
|
-
mcp = FastMCP(name=self.ver.__appid__, auth=auth)
|
|
64
|
+
mcp = FastMCP(name=self.ver.__appid__, auth=auth, tools=tools)
|
|
65
65
|
else:
|
|
66
66
|
self.logger.info(f"Using BearerAuthProvider without public key, issuer, or audience.")
|
|
67
67
|
mcp = FastMCP(name=self.ver.__appid__)
|
|
68
68
|
mcp.add_middleware(self.create_mw_logging(self.logger, args))
|
|
69
|
-
mcp.add_middleware(self.create_mw_reqscope(self.logger, args
|
|
70
|
-
|
|
71
|
-
options = Options.getInstance()
|
|
72
|
-
cmd_list:feature.Feature = options.get_cmd_attr('cmd', 'list', "feature")
|
|
73
|
-
language, _ = locale.getlocale()
|
|
74
|
-
is_japan = language.find('Japan') >= 0 or language.find('ja_JP') >= 0
|
|
75
|
-
_self_mcp = self
|
|
76
|
-
from cmdbox.app.web import Web
|
|
77
|
-
from fastmcp.tools import tool, tool_manager
|
|
78
|
-
class CustomToolManager(tool_manager.ToolManager):
|
|
79
|
-
async def _load_tools(self, *, via_server: bool = False) -> dict[str, tool.Tool]:
|
|
80
|
-
if hasattr(self, '_tools') and self._tools:
|
|
81
|
-
return self._tools
|
|
82
|
-
ret = await super()._load_tools(via_server=via_server)
|
|
83
|
-
#scope = signin.get_request_scope()
|
|
84
|
-
#web:Web = scope["web"]
|
|
85
|
-
signin_file = web.signin_file
|
|
86
|
-
#signin_data = signin.Signin.load_signin_file(signin_file)
|
|
87
|
-
#if signin.Signin._check_signin(scope["req"], scope["res"], signin_data, logger) is not None:
|
|
88
|
-
# logger.warning("Unable to execute command because authentication information cannot be obtained")
|
|
89
|
-
# raise Exception("Unable to execute command because authentication information cannot be obtained")
|
|
90
|
-
#groups = scope["req"].session["signin"]["groups"]
|
|
91
|
-
ret_tools = dict()
|
|
92
|
-
# システムコマンドリストのフィルタリング
|
|
93
|
-
for func in tools:
|
|
94
|
-
mode = [t.replace('mode=', '') for t in func.tags if t.startswith('mode=')]
|
|
95
|
-
mode = mode[0] if mode else None
|
|
96
|
-
cmd = [t.replace('cmd=', '') for t in func.tags if t.startswith('cmd=')]
|
|
97
|
-
cmd = cmd[0] if cmd else None
|
|
98
|
-
if mode is None or cmd is None:
|
|
99
|
-
logger.warning(f"Tool {func.name} does not have mode or cmd tag, skipping.")
|
|
100
|
-
continue
|
|
101
|
-
#if not signin.Signin._check_cmd(signin_data, groups, mode, cmd, logger):
|
|
102
|
-
# logger.warning(f"User does not have permission to use tool {func.name} (mode={mode}, cmd={cmd}), skipping.")
|
|
103
|
-
# continue
|
|
104
|
-
ret_tools[func.name] = func
|
|
105
|
-
# ユーザーコマンドリストの取得(すべてのコマンドを取得するためにgroupsをadminに設定)
|
|
106
|
-
args = argparse.Namespace(data=web.data, signin_file=signin_file, groups=['admin'], kwd=None,
|
|
107
|
-
format=False, output_json=None, output_json_append=False,)
|
|
108
|
-
st, ret, _ = cmd_list.apprun(logger, args, time.perf_counter(), [])
|
|
109
|
-
if ret is None or 'success' not in ret or not ret['success']:
|
|
110
|
-
return ret_tools
|
|
111
|
-
for opt in ret['success']:
|
|
112
|
-
func_name = opt['title']
|
|
113
|
-
mode, cmd, description = opt['mode'], opt['cmd'], opt['description'] if 'description' in opt and opt['description'] else ''
|
|
114
|
-
choices = options.get_cmd_choices(mode, cmd, False)
|
|
115
|
-
description += '\n' + options.get_cmd_attr(mode, cmd, 'description_ja' if is_japan else 'description_en')
|
|
116
|
-
# 関数の定義を生成
|
|
117
|
-
func_txt = _self_mcp._create_func_txt(func_name, mode, cmd, is_japan, options, title=opt['title'])
|
|
118
|
-
if logger.level == logging.DEBUG:
|
|
119
|
-
logger.debug(f"generating agent tool: {func_name}")
|
|
120
|
-
func_ctx = []
|
|
121
|
-
# 関数を実行してコンテキストに追加
|
|
122
|
-
exec(func_txt,
|
|
123
|
-
dict(time=time,List=List, Path=Path, argparse=argparse, common=common, options=options, logging=logging, signin=signin,),
|
|
124
|
-
dict(func_ctx=func_ctx))
|
|
125
|
-
# 関数のスキーマを生成
|
|
126
|
-
input_schema = dict(
|
|
127
|
-
type="object",
|
|
128
|
-
properties={o['opt']: _self_mcp._to_schema(o, is_japan) for o in choices},
|
|
129
|
-
required=[],
|
|
130
|
-
)
|
|
131
|
-
output_schema = dict(type="object", properties=dict())
|
|
132
|
-
func_tool = tool.FunctionTool(fn=func_ctx[0], name=func_name, title=func_name.title(), description=description,
|
|
133
|
-
tags=[f"mode={mode}", f"cmd={cmd}"],
|
|
134
|
-
parameters=input_schema, output_schema=output_schema,)
|
|
135
|
-
# ツールリストに追加
|
|
136
|
-
ret_tools[func_name] = func_tool
|
|
137
|
-
self._tools = ret_tools
|
|
138
|
-
return ret_tools
|
|
139
|
-
mcp._tool_manager = CustomToolManager(
|
|
140
|
-
duplicate_behavior=mcp._tool_manager.duplicate_behavior,
|
|
141
|
-
mask_error_details=mcp._tool_manager.mask_error_details
|
|
142
|
-
)
|
|
69
|
+
mcp.add_middleware(self.create_mw_reqscope(self.logger, args))
|
|
143
70
|
return mcp
|
|
144
71
|
|
|
145
72
|
def create_session_service(self, args:argparse.Namespace) -> Any:
|
|
@@ -190,8 +117,7 @@ class Mcp:
|
|
|
190
117
|
"""
|
|
191
118
|
if logger.level == logging.DEBUG:
|
|
192
119
|
logger.debug(f"create_agent processing..")
|
|
193
|
-
|
|
194
|
-
is_japan = language.find('Japan') >= 0 or language.find('ja_JP') >= 0
|
|
120
|
+
is_japan = common.is_japan()
|
|
195
121
|
description = f"{self.ver.__appid__}に登録されているコマンド提供"
|
|
196
122
|
instruction = f"あなたはコマンドの意味を熟知しているエキスパートです。" + \
|
|
197
123
|
f"ユーザーがコマンドを実行したいとき、あなたは以下の手順に従ってコマンドを確実に実行してください。\n" + \
|
|
@@ -441,52 +367,21 @@ class Mcp:
|
|
|
441
367
|
func_txt += f'func_ctx.append({func_name})\n'
|
|
442
368
|
return func_txt
|
|
443
369
|
|
|
444
|
-
def create_tools(self, logger:logging.Logger, args:argparse.Namespace) ->
|
|
370
|
+
def create_tools(self, logger:logging.Logger, args:argparse.Namespace, extract_callable:bool) -> Any:
|
|
445
371
|
"""
|
|
446
372
|
ツールリストを作成します
|
|
447
373
|
|
|
448
374
|
Args:
|
|
449
375
|
logger (logging.Logger): ロガー
|
|
450
376
|
args (argparse.Namespace): 引数
|
|
451
|
-
|
|
377
|
+
extract_callable (bool): コール可能な関数を抽出するかどうか
|
|
378
|
+
|
|
452
379
|
Returns:
|
|
453
|
-
|
|
380
|
+
ToolList: ToolListのリスト
|
|
454
381
|
"""
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
is_japan = language.find('Japan') >= 0 or language.find('ja_JP') >= 0
|
|
459
|
-
func_tools:List[FunctionTool] = []
|
|
460
|
-
for mode in options.get_mode_keys():
|
|
461
|
-
for cmd in options.get_cmd_keys(mode):
|
|
462
|
-
if not options.get_cmd_attr(mode, cmd, 'use_agent'):
|
|
463
|
-
continue
|
|
464
|
-
# コマンドの説明と選択肢を取得
|
|
465
|
-
description = options.get_cmd_attr(mode, cmd, 'description_ja' if is_japan else 'description_en')
|
|
466
|
-
choices = options.get_cmd_choices(mode, cmd, False)
|
|
467
|
-
func_name = f"{mode}_{cmd}"
|
|
468
|
-
# 関数の定義を生成
|
|
469
|
-
func_txt = self._create_func_txt(func_name, mode, cmd, is_japan, options)
|
|
470
|
-
if logger.level == logging.DEBUG:
|
|
471
|
-
logger.debug(f"generating agent tool: {func_name}")
|
|
472
|
-
func_ctx = []
|
|
473
|
-
# 関数を実行してコンテキストに追加
|
|
474
|
-
exec(func_txt,
|
|
475
|
-
dict(time=time,List=List, Path=Path, argparse=argparse, common=common, options=options, logging=logging, signin=signin,),
|
|
476
|
-
dict(func_ctx=func_ctx))
|
|
477
|
-
# 関数のスキーマを生成
|
|
478
|
-
input_schema = dict(
|
|
479
|
-
type="object",
|
|
480
|
-
properties={o['opt']: self._to_schema(o, is_japan) for o in choices},
|
|
481
|
-
required=[o['opt'] for o in choices if o['required']],
|
|
482
|
-
)
|
|
483
|
-
output_schema = dict(type="object", properties=dict())
|
|
484
|
-
func_tool = FunctionTool(fn=func_ctx[0], name=func_name, title=func_name.title(), description=description,
|
|
485
|
-
tags=[f"mode={mode}", f"cmd={cmd}"],
|
|
486
|
-
parameters=input_schema, output_schema=output_schema,)
|
|
487
|
-
# ツールリストに追加
|
|
488
|
-
func_tools.append(func_tool)
|
|
489
|
-
return func_tools
|
|
382
|
+
tool_list = ToolList(self, logger)
|
|
383
|
+
tool_list.extract_callable = extract_callable
|
|
384
|
+
return tool_list
|
|
490
385
|
|
|
491
386
|
def create_mw_logging(self, logger:logging.Logger, args:argparse.Namespace) -> Any:
|
|
492
387
|
"""
|
|
@@ -514,7 +409,7 @@ class Mcp:
|
|
|
514
409
|
raise e
|
|
515
410
|
return LoggingMiddleware()
|
|
516
411
|
|
|
517
|
-
def create_mw_reqscope(self, logger:logging.Logger, args:argparse.Namespace
|
|
412
|
+
def create_mw_reqscope(self, logger:logging.Logger, args:argparse.Namespace) -> Any:
|
|
518
413
|
"""
|
|
519
414
|
認証用のミドルウェアを作成します
|
|
520
415
|
|
|
@@ -526,11 +421,12 @@ class Mcp:
|
|
|
526
421
|
Returns:
|
|
527
422
|
Any: ミドルウェア
|
|
528
423
|
"""
|
|
424
|
+
from cmdbox.app.web import Web
|
|
529
425
|
from fastapi import Response
|
|
530
426
|
from fastmcp.server.middleware import Middleware, MiddlewareContext
|
|
531
427
|
class ReqScopeMiddleware(Middleware):
|
|
532
428
|
async def on_message(self, context: MiddlewareContext, call_next):
|
|
533
|
-
signin.request_scope.set(dict(req=context.fastmcp_context.request_context.request, res=Response(), websocket=None, web=
|
|
429
|
+
signin.request_scope.set(dict(req=context.fastmcp_context.request_context.request, res=Response(), websocket=None, web=Web.getInstance()))
|
|
534
430
|
result = await call_next(context)
|
|
535
431
|
return result
|
|
536
432
|
return ReqScopeMiddleware()
|
|
@@ -557,11 +453,213 @@ class Mcp:
|
|
|
557
453
|
from fastmcp import FastMCP
|
|
558
454
|
from google.adk.sessions import BaseSessionService
|
|
559
455
|
session_service:BaseSessionService = self.create_session_service(args)
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
mcp:FastMCP = self.create_mcpserver(logger, args, tools, web)
|
|
563
|
-
root_agent = self.create_agent(logger, args, [t.fn for t in tools])
|
|
456
|
+
mcp:FastMCP = self.create_mcpserver(logger, args, self.create_tools(logger, args, False))
|
|
457
|
+
root_agent = self.create_agent(logger, args, self.create_tools(logger, args, True))
|
|
564
458
|
runner = self.create_runner(logger, args, session_service, root_agent)
|
|
565
459
|
if logger.level == logging.DEBUG:
|
|
566
460
|
logger.debug(f"init_agent_runner complate.")
|
|
567
461
|
return runner, mcp
|
|
462
|
+
|
|
463
|
+
class ToolList(object):
|
|
464
|
+
def __init__(self, mcp:Mcp, logger:logging.Logger, *args:List):
|
|
465
|
+
"""
|
|
466
|
+
ツールリストを初期化します
|
|
467
|
+
|
|
468
|
+
Args:
|
|
469
|
+
mcp (Mcp): MCPインスタンス
|
|
470
|
+
logger (logging.Logger): ロガー
|
|
471
|
+
*args (List): 追加するツールのリスト
|
|
472
|
+
"""
|
|
473
|
+
from fastmcp.tools import FunctionTool
|
|
474
|
+
options = Options.getInstance()
|
|
475
|
+
is_japan = common.is_japan()
|
|
476
|
+
|
|
477
|
+
self.tools = []
|
|
478
|
+
self.mcp = mcp
|
|
479
|
+
self.logger = logger
|
|
480
|
+
self.extract_callable = False
|
|
481
|
+
for mode in options.get_mode_keys():
|
|
482
|
+
for cmd in options.get_cmd_keys(mode):
|
|
483
|
+
if not options.get_cmd_attr(mode, cmd, 'use_agent'):
|
|
484
|
+
continue
|
|
485
|
+
# コマンドの説明と選択肢を取得
|
|
486
|
+
description = options.get_cmd_attr(mode, cmd, 'description_ja' if is_japan else 'description_en')
|
|
487
|
+
choices = options.get_cmd_choices(mode, cmd, False)
|
|
488
|
+
func_name = f"{mode}_{cmd}"
|
|
489
|
+
# 関数の定義を生成
|
|
490
|
+
func_txt = self.mcp._create_func_txt(func_name, mode, cmd, is_japan, options)
|
|
491
|
+
if self.logger.level == logging.DEBUG:
|
|
492
|
+
self.logger.debug(f"generating agent tool: {func_name}")
|
|
493
|
+
func_ctx = []
|
|
494
|
+
# 関数を実行してコンテキストに追加
|
|
495
|
+
exec(func_txt,
|
|
496
|
+
dict(time=time,List=List, Path=Path, argparse=argparse, common=common, options=options, logging=logging, signin=signin,),
|
|
497
|
+
dict(func_ctx=func_ctx))
|
|
498
|
+
# 関数のスキーマを生成
|
|
499
|
+
input_schema = dict(
|
|
500
|
+
type="object",
|
|
501
|
+
properties={o['opt']: self.mcp._to_schema(o, is_japan) for o in choices},
|
|
502
|
+
required=[o['opt'] for o in choices if o['required']],
|
|
503
|
+
)
|
|
504
|
+
output_schema = dict(type="object", properties=dict())
|
|
505
|
+
func_tool = FunctionTool(fn=func_ctx[0], name=func_name, title=func_name.title(), description=description,
|
|
506
|
+
tags=[f"mode={mode}", f"cmd={cmd}"],
|
|
507
|
+
parameters=input_schema, output_schema=output_schema,)
|
|
508
|
+
# ツールリストに追加
|
|
509
|
+
self.tools.append(func_tool)
|
|
510
|
+
for tool in args:
|
|
511
|
+
if isinstance(tool, FunctionTool):
|
|
512
|
+
if self.logger.level == logging.DEBUG:
|
|
513
|
+
self.logger.debug(f"adding tool: {tool.name}")
|
|
514
|
+
else:
|
|
515
|
+
raise TypeError(f"Expected FunctionTool, got {type(tool)}")
|
|
516
|
+
self.tools.append(tool)
|
|
517
|
+
|
|
518
|
+
@property
|
|
519
|
+
def extract_callable(self):
|
|
520
|
+
"""
|
|
521
|
+
ツールリストから関数を抽出するかどうかを取得します
|
|
522
|
+
|
|
523
|
+
Returns:
|
|
524
|
+
bool: 関数を抽出する場合はTrue、しない場合はFalse
|
|
525
|
+
"""
|
|
526
|
+
return self._extract_callable
|
|
527
|
+
|
|
528
|
+
@extract_callable.setter
|
|
529
|
+
def extract_callable(self, value:bool):
|
|
530
|
+
"""
|
|
531
|
+
ツールリストから関数を抽出するかどうかを設定します
|
|
532
|
+
|
|
533
|
+
Args:
|
|
534
|
+
value (bool): 関数を抽出する場合はTrue、しない場合はFalse
|
|
535
|
+
"""
|
|
536
|
+
if not isinstance(value, bool):
|
|
537
|
+
raise TypeError(f"Expected bool, got {type(value)}")
|
|
538
|
+
self._extract_callable = value
|
|
539
|
+
|
|
540
|
+
def append(self, tool):
|
|
541
|
+
"""
|
|
542
|
+
ツールを追加します
|
|
543
|
+
|
|
544
|
+
Args:
|
|
545
|
+
tool (FunctionTool): 追加するツール
|
|
546
|
+
"""
|
|
547
|
+
from fastmcp.tools import FunctionTool
|
|
548
|
+
if isinstance(tool, FunctionTool):
|
|
549
|
+
self.tools.append(tool)
|
|
550
|
+
else:
|
|
551
|
+
raise TypeError(f"Expected FunctionTool, got {type(tool)}")
|
|
552
|
+
|
|
553
|
+
def pop(self):
|
|
554
|
+
"""
|
|
555
|
+
ツールを取り出します
|
|
556
|
+
|
|
557
|
+
Returns:
|
|
558
|
+
FunctionTool: 取り出したツール
|
|
559
|
+
"""
|
|
560
|
+
if len(self.tools) == 0:
|
|
561
|
+
raise IndexError("No tools available to pop.")
|
|
562
|
+
return self.tools.pop()
|
|
563
|
+
|
|
564
|
+
def __repr__(self):
|
|
565
|
+
"""
|
|
566
|
+
ツールリストの文字列表現を返します
|
|
567
|
+
|
|
568
|
+
Returns:
|
|
569
|
+
str: ツールリストの文字列表現
|
|
570
|
+
"""
|
|
571
|
+
return 'ToolList(' + repr(self.tools) + ')'
|
|
572
|
+
|
|
573
|
+
def __str__(self):
|
|
574
|
+
"""
|
|
575
|
+
ツールリストの文字列表現を返します
|
|
576
|
+
|
|
577
|
+
Returns:
|
|
578
|
+
str: ツールリストの文字列表現
|
|
579
|
+
"""
|
|
580
|
+
return str(self.tools)
|
|
581
|
+
|
|
582
|
+
def __getitem__(self, key:int):
|
|
583
|
+
"""
|
|
584
|
+
ツールリストからツールを取得します
|
|
585
|
+
|
|
586
|
+
Args:
|
|
587
|
+
key (int): インデックス
|
|
588
|
+
Returns:
|
|
589
|
+
FunctionTool: 取得したツール
|
|
590
|
+
"""
|
|
591
|
+
return self.tools[key]
|
|
592
|
+
|
|
593
|
+
def __iter__(self):
|
|
594
|
+
"""
|
|
595
|
+
ツールリストをイテレータとして返します
|
|
596
|
+
|
|
597
|
+
Returns:
|
|
598
|
+
Iterator[FunctionTool]: ツールリストのイテレータ
|
|
599
|
+
"""
|
|
600
|
+
from cmdbox.app.web import Web
|
|
601
|
+
from fastmcp.tools import FunctionTool
|
|
602
|
+
options = Options.getInstance()
|
|
603
|
+
is_japan = common.is_japan()
|
|
604
|
+
ret_tools = self.tools.copy()
|
|
605
|
+
web = Web.getInstance()
|
|
606
|
+
if web.signin.signin_file_data is None:
|
|
607
|
+
# サインインファイルが読み込まれていない場合は登録済みのリストを返す
|
|
608
|
+
if self.extract_callable:
|
|
609
|
+
# 関数を抽出する場合はツールリストから関数を抽出して返す
|
|
610
|
+
return (tool.fn for tool in ret_tools if callable(tool.fn)).__iter__()
|
|
611
|
+
return ret_tools.__iter__()
|
|
612
|
+
try:
|
|
613
|
+
# ユーザーコマンドの読み込み
|
|
614
|
+
paths = glob.glob(str(Path(web.data) / ".cmds" / f"cmd-*.json"))
|
|
615
|
+
cmd_list = [common.loadopt(path, True) for path in paths]
|
|
616
|
+
cmd_list = sorted(cmd_list, key=lambda cmd: cmd["title"])
|
|
617
|
+
# ユーザーコマンドリストの取得(すべてのコマンドを取得するためにgroupsをadminに設定)
|
|
618
|
+
# 実行時にはユーザーのグループに応じて認可する
|
|
619
|
+
cmd_list = [dict(title=r.get('title',''), mode=r['mode'], cmd=r['cmd'],
|
|
620
|
+
description=r.get('description','') + options.get_cmd_attr(r['mode'], r['cmd'], 'description_ja' if is_japan else 'description_en'),
|
|
621
|
+
tag=r.get('tag','')) for r in cmd_list \
|
|
622
|
+
if signin.Signin._check_cmd(web.signin.signin_file_data, ['admin'], r['mode'], r['cmd'], self.logger)]
|
|
623
|
+
|
|
624
|
+
except Exception as e:
|
|
625
|
+
# ユーザーコマンドの読み込みに失敗した場合は警告を出して登録済みのリストを返す
|
|
626
|
+
self.logger.warning(f"Error loading user commands: {e}", exc_info=True)
|
|
627
|
+
if self.extract_callable:
|
|
628
|
+
# 関数を抽出する場合はツールリストから関数を抽出して返す
|
|
629
|
+
return (tool.fn for tool in ret_tools if callable(tool.fn)).__iter__()
|
|
630
|
+
return ret_tools.__iter__()
|
|
631
|
+
_tools_fns = [tool.name for tool in ret_tools]
|
|
632
|
+
# ユーザーコマンドの定義を関数として生成
|
|
633
|
+
for opt in cmd_list:
|
|
634
|
+
func_name = opt['title']
|
|
635
|
+
mode, cmd, description = opt['mode'], opt['cmd'], opt['description'] if 'description' in opt and opt['description'] else ''
|
|
636
|
+
choices = options.get_cmd_choices(mode, cmd, False)
|
|
637
|
+
description += '\n' + options.get_cmd_attr(mode, cmd, 'description_ja' if is_japan else 'description_en')
|
|
638
|
+
# 関数の定義を生成
|
|
639
|
+
func_txt = self.mcp._create_func_txt(func_name, mode, cmd, is_japan, options, title=opt['title'])
|
|
640
|
+
if self.logger.level == logging.DEBUG:
|
|
641
|
+
self.logger.debug(f"generating agent tool: {func_name}")
|
|
642
|
+
func_ctx = []
|
|
643
|
+
# 関数を実行してコンテキストに追加
|
|
644
|
+
exec(func_txt,
|
|
645
|
+
dict(time=time,List=List, Path=Path, argparse=argparse, common=common, options=options, logging=logging, signin=signin,),
|
|
646
|
+
dict(func_ctx=func_ctx))
|
|
647
|
+
# 関数のスキーマを生成
|
|
648
|
+
input_schema = dict(
|
|
649
|
+
type="object",
|
|
650
|
+
properties={o['opt']: self.mcp._to_schema(o, is_japan) for o in choices},
|
|
651
|
+
required=[],
|
|
652
|
+
)
|
|
653
|
+
output_schema = dict(type="object", properties=dict())
|
|
654
|
+
func_tool = FunctionTool(fn=func_ctx[0], name=func_name, title=func_name.title(), description=description,
|
|
655
|
+
tags=[f"mode={mode}", f"cmd={cmd}"],
|
|
656
|
+
parameters=input_schema, output_schema=output_schema,)
|
|
657
|
+
if func_name in _tools_fns:
|
|
658
|
+
# 既に同名の関数が存在する場合は差し替え
|
|
659
|
+
self.logger.warning(f"Function {func_name} already exists, replacing.")
|
|
660
|
+
ret_tools = [tool for tool in ret_tools if tool.name != func_name]
|
|
661
|
+
ret_tools.append(func_tool)
|
|
662
|
+
if self.extract_callable:
|
|
663
|
+
# 関数を抽出する場合はツールリストから関数を抽出して返す
|
|
664
|
+
return (tool.fn for tool in ret_tools if callable(tool.fn)).__iter__()
|
|
665
|
+
return ret_tools.__iter__()
|
cmdbox/app/options.py
CHANGED
|
@@ -389,7 +389,8 @@ class Options:
|
|
|
389
389
|
features_yml = Path(ver.__file__).parent / 'extensions' / 'features.yml'
|
|
390
390
|
#if not features_yml.exists() or not features_yml.is_file():
|
|
391
391
|
# features_yml = Path('.samples/features.yml')
|
|
392
|
-
logger.
|
|
392
|
+
if logger.level == logging.DEBUG:
|
|
393
|
+
logger.debug(f"load features.yml: {features_yml}, is_file={features_yml.is_file()}")
|
|
393
394
|
if features_yml.exists() and features_yml.is_file():
|
|
394
395
|
if self.features_yml_data is None:
|
|
395
396
|
self.features_yml_data = yml = common.load_yml(features_yml)
|
cmdbox/app/web.py
CHANGED
|
@@ -289,7 +289,7 @@ class Web:
|
|
|
289
289
|
pass_miss_count = self.user_data(None, u['uid'], u['name'], 'password', 'pass_miss_count')
|
|
290
290
|
pass_miss_last = self.user_data(None, u['uid'], u['name'], 'password', 'pass_miss_last')
|
|
291
291
|
|
|
292
|
-
if name is None:
|
|
292
|
+
if name is None or name == '':
|
|
293
293
|
ret.append({**u, **dict(last_signin=signin_last, pass_last_update=pass_last_update,
|
|
294
294
|
pass_miss_count=pass_miss_count, pass_miss_last=pass_miss_last)})
|
|
295
295
|
return ret
|
|
@@ -530,7 +530,7 @@ class Web:
|
|
|
530
530
|
signin_data = self.signin.get_data()
|
|
531
531
|
if signin_data is None:
|
|
532
532
|
raise ValueError(f'signin_file_data is None. ({self.signin_file})')
|
|
533
|
-
if name is None:
|
|
533
|
+
if name is None or name == '':
|
|
534
534
|
return copy.deepcopy(signin_data['groups'])
|
|
535
535
|
for g in copy.deepcopy(signin_data['groups']):
|
|
536
536
|
if g['name'] == name:
|
cmdbox/extensions/features.yml
CHANGED
|
@@ -43,6 +43,9 @@ agentrule: # Specifies a list of rules that determi
|
|
|
43
43
|
- mode: cmd # Specify the "mode" as the condition for applying the rule.
|
|
44
44
|
cmds: [list, load] # Specify the "cmd" to which the rule applies. Multiple items can be specified in a list.
|
|
45
45
|
rule: allow # Specifies whether the specified command is allowed or not. Values are allow or deny.
|
|
46
|
+
- mode: client
|
|
47
|
+
cmds: [http]
|
|
48
|
+
rule: allow
|
|
46
49
|
audit:
|
|
47
50
|
enabled: true # Specify whether to enable the audit function.
|
|
48
51
|
write:
|
|
@@ -49,20 +49,11 @@ aliases: # Specify the alias for the specified co
|
|
|
49
49
|
agentrule: # Specifies a list of rules that determine which commands the agent can execute.
|
|
50
50
|
policy: deny # Specify the default policy for the rule. The value can be allow or deny.
|
|
51
51
|
rules: # Specify the rules for the commands that the agent can execute according to the group to which the user belongs.
|
|
52
|
-
- mode:
|
|
53
|
-
cmds: [
|
|
52
|
+
- mode: cmd # Specify the "mode" as the condition for applying the rule.
|
|
53
|
+
cmds: [list, load] # Specify the "cmd" to which the rule applies. Multiple items can be specified in a list.
|
|
54
54
|
rule: allow # Specifies whether the specified command is allowed or not. Values are allow or deny.
|
|
55
55
|
- mode: client
|
|
56
|
-
cmds: [
|
|
57
|
-
rule: allow
|
|
58
|
-
- mode: cmd
|
|
59
|
-
cmds: [list, load]
|
|
60
|
-
rule: allow
|
|
61
|
-
- mode: server
|
|
62
|
-
cmds: [list]
|
|
63
|
-
rule: allow
|
|
64
|
-
- mode: web
|
|
65
|
-
cmds: [gencert, genpass, group_list, user_list]
|
|
56
|
+
cmds: [http]
|
|
66
57
|
rule: allow
|
|
67
58
|
audit:
|
|
68
59
|
enabled: true # Specify whether to enable the audit function.
|
cmdbox/version.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import datetime
|
|
2
2
|
|
|
3
|
-
dt_now = datetime.datetime(2025, 7,
|
|
3
|
+
dt_now = datetime.datetime(2025, 7, 28)
|
|
4
4
|
days_ago = (datetime.datetime.now() - dt_now).days
|
|
5
5
|
__appid__ = 'cmdbox'
|
|
6
6
|
__title__ = 'cmdbox (Command Development Application)'
|
|
7
|
-
__version__ = '0.6.
|
|
7
|
+
__version__ = '0.6.3'
|
|
8
8
|
__copyright__ = f'Copyright © 2023-{dt_now.strftime("%Y")} hamacom2004jp'
|
|
9
9
|
__pypiurl__ = 'https://pypi.org/project/cmdbox/'
|
|
10
10
|
__srcurl__ = 'https://github.com/hamacom2004jp/cmdbox'
|
|
@@ -34,7 +34,8 @@ const render_result_func = (target_elem, result, res_size) => {
|
|
|
34
34
|
// list型の結果をテーブルに変換
|
|
35
35
|
const list2table = (data, table_head, table_body) => {
|
|
36
36
|
data.forEach((row, i) => {
|
|
37
|
-
if(
|
|
37
|
+
if (!row) return;
|
|
38
|
+
if(typeof row == "object" && row['success'] && typeof row['success'] == "object" && !Array.isArray(row['success'])){
|
|
38
39
|
dict2table(row['success'], i==0?table_head:null, table_body, row['output_image']);
|
|
39
40
|
return;
|
|
40
41
|
}
|
|
@@ -10,19 +10,19 @@ cmdbox/logconf_gui.yml,sha256=-95vyd0q-aB1gsabdk8rg9dJ2zRKAZc8hRxyhNOQboU,1076
|
|
|
10
10
|
cmdbox/logconf_mcp.yml,sha256=pED0i1iKP8UoyXE0amFMA5kjV7Qc6_eJCUDVen3L4AU,1069
|
|
11
11
|
cmdbox/logconf_server.yml,sha256=n3c5-KVzjUzcUX5BQ6uE-PN9rp81yXaJql3whyCcSDQ,1091
|
|
12
12
|
cmdbox/logconf_web.yml,sha256=pPbdAwckbK0cgduxcVkx2mbk-Ymz5hVzR4guIsfApMQ,1076
|
|
13
|
-
cmdbox/version.py,sha256=
|
|
13
|
+
cmdbox/version.py,sha256=HTU-X6-2WVXAPOXs7dqpmC2oYd3v69th6uurBQSFxUg,2108
|
|
14
14
|
cmdbox/app/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
15
|
cmdbox/app/app.py,sha256=_UJqSTs3LStGSu3vLMTqOKmpL4x7NQAQb2hUMbEFcg4,9639
|
|
16
16
|
cmdbox/app/client.py,sha256=n986lXeV7hhaki4iyyvsfhNptmCXDFphxlNoNe2XhKg,19542
|
|
17
|
-
cmdbox/app/common.py,sha256=
|
|
17
|
+
cmdbox/app/common.py,sha256=iY4Bl9r0MSSDhZ9Ep3Y45MVBapurKpwkBNCHYb-COnY,28130
|
|
18
18
|
cmdbox/app/edge.py,sha256=2Aav7n4skhP0FUvG6_3JKijHHozA-WcwALgEwNB0DUI,41439
|
|
19
19
|
cmdbox/app/edge_tool.py,sha256=HXxr4Or8QaZ5ueYIN3huv8GnXSnV28RZCmZBUEfiIk0,8062
|
|
20
20
|
cmdbox/app/feature.py,sha256=fK7JP1fc8b9k1zhSNOkWq02ad8i-_wuAX5kyyK2TZdE,10391
|
|
21
21
|
cmdbox/app/filer.py,sha256=L_DSMTvnbN_ffr3JIt0obbOmVoTHEfVm2cAVz3rLH-Q,16059
|
|
22
|
-
cmdbox/app/mcp.py,sha256=
|
|
23
|
-
cmdbox/app/options.py,sha256=
|
|
22
|
+
cmdbox/app/mcp.py,sha256=ZzpfaZHgNSrTY5Jj5KZzm28LLtW7cAMrS8-NSf6eGMc,32635
|
|
23
|
+
cmdbox/app/options.py,sha256=GVGq9ID46czZsWNlCHkVf33DrM-1oY5ea90ej1-UnFQ,46268
|
|
24
24
|
cmdbox/app/server.py,sha256=woOmIk901ONn5a_2yz_b3I1JpLYIF8g42uQRd0_MRuQ,10417
|
|
25
|
-
cmdbox/app/web.py,sha256=
|
|
25
|
+
cmdbox/app/web.py,sha256=1T4cRg6TnhB7LA37sePZFgnZAc1hARC7qS6DrRGFcEc,54035
|
|
26
26
|
cmdbox/app/auth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
27
27
|
cmdbox/app/auth/azure_signin.py,sha256=jJlIZJIGLZCngnJgoxBajaD2s8nM7QoszuN6-FT-5h8,1953
|
|
28
28
|
cmdbox/app/auth/azure_signin_saml.py,sha256=oM2buGTK4t6-OsUuiUXTlZk0YXZL01khuPYVB84dMDU,472
|
|
@@ -48,8 +48,9 @@ cmdbox/app/features/cli/cmdbox_client_file_move.py,sha256=eSj08rmHseZDrqgit5_Jek
|
|
|
48
48
|
cmdbox/app/features/cli/cmdbox_client_file_remove.py,sha256=oupYP04CbAZ-x7MaODjSTuXaHqHTWzuWrOtq00U3rWQ,11554
|
|
49
49
|
cmdbox/app/features/cli/cmdbox_client_file_rmdir.py,sha256=E32Av7_0g-Rlesr9onc4iu-HZGtjfgaM_frLW2jMF7Y,11530
|
|
50
50
|
cmdbox/app/features/cli/cmdbox_client_file_upload.py,sha256=-sAqQiIpqH4wWfv_IAN2EYafHzNjFnOOfuLjyjHPwLc,13407
|
|
51
|
+
cmdbox/app/features/cli/cmdbox_client_http.py,sha256=07nR3MU5BMNcdLza3iaj0cvBfpU0F4YKccq3b6tRC8Q,10004
|
|
51
52
|
cmdbox/app/features/cli/cmdbox_client_server_info.py,sha256=tBGOfFxUQojkVu_o8Jv-VR2QSMnxSLN6EBtHZy5NU6k,9575
|
|
52
|
-
cmdbox/app/features/cli/cmdbox_cmd_list.py,sha256=
|
|
53
|
+
cmdbox/app/features/cli/cmdbox_cmd_list.py,sha256=CNH8jfviZxH5WH1r1O1E2ilkq0J2JBmFGgHSbYrANnQ,6926
|
|
53
54
|
cmdbox/app/features/cli/cmdbox_cmd_load.py,sha256=U1NWnJ_bjGOMCp9mtaqt4ujaDtPkhGnybupX-h15Tuw,6747
|
|
54
55
|
cmdbox/app/features/cli/cmdbox_edge_config.py,sha256=2fppuJ5yAiepq5i4Qj_1w3ciSXhy1sFDK6FFOw5sB68,9472
|
|
55
56
|
cmdbox/app/features/cli/cmdbox_edge_start.py,sha256=PVkvRBaepxqdjswUp1JzQqfzD5xdiPaZYXy72P0rlDE,3823
|
|
@@ -110,7 +111,7 @@ cmdbox/app/features/web/cmdbox_web_users.py,sha256=LZ3BUudBF21wqGO5EWwKvyLMxK_gE
|
|
|
110
111
|
cmdbox/app/features/web/cmdbox_web_usesignout.py,sha256=lBjBj8M8e69uXhdv7H92wZfRRWD2j6kmC_WekSCw5yo,682
|
|
111
112
|
cmdbox/app/features/web/cmdbox_web_versions_cmdbox.py,sha256=hG4ikQc0Qr6He8AhYu8kK1GD5TNjezr-VpmCSAFL7Nk,818
|
|
112
113
|
cmdbox/app/features/web/cmdbox_web_versions_used.py,sha256=xA368ASudYFIrJjWOC1MGmsaAE3Mdd5i-Y8sZBWL7p4,1322
|
|
113
|
-
cmdbox/extensions/features.yml,sha256=
|
|
114
|
+
cmdbox/extensions/features.yml,sha256=Dr8C8x3381oxQmigCM9OEDbOHuYEUCeqbJhIyjSMADk,6749
|
|
114
115
|
cmdbox/extensions/user_list.yml,sha256=P_KdBu9VmNDEh9rEQ4QGKObpeXb34wMF4__uOShLh44,13098
|
|
115
116
|
cmdbox/extensions/sample_project/requirements.txt,sha256=z_gUanGVrPeYUExYeU5_gHiOTy8RKZkaJSeKxOM4mqY,18
|
|
116
117
|
cmdbox/extensions/sample_project/.vscode/launch.json,sha256=Bj_FO1P0lPMfuwZxvyLfwQa0f7Gk276dvcVRjj2aem4,1348
|
|
@@ -123,7 +124,7 @@ cmdbox/extensions/sample_project/sample/app/features/cli/__init__.py,sha256=47DE
|
|
|
123
124
|
cmdbox/extensions/sample_project/sample/app/features/cli/sample_client_time.py,sha256=276227PBveyHqWXah5CHQUWeJZ1W2AA6ujB9Zw8Ydh8,3131
|
|
124
125
|
cmdbox/extensions/sample_project/sample/app/features/cli/sample_server_time.py,sha256=vpMBd-7gymFP9qcpFf9uvPp8dxn5qQv6VcoFw4lSZuo,7444
|
|
125
126
|
cmdbox/extensions/sample_project/sample/app/features/web/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
126
|
-
cmdbox/extensions/sample_project/sample/extensions/features.yml,sha256=
|
|
127
|
+
cmdbox/extensions/sample_project/sample/extensions/features.yml,sha256=JKPm-yRs3Ik41zmuoHPh5oua-G7ricGMMpMQGP9YrcQ,7084
|
|
127
128
|
cmdbox/extensions/sample_project/sample/extensions/user_list.yml,sha256=P_KdBu9VmNDEh9rEQ4QGKObpeXb34wMF4__uOShLh44,13098
|
|
128
129
|
cmdbox/extensions/sample_project/sample/web/assets/sample/favicon.ico,sha256=z-jwmfktVBIsYjhUfCOj7ZNiq55GH-uXtbbDRzk7DHQ,9662
|
|
129
130
|
cmdbox/extensions/sample_project/sample/web/assets/sample/icon.png,sha256=8WmOhepVHG46KG8Sjs4OjZht16dTcgpsNIs972PiVWU,327723
|
|
@@ -335,7 +336,7 @@ cmdbox/web/assets/cmdbox/signin.js,sha256=ZEVJJfYlcROSvEfzlnKBU-ZWU89b5YrwOsAWli
|
|
|
335
336
|
cmdbox/web/assets/cmdbox/svgicon.js,sha256=zXaAD2CiPW9vBannU1EeM6-QV6H_9tWD_d0461pn6pI,12563
|
|
336
337
|
cmdbox/web/assets/cmdbox/users.js,sha256=cMWwoEPigCeJVC_HLy2P8CgFek0Zp7oZDu0IZpWMhHY,30195
|
|
337
338
|
cmdbox/web/assets/cmdbox/view_raw.js,sha256=Cyp3m-BjWGzFXyPCkruQu2d6Wtv5xy2ZGHcVOy0xmSA,2668
|
|
338
|
-
cmdbox/web/assets/cmdbox/view_result.js,sha256=
|
|
339
|
+
cmdbox/web/assets/cmdbox/view_result.js,sha256=yfodJByYU5LYf_UTmBa7NoXLsXYIVvsPk2BEHPmaONE,6888
|
|
339
340
|
cmdbox/web/assets/encodingjs/LICENSE.txt,sha256=mBdECJD6rOMBa4VSrrJFzs67vFDvGuMPVtxvvDbgi9o,1070
|
|
340
341
|
cmdbox/web/assets/encodingjs/encoding.js,sha256=pMUL__JEPZ0hHv1iH1kt-zwfDwJcDzzrD1JpdhEKBy8,297288
|
|
341
342
|
cmdbox/web/assets/encodingjs/encoding.min.js,sha256=Q8LqZsCp1UpROsdrkt6K7gL0XriXIxjVrziq5WrDWBM,227869
|
|
@@ -378,9 +379,9 @@ cmdbox/web/assets/tree-menu/image/file.png,sha256=Uw4zYkHyuoZ_kSVkesHAeSeA_g9_LP
|
|
|
378
379
|
cmdbox/web/assets/tree-menu/image/folder-close.png,sha256=TcgsKTBBF2ejgzekOEDBFBxsJf-Z5u0x9IZVi4GBR-I,284
|
|
379
380
|
cmdbox/web/assets/tree-menu/image/folder-open.png,sha256=DT7y1GRK4oXJkFvqTN_oSGM5ZYARzPvjoCGL6wqkoo0,301
|
|
380
381
|
cmdbox/web/assets/tree-menu/js/tree-menu.js,sha256=-GkZxI7xzHuXXHYQBHAVTcuKX4TtoiMuyIms6Xc3pxk,1029
|
|
381
|
-
cmdbox-0.6.
|
|
382
|
-
cmdbox-0.6.
|
|
383
|
-
cmdbox-0.6.
|
|
384
|
-
cmdbox-0.6.
|
|
385
|
-
cmdbox-0.6.
|
|
386
|
-
cmdbox-0.6.
|
|
382
|
+
cmdbox-0.6.3.dist-info/LICENSE,sha256=sBzzPc5v-5LBuIFi2V4olsnoVg-3EBI0zRX5r19SOxE,1117
|
|
383
|
+
cmdbox-0.6.3.dist-info/METADATA,sha256=o68uXEPaEhHqDp9HvcnpzP4qXBc9KTt8-sLqUcrJjX4,33522
|
|
384
|
+
cmdbox-0.6.3.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
385
|
+
cmdbox-0.6.3.dist-info/entry_points.txt,sha256=1LdoMUjTD_YdxlsAiAiJ1cREcXFG8-Xg2xQTNYoNpT4,47
|
|
386
|
+
cmdbox-0.6.3.dist-info/top_level.txt,sha256=eMEkD5jn8_0PkCAL8h5xJu4qAzF2O8Wf3vegFkKUXR4,7
|
|
387
|
+
cmdbox-0.6.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|