cmdbox 0.5.3.1__py3-none-any.whl → 0.6.0__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.
Potentially problematic release.
This version of cmdbox might be problematic. Click here for more details.
- cmdbox/app/auth/__init__.py +0 -0
- cmdbox/app/auth/azure_signin.py +38 -0
- cmdbox/app/auth/azure_signin_saml.py +12 -0
- cmdbox/app/auth/github_signin.py +38 -0
- cmdbox/app/auth/google_signin.py +32 -0
- cmdbox/app/auth/signin.py +490 -287
- cmdbox/app/auth/signin_saml.py +61 -0
- cmdbox/app/common.py +48 -3
- cmdbox/app/edge.py +182 -213
- cmdbox/app/edge_tool.py +177 -0
- cmdbox/app/feature.py +10 -10
- cmdbox/app/features/cli/agent_base.py +477 -0
- cmdbox/app/features/cli/audit_base.py +1 -1
- cmdbox/app/features/cli/cmdbox_audit_search.py +24 -1
- cmdbox/app/features/cli/cmdbox_client_file_download.py +1 -1
- cmdbox/app/features/cli/cmdbox_cmd_list.py +105 -0
- cmdbox/app/features/cli/cmdbox_cmd_load.py +104 -0
- cmdbox/app/features/cli/cmdbox_edge_config.py +21 -7
- cmdbox/app/features/cli/cmdbox_edge_start.py +1 -1
- cmdbox/app/features/cli/cmdbox_gui_start.py +9 -132
- cmdbox/app/features/cli/cmdbox_gui_stop.py +4 -21
- cmdbox/app/features/cli/cmdbox_server_start.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_apikey_add.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_apikey_del.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_genpass.py +0 -3
- cmdbox/app/features/cli/cmdbox_web_group_add.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_group_del.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_group_edit.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_group_list.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_start.py +119 -104
- cmdbox/app/features/cli/cmdbox_web_stop.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_user_add.py +4 -4
- cmdbox/app/features/cli/cmdbox_web_user_del.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_user_edit.py +4 -4
- cmdbox/app/features/cli/cmdbox_web_user_list.py +1 -1
- cmdbox/app/features/web/cmdbox_web_agent.py +250 -0
- cmdbox/app/features/web/cmdbox_web_do_signin.py +79 -103
- cmdbox/app/features/web/cmdbox_web_exec_cmd.py +8 -3
- cmdbox/app/features/web/cmdbox_web_signin.py +26 -4
- cmdbox/app/features/web/cmdbox_web_users.py +2 -0
- cmdbox/app/options.py +55 -2
- cmdbox/app/web.py +155 -27
- cmdbox/extensions/features.yml +18 -0
- cmdbox/extensions/sample_project/sample/app/features/cli/__init__.py +0 -0
- cmdbox/extensions/sample_project/sample/app/features/web/__init__.py +0 -0
- cmdbox/extensions/sample_project/sample/extensions/features.yml +23 -0
- cmdbox/extensions/sample_project/sample/extensions/user_list.yml +40 -6
- cmdbox/extensions/user_list.yml +37 -6
- cmdbox/licenses/{LICENSE.starlette.0.41.3(BSD License).txt → LICENSE.Authlib.1.5.2(BSD License).txt } +3 -1
- cmdbox/licenses/{LICENSE.pydantic_core.2.33.0(MIT License).txt → LICENSE.Deprecated.1.2.18(MIT License).txt } +2 -2
- cmdbox/licenses/{LICENSE.more-itertools.10.6.0(MIT License).txt → LICENSE.SQLAlchemy.2.0.40(MIT License).txt } +1 -1
- cmdbox/licenses/LICENSE.aiohttp.3.11.18(Apache Software License).txt +13 -0
- cmdbox/licenses/LICENSE.aiosignal.1.3.2(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.async-timeout.5.0.1(Apache Software License).txt +13 -0
- cmdbox/licenses/{LICENSE.watchfiles.1.0.0(MIT License).txt → LICENSE.attrs.25.3.0(UNKNOWN).txt} +1 -1
- cmdbox/licenses/{LICENSE.anyio.4.6.2.post1(MIT License).txt → LICENSE.cachetools.5.5.2(MIT License).txt } +1 -1
- cmdbox/licenses/LICENSE.distro.1.9.0(Apache Software License).txt +202 -0
- cmdbox/licenses/{LICENSE.pydantic_core.2.33.1(MIT License).txt → LICENSE.docstring_parser.0.16(MIT License).txt } +1 -1
- cmdbox/licenses/LICENSE.filelock.3.18.0(The Unlicense (Unlicense)).txt +24 -0
- cmdbox/licenses/LICENSE.frozenlist.1.6.0(Apache-2.0).txt +201 -0
- cmdbox/licenses/{LICENSE.starlette.0.46.1(BSD License).txt → LICENSE.fsspec.2025.3.2(BSD License).txt } +3 -1
- cmdbox/licenses/{LICENSE.argcomplete.3.6.1(Apache Software License).txt → LICENSE.google-adk.0.5.0(Apache Software License).txt } +25 -0
- cmdbox/licenses/LICENSE.google-api-python-client.2.169.0(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.google-auth-httplib2.0.2.0(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.google-auth.2.40.1(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.google-cloud-aiplatform.1.92.0(Apache 2.0).txt +202 -0
- cmdbox/licenses/LICENSE.google-cloud-bigquery.3.31.0(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-cloud-core.2.4.3(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-cloud-resource-manager.1.14.2(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-cloud-secret-manager.2.23.3(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-cloud-speech.2.32.0(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-cloud-storage.2.19.0(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-cloud-trace.1.16.1(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-crc32c.1.7.1(Apache 2.0).txt +202 -0
- cmdbox/licenses/LICENSE.google-genai.1.14.0(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-resumable-media.2.7.2(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.googleapis-common-protos.1.70.0(Apache Software License).txt +202 -0
- cmdbox/licenses/{LICENSE.fastapi.0.115.5(MIT License).txt → LICENSE.graphviz.0.20.3(MIT License).txt } +1 -1
- cmdbox/licenses/LICENSE.grpc-google-iam-v1.0.14.2(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.grpcio-status.1.71.0(Apache Software License).txt +610 -0
- cmdbox/licenses/LICENSE.grpcio.1.71.0(Apache Software License).txt +610 -0
- cmdbox/licenses/{LICENSE.uvicorn.0.34.0(BSD License).txt → LICENSE.httpcore.1.0.9(BSD License).txt } +1 -1
- cmdbox/licenses/LICENSE.httplib2.0.22.0(MIT License).txt +23 -0
- cmdbox/licenses/{LICENSE.tomli.2.1.0(MIT License).txt → LICENSE.httpx-sse.0.4.0(MIT).txt} +1 -1
- cmdbox/licenses/LICENSE.httpx.0.28.1(BSD License).txt +12 -0
- cmdbox/licenses/LICENSE.huggingface-hub.0.31.1(Apache Software License).txt +201 -0
- cmdbox/licenses/{LICENSE.charset-normalizer.3.4.0(MIT License).txt → LICENSE.jsonschema-specifications.2025.4.1(UNKNOWN).txt} +5 -7
- cmdbox/licenses/LICENSE.jsonschema.4.23.0(MIT License).txt +19 -0
- cmdbox/licenses/{LICENSE.pkginfo.1.10.0(MIT License).txt → LICENSE.litellm.1.69.0(MIT License).txt } +6 -1
- cmdbox/licenses/{LICENSE.redis.5.2.1(MIT License).txt → LICENSE.mcp.1.8.0(MIT License).txt } +1 -1
- cmdbox/licenses/LICENSE.multidict.6.4.3(Apache Software License).txt +13 -0
- cmdbox/licenses/{LICENSE.argcomplete.3.5.1(Apache Software License).txt → LICENSE.openai.1.75.0(Apache Software License).txt } +25 -1
- cmdbox/licenses/LICENSE.opentelemetry-api.1.33.0(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.opentelemetry-exporter-gcp-trace.1.9.0(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.opentelemetry-resourcedetector-gcp.1.9.0a0(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.opentelemetry-sdk.1.33.0(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.opentelemetry-semantic-conventions.0.54b0(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.propcache.0.3.1(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.proto-plus.1.26.1(Apache Software License).txt +202 -0
- cmdbox/licenses/{LICENSE.Pygments.2.18.0(BSD License).txt → LICENSE.protobuf.5.29.4(3-Clause BSD License).txt } +15 -8
- cmdbox/licenses/LICENSE.pyasn1.0.6.1(BSD License).txt +24 -0
- cmdbox/licenses/LICENSE.pyasn1_modules.0.4.2(BSD License).txt +24 -0
- cmdbox/licenses/LICENSE.pydantic-settings.2.9.1(MIT License).txt +21 -0
- cmdbox/licenses/{LICENSE.gevent.25.4.1(MIT).txt → LICENSE.pyparsing.3.2.3(MIT License).txt } +5 -12
- cmdbox/licenses/LICENSE.python-dateutil.2.9.0.post0(Apache Software License; BSD License).txt +54 -0
- cmdbox/licenses/LICENSE.referencing.0.36.2(UNKNOWN).txt +19 -0
- cmdbox/licenses/LICENSE.regex.2024.11.6(Apache Software License).txt +208 -0
- cmdbox/licenses/LICENSE.rpds-py.0.24.0(MIT).txt +19 -0
- cmdbox/licenses/{LICENSE.python-multipart.0.0.17(Apache Software License).txt → LICENSE.rsa.4.9.1(Apache Software License).txt } +1 -2
- cmdbox/licenses/{LICENSE.sphinx-intl.2.3.0(BSD License).txt → LICENSE.shapely.2.1.0(BSD License).txt } +6 -2
- cmdbox/licenses/LICENSE.sse-starlette.2.3.4(BSD License).txt +27 -0
- cmdbox/licenses/LICENSE.tiktoken.0.9.0(MIT License).txt +21 -0
- cmdbox/licenses/LICENSE.tokenizers.0.21.1(Apache Software License).txt +1 -0
- cmdbox/licenses/{LICENSE.six.1.16.0(MIT License).txt → LICENSE.tqdm.4.67.1(MIT License; Mozilla Public License 2.0 (MPL 2.0)).txt } +32 -1
- cmdbox/licenses/{LICENSE.rich.13.9.4(MIT License).txt → LICENSE.tzlocal.5.3.1(MIT License).txt } +3 -3
- cmdbox/licenses/LICENSE.uritemplate.4.1.1(Apache Software License; BSD License).txt +3 -0
- cmdbox/licenses/LICENSE.wrapt.1.17.2(BSD License).txt +24 -0
- cmdbox/licenses/LICENSE.yarl.1.20.0(Apache Software License).txt +202 -0
- cmdbox/licenses/files.txt +111 -17
- cmdbox/logconf_agent.yml +38 -0
- cmdbox/logconf_audit.yml +13 -5
- cmdbox/logconf_client.yml +13 -5
- cmdbox/logconf_cmdbox.yml +13 -5
- cmdbox/logconf_edge.yml +13 -5
- cmdbox/logconf_gui.yml +13 -5
- cmdbox/logconf_server.yml +13 -5
- cmdbox/logconf_web.yml +13 -5
- cmdbox/version.py +3 -2
- cmdbox/web/agent.html +263 -0
- cmdbox/web/assets/cmdbox/agent.js +335 -0
- cmdbox/web/assets/cmdbox/common.js +1111 -1020
- cmdbox/web/assets/cmdbox/signin.js +16 -3
- cmdbox/web/assets/cmdbox/users.js +1 -1
- cmdbox/web/assets/filer/filer.js +4 -2
- cmdbox/web/signin.html +10 -6
- {cmdbox-0.5.3.1.dist-info → cmdbox-0.6.0.dist-info}/METADATA +132 -35
- {cmdbox-0.5.3.1.dist-info → cmdbox-0.6.0.dist-info}/RECORD +161 -123
- cmdbox/app/features/web/cmdbox_web_load_pin.py +0 -43
- cmdbox/app/features/web/cmdbox_web_save_pin.py +0 -42
- cmdbox/licenses/LICENSE.Jinja2.3.1.4(BSD License).txt +0 -28
- cmdbox/licenses/LICENSE.Sphinx.8.1.3(BSD License).txt +0 -31
- cmdbox/licenses/LICENSE.babel.2.16.0(BSD License).txt +0 -27
- cmdbox/licenses/LICENSE.certifi.2025.1.31(Mozilla Public License 2.0 (MPL 2.0)).txt +0 -20
- cmdbox/licenses/LICENSE.click.8.1.8(BSD License).txt +0 -28
- cmdbox/licenses/LICENSE.cryptography.44.0.2(Apache Software License; BSD License).txt +0 -3
- cmdbox/licenses/LICENSE.greenlet.3.2.0(MIT AND Python-2.0).txt +0 -30
- cmdbox/licenses/LICENSE.keyring.25.5.0(MIT License).txt +0 -17
- cmdbox/licenses/LICENSE.numpy.2.2.4(BSD License).txt +0 -950
- cmdbox/licenses/LICENSE.pillow.11.0.0(CMU License (MIT-CMU)).txt +0 -1226
- cmdbox/licenses/LICENSE.pillow.11.1.0(CMU License (MIT-CMU)).txt +0 -1213
- cmdbox/licenses/LICENSE.prettytable.3.12.0(BSD License).txt +0 -30
- cmdbox/licenses/LICENSE.prompt_toolkit.3.0.50(BSD License).txt +0 -27
- cmdbox/licenses/LICENSE.psycopg.3.2.6(GNU Lesser General Public License v3 (LGPLv3)).txt +0 -165
- cmdbox/licenses/LICENSE.pydantic.2.11.1(MIT License).txt +0 -21
- cmdbox/licenses/LICENSE.pydantic.2.11.3(MIT License).txt +0 -21
- cmdbox/licenses/LICENSE.python-dotenv.1.0.1(BSD License).txt +0 -27
- cmdbox/licenses/LICENSE.twine.5.1.1(Apache Software License).txt +0 -174
- cmdbox/licenses/LICENSE.typing_extensions.4.13.0(UNKNOWN).txt +0 -279
- cmdbox/licenses/LICENSE.urllib3.2.2.3(MIT License).txt +0 -21
- cmdbox/licenses/LICENSE.urllib3.2.3.0(MIT License).txt +0 -21
- cmdbox/licenses/LICENSE.uvicorn.0.34.1(BSD License).txt +0 -27
- cmdbox/licenses/LICENSE.watchfiles.1.0.4(MIT License).txt +0 -21
- cmdbox/licenses/LICENSE.websockets.14.1(BSD License).txt +0 -24
- cmdbox/licenses/LICENSE.zope.interface.7.1.1(Zope Public License).txt +0 -44
- /cmdbox/licenses/{LICENSE.typing_extensions.4.12.2(Python Software Foundation License).txt → LICENSE.aiohappyeyeballs.2.6.1(Python Software Foundation License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.certifi.2024.8.30(Mozilla Public License 2.0 (MPL 2.0)).txt → LICENSE.certifi.2025.4.26(Mozilla Public License 2.0 (MPL 2.0)).txt} +0 -0
- /cmdbox/licenses/{LICENSE.charset-normalizer.3.4.1(MIT License).txt → LICENSE.charset-normalizer.3.4.2(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.click.8.1.7(BSD License).txt → LICENSE.click.8.2.0(UNKNOWN).txt} +0 -0
- /cmdbox/licenses/{LICENSE.cryptography.43.0.3(Apache Software License; BSD License).txt → LICENSE.cryptography.44.0.3(Apache Software License; BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.gevent.24.11.1(MIT License).txt → LICENSE.gevent.25.4.2(MIT).txt} +0 -0
- /cmdbox/licenses/{LICENSE.importlib_metadata.8.5.0(Apache Software License).txt → LICENSE.google-api-core.2.24.2(Apache Software License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.greenlet.3.1.1(MIT License).txt → LICENSE.greenlet.3.2.2(MIT AND Python-2.0).txt} +0 -0
- /cmdbox/licenses/{LICENSE.h11.0.14.0(MIT License).txt → LICENSE.h11.0.16.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.nh3.0.2.18(MIT).txt → LICENSE.jiter.0.9.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.more-itertools.10.5.0(MIT License).txt → LICENSE.more-itertools.10.7.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.numpy.2.1.3(BSD License).txt → LICENSE.numpy.2.2.5(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.packaging.24.2(Apache Software License; BSD License).txt → LICENSE.packaging.25.0(Apache Software License; BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.psycopg-binary.3.2.6(GNU Lesser General Public License v3 (LGPLv3)).txt → LICENSE.psycopg-binary.3.2.7(GNU Lesser General Public License v3 (LGPLv3)).txt} +0 -0
- /cmdbox/licenses/{LICENSE.psycopg-pool.3.2.6(GNU Lesser General Public License v3 (LGPLv3)).txt → LICENSE.psycopg.3.2.7(GNU Lesser General Public License v3 (LGPLv3)).txt} +0 -0
- /cmdbox/licenses/{LICENSE.pydantic.2.10.2(MIT License).txt → LICENSE.pydantic.2.11.4(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.pydantic_core.2.27.1(MIT License).txt → LICENSE.pydantic_core.2.33.2(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.redis.5.2.0(MIT License).txt → LICENSE.redis.6.0.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.snowballstemmer.2.2.0(BSD License).txt → LICENSE.snowballstemmer.3.0.1(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.uvicorn.0.32.1(BSD License).txt → LICENSE.uvicorn.0.34.2(BSD License).txt} +0 -0
- {cmdbox-0.5.3.1.dist-info → cmdbox-0.6.0.dist-info}/LICENSE +0 -0
- {cmdbox-0.5.3.1.dist-info → cmdbox-0.6.0.dist-info}/WHEEL +0 -0
- {cmdbox-0.5.3.1.dist-info → cmdbox-0.6.0.dist-info}/entry_points.txt +0 -0
- {cmdbox-0.5.3.1.dist-info → cmdbox-0.6.0.dist-info}/top_level.txt +0 -0
cmdbox/app/edge_tool.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
from cmdbox.app import common
|
|
2
|
+
from cmdbox.app.commons import convert
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Dict, Any, Tuple
|
|
5
|
+
import logging
|
|
6
|
+
import requests
|
|
7
|
+
import webbrowser
|
|
8
|
+
import urllib.parse
|
|
9
|
+
import urllib3
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Tool(object):
|
|
13
|
+
def __init__(self, logger:logging.Logger, appcls=None, ver=None):
|
|
14
|
+
self.logger = logger
|
|
15
|
+
self.appcls = appcls
|
|
16
|
+
self.ver = ver
|
|
17
|
+
|
|
18
|
+
def notify(self, message:dict):
|
|
19
|
+
"""
|
|
20
|
+
通知メッセージを表示します
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
message (dict): メッセージ
|
|
24
|
+
"""
|
|
25
|
+
if type(message) is list:
|
|
26
|
+
message = message[0]
|
|
27
|
+
if type(message) is not dict:
|
|
28
|
+
message = {"info":str(message)}
|
|
29
|
+
if self.logger.level == logging.DEBUG:
|
|
30
|
+
self.logger.debug(f"notify: {common.to_str(message, slise=256)}")
|
|
31
|
+
try:
|
|
32
|
+
if 'success' in message and type(message['success']) == dict:
|
|
33
|
+
message = "\n".join([f"{k}:{v}" for k, v in message['success'].items()])
|
|
34
|
+
message = f'Success\n{message}'
|
|
35
|
+
else:
|
|
36
|
+
message = "\n".join([f"{k} : {v}" for k, v in message.items()])
|
|
37
|
+
import plyer
|
|
38
|
+
if hasattr(self, 'icon_path') and self.icon_path is not None:
|
|
39
|
+
plyer.notification.notify(title=self.ver.__title__, message=str(message)[:256], app_icon=str(self.icon_path))
|
|
40
|
+
else:
|
|
41
|
+
plyer.notification.notify(title=self.ver.__title__, message=str(message)[:256])
|
|
42
|
+
except Exception as e:
|
|
43
|
+
self.logger.error(f"notify error. {e}", exc_info=True)
|
|
44
|
+
|
|
45
|
+
def set_session(self, session:requests.Session, svcert_no_verify:bool, endpoint:str, icon_path:Path, user_info:Dict[str, Any], oauth2:str, saml:str):
|
|
46
|
+
"""
|
|
47
|
+
セッションを設定します
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
session (requests.Session): セッション
|
|
51
|
+
svcert_no_verify (bool): サーバー証明書の検証を行わない
|
|
52
|
+
endpoint (str): エンドポイント
|
|
53
|
+
icon_path (Path): アイコン画像のパス
|
|
54
|
+
user_info (Dict[str, Any]): ユーザー情報
|
|
55
|
+
oauth2 (str): OAuth2
|
|
56
|
+
"""
|
|
57
|
+
self.session = session
|
|
58
|
+
self.svcert_no_verify = svcert_no_verify
|
|
59
|
+
self.endpoint = endpoint
|
|
60
|
+
self.icon_path = icon_path
|
|
61
|
+
self.user = user_info
|
|
62
|
+
self.oauth2 = oauth2
|
|
63
|
+
self.saml = saml
|
|
64
|
+
|
|
65
|
+
def exec_cmd(self, opt:Dict[str, Any], logger:logging.Logger, timeout:int, prevres:Any=None) -> Tuple[int, Dict[str, Any]]:
|
|
66
|
+
"""
|
|
67
|
+
この機能のエッジ側の実行を行います
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
opt (Dict[str, Any]): オプション
|
|
71
|
+
logger (logging.Logger): ロガー
|
|
72
|
+
timeout (int): タイムアウト時間
|
|
73
|
+
prevres (Any): 前コマンドの結果。pipeline実行の実行結果を参照する時に使用します。
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
Tuple[int, Dict[str, Any], Any]: 終了コード, 結果
|
|
77
|
+
"""
|
|
78
|
+
if logger.level == logging.DEBUG:
|
|
79
|
+
logger.debug(f"exec_cmd: {self.endpoint}/exec_cmd/{opt['title']}")
|
|
80
|
+
if prevres is not None:
|
|
81
|
+
headers = {'content-type':'application/octet-stream'}
|
|
82
|
+
prevres = common.to_str(prevres)
|
|
83
|
+
res = self.session.post(f"{self.endpoint}/exec_cmd/{opt['title']}", headers=headers, data=prevres,
|
|
84
|
+
verify=not self.svcert_no_verify, timeout=timeout, allow_redirects=False)
|
|
85
|
+
else:
|
|
86
|
+
res = self.session.post(f"{self.endpoint}/exec_cmd/{opt['title']}",
|
|
87
|
+
verify=not self.svcert_no_verify, timeout=timeout, allow_redirects=False)
|
|
88
|
+
|
|
89
|
+
if res.status_code != 200:
|
|
90
|
+
msg = dict(warn=f"Access failed. status_code={res.status_code}")
|
|
91
|
+
logger.warning(f"Access failed. status_code={res.status_code}")
|
|
92
|
+
return 1, msg
|
|
93
|
+
else:
|
|
94
|
+
ret = msg = res.json()
|
|
95
|
+
if isinstance(msg, list):
|
|
96
|
+
if len(msg) == 0:
|
|
97
|
+
logger.warning(f"No result.")
|
|
98
|
+
return 1, dict(warn="No result.")
|
|
99
|
+
msg = msg[0]
|
|
100
|
+
if isinstance(msg, dict) and 'success' not in msg:
|
|
101
|
+
logger.warning(f"{msg}")
|
|
102
|
+
return 1, ret
|
|
103
|
+
if logger.level == logging.DEBUG:
|
|
104
|
+
logger.debug(f"{common.to_str(ret, slise=255)}")
|
|
105
|
+
return 0, ret
|
|
106
|
+
|
|
107
|
+
def pub_result(self, title:str, output:str, timeout:int) -> Tuple[int, Dict[str, Any]]:
|
|
108
|
+
"""
|
|
109
|
+
結果を公開します
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
title (str): タイトル
|
|
113
|
+
output (str): 出力
|
|
114
|
+
logger (logging.Logger): ロガー
|
|
115
|
+
timeout (int): タイムアウト時間
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
Tuple[int, Dict[str, Any]]: 終了コード, メッセージ
|
|
119
|
+
"""
|
|
120
|
+
output = common.to_str(output)
|
|
121
|
+
data = f'title={urllib.parse.quote(title)}&output={urllib.parse.quote(output)}'
|
|
122
|
+
headers = {'content-type':'application/x-www-form-urlencoded'}
|
|
123
|
+
res = self.session.post(f"{self.endpoint}/result/pub", headers=headers, data=data,
|
|
124
|
+
verify=not self.svcert_no_verify, timeout=timeout, allow_redirects=False)
|
|
125
|
+
if res.status_code != 200:
|
|
126
|
+
msg = dict(warn=f"Access failed. status_code={res.status_code}")
|
|
127
|
+
return 1, msg
|
|
128
|
+
else:
|
|
129
|
+
msg = res.json()
|
|
130
|
+
return 0, msg
|
|
131
|
+
|
|
132
|
+
def open_browser(self, path:str) -> Tuple[int, Dict[str, str]]:
|
|
133
|
+
"""
|
|
134
|
+
指定したパスをブラウザで開きます。
|
|
135
|
+
この時認証情報を含めて開きます。
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
path (str): パス
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
Tuple[int, Dict[str, str]]: 終了コード, メッセージ
|
|
142
|
+
"""
|
|
143
|
+
path = f"/{path}" if not path.startswith('/') else path
|
|
144
|
+
if not hasattr(self, 'user'):
|
|
145
|
+
webbrowser.open(f"{self.endpoint}{path}")
|
|
146
|
+
return 0, dict(success="Open browser.")
|
|
147
|
+
token = dict(auth_type=self.user['auth_type'])
|
|
148
|
+
if self.user['auth_type'] == "noauth":
|
|
149
|
+
webbrowser.open(f"{self.endpoint}{path}")
|
|
150
|
+
return 0, dict(success="Open browser.")
|
|
151
|
+
elif self.user['auth_type'] == "idpw":
|
|
152
|
+
hashed = self.user['password'] if self.user['hash']=='plain' else common.hash_password(self.user['password'], self.user['hash'])
|
|
153
|
+
token = dict(**token, **dict(user=self.user['name'], token=common.encrypt(path, hashed)))
|
|
154
|
+
token = convert.str2b64str(common.to_str(token))
|
|
155
|
+
webbrowser.open(f"{self.endpoint}/dosignin_token/{token}{path}")
|
|
156
|
+
return 0, dict(success="Open browser.")
|
|
157
|
+
elif self.user['auth_type'] == "apikey":
|
|
158
|
+
hashed = common.hash_password(self.user['apikey'], 'sha1')
|
|
159
|
+
token = dict(**token, **dict(user=self.user['name'], token=common.encrypt(path, hashed)))
|
|
160
|
+
token = convert.str2b64str(common.to_str(token))
|
|
161
|
+
webbrowser.open(f"{self.endpoint}/dosignin_token/{token}{path}")
|
|
162
|
+
return 0, dict(success="Open browser.")
|
|
163
|
+
elif self.user['auth_type'] == "oauth2":
|
|
164
|
+
if self.oauth2 == 'google':
|
|
165
|
+
webbrowser.open(f"{self.endpoint}/oauth2/google/session/{self.user['access_token']}{path}")
|
|
166
|
+
return 0, dict(success="Open browser.")
|
|
167
|
+
if self.oauth2 == 'github':
|
|
168
|
+
webbrowser.open(f"{self.endpoint}/oauth2/github/session/{self.user['access_token']}{path}")
|
|
169
|
+
return 0, dict(success="Open browser.")
|
|
170
|
+
if self.oauth2 == 'azure':
|
|
171
|
+
webbrowser.open(f"{self.endpoint}/oauth2/azure/session/{self.user['access_token']}{path}")
|
|
172
|
+
return 0, dict(success="Open browser.")
|
|
173
|
+
elif self.user['auth_type'] == "saml":
|
|
174
|
+
if self.saml == 'azure':
|
|
175
|
+
webbrowser.open(f"{self.endpoint}/saml/azure/session/{self.user['saml_token']}{path}")
|
|
176
|
+
return 0, dict(success="Open browser.")
|
|
177
|
+
return 1, dict(warn="unsupported auth_type.")
|
cmdbox/app/feature.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from cmdbox import version
|
|
2
|
-
from cmdbox.app import
|
|
3
|
-
from cmdbox.app.commons import redis_client
|
|
2
|
+
from cmdbox.app import common, edge_tool
|
|
3
|
+
from cmdbox.app.commons import convert, redis_client
|
|
4
4
|
from cmdbox.app.web import Web
|
|
5
5
|
from fastapi import FastAPI
|
|
6
6
|
from pathlib import Path
|
|
@@ -8,7 +8,6 @@ from typing import Dict, Any, Tuple, List, Union
|
|
|
8
8
|
import argparse
|
|
9
9
|
import logging
|
|
10
10
|
import os
|
|
11
|
-
import time
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
class Feature(object):
|
|
@@ -28,6 +27,7 @@ class Feature(object):
|
|
|
28
27
|
self.ver = ver
|
|
29
28
|
self.appcls = appcls
|
|
30
29
|
self.default_svname:str = ver.__appid__
|
|
30
|
+
self.default_data:Path = os.environ.get('DATA_DIR', common.HOME_DIR / f".{self.ver.__appid__}")
|
|
31
31
|
|
|
32
32
|
def get_mode(self) -> Union[str, List[str]]:
|
|
33
33
|
"""
|
|
@@ -106,13 +106,13 @@ class Feature(object):
|
|
|
106
106
|
"""
|
|
107
107
|
raise NotImplementedError
|
|
108
108
|
|
|
109
|
-
def edgerun(self, opt:Dict[str, Any], tool:
|
|
109
|
+
def edgerun(self, opt:Dict[str, Any], tool:edge_tool.Tool, logger:logging.Logger, timeout:int, prevres:Any=None):
|
|
110
110
|
"""
|
|
111
111
|
この機能のエッジ側の実行を行います
|
|
112
112
|
|
|
113
113
|
Args:
|
|
114
114
|
opt (Dict[str, Any]): オプション
|
|
115
|
-
tool (
|
|
115
|
+
tool (edge_tool.Tool): 通知関数などedge側のUI操作を行うためのクラス
|
|
116
116
|
logger (logging.Logger): ロガー
|
|
117
117
|
timeout (int): タイムアウト時間
|
|
118
118
|
prevres (Any): 前コマンドの結果。pipeline実行の実行結果を参照する時に使用します。
|
|
@@ -127,7 +127,7 @@ class OneshotEdgeFeature(Feature):
|
|
|
127
127
|
"""
|
|
128
128
|
一度だけ実行するエッジ機能の基底クラス
|
|
129
129
|
"""
|
|
130
|
-
def edgerun(self, opt:Dict[str, Any], tool:
|
|
130
|
+
def edgerun(self, opt:Dict[str, Any], tool:edge_tool.Tool, logger:logging.Logger, timeout:int, prevres:Any=None):
|
|
131
131
|
status, res = tool.exec_cmd(opt, logger, timeout, prevres)
|
|
132
132
|
yield 1, res
|
|
133
133
|
|
|
@@ -135,7 +135,7 @@ class OneshotNotifyEdgeFeature(OneshotEdgeFeature):
|
|
|
135
135
|
"""
|
|
136
136
|
実行結果の通知を行うエッジ機能の基底クラス
|
|
137
137
|
"""
|
|
138
|
-
def edgerun(self, opt:Dict[str, Any], tool:
|
|
138
|
+
def edgerun(self, opt:Dict[str, Any], tool:edge_tool.Tool, logger:logging.Logger, timeout:int, prevres:Any=None):
|
|
139
139
|
status, res = next(super().edgerun(opt, tool, logger, timeout, prevres))
|
|
140
140
|
tool.notify(res)
|
|
141
141
|
yield status, res
|
|
@@ -144,7 +144,7 @@ class ResultEdgeFeature(Feature):
|
|
|
144
144
|
"""
|
|
145
145
|
実行結果をWebブラウザで表示するエッジ機能の基底クラス
|
|
146
146
|
"""
|
|
147
|
-
def edgerun(self, opt:Dict[str, Any], tool:
|
|
147
|
+
def edgerun(self, opt:Dict[str, Any], tool:edge_tool.Tool, logger:logging.Logger, timeout:int, prevres:Any=None):
|
|
148
148
|
status, res = next(super().edgerun(opt, tool, logger, timeout, prevres))
|
|
149
149
|
if status == 0:
|
|
150
150
|
status, res = tool.pub_result(opt['title'], res, timeout)
|
|
@@ -156,7 +156,7 @@ class OneshotResultEdgeFeature(ResultEdgeFeature):
|
|
|
156
156
|
"""
|
|
157
157
|
一度だけ実行結果をWebブラウザで表示するエッジ機能の基底クラス
|
|
158
158
|
"""
|
|
159
|
-
def edgerun(self, opt:Dict[str, Any], tool:
|
|
159
|
+
def edgerun(self, opt:Dict[str, Any], tool:edge_tool.Tool, logger:logging.Logger, timeout:int, prevres:Any=None):
|
|
160
160
|
status, res = next(super().edgerun(opt, tool, logger, timeout, prevres))
|
|
161
161
|
yield 1, res
|
|
162
162
|
|
|
@@ -164,7 +164,7 @@ class UnsupportEdgeFeature(Feature):
|
|
|
164
164
|
"""
|
|
165
165
|
サポートされていないエッジ機能の基底クラス
|
|
166
166
|
"""
|
|
167
|
-
def edgerun(self, opt:Dict[str, Any], tool:
|
|
167
|
+
def edgerun(self, opt:Dict[str, Any], tool:edge_tool.Tool, logger:logging.Logger, timeout:int, prevres:Any=None):
|
|
168
168
|
res = dict(warn=f'Unsupported edgerun. mode="{opt["mode"]}", cmd="{opt["cmd"]}"')
|
|
169
169
|
tool.notify(res)
|
|
170
170
|
yield 1, res
|