domino-proxy 0.17.8__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.
- domino_agent.py +209 -0
- domino_agent_backend.py +40 -0
- domino_cli.py +2545 -0
- domino_completion.py +165 -0
- domino_install.py +30 -0
- domino_linux.py +289 -0
- domino_logs.py +64 -0
- domino_macos.py +557 -0
- domino_model.py +85 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/CHANGELOG.md +343 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/CONTRIBUTING.md +68 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/LICENSE +674 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/NOTICE +24 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/README.md +163 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/README.pypi.md +49 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/SECURITY.md +13 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/assets/README.md +18 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/assets/domino-logo.gif +0 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/assets/domino-logo.png +0 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/docs/AGENT.md +162 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/docs/ARCHITECTURE.md +40 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/docs/DELIVERY.md +120 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/docs/DISTRIBUTION.md +164 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/docs/PLATFORMS.md +45 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/docs/USAGE.md +796 -0
- domino_proxy-0.17.8.data/data/share/doc/domino/licenses/mihomo-GPL-3.0.txt +674 -0
- domino_proxy-0.17.8.dist-info/METADATA +90 -0
- domino_proxy-0.17.8.dist-info/RECORD +42 -0
- domino_proxy-0.17.8.dist-info/WHEEL +5 -0
- domino_proxy-0.17.8.dist-info/entry_points.txt +3 -0
- domino_proxy-0.17.8.dist-info/licenses/LICENSE +674 -0
- domino_proxy-0.17.8.dist-info/licenses/NOTICE +24 -0
- domino_proxy-0.17.8.dist-info/licenses/licenses/mihomo-GPL-3.0.txt +674 -0
- domino_proxy-0.17.8.dist-info/top_level.txt +17 -0
- domino_resources.py +102 -0
- domino_service.py +627 -0
- domino_shell.py +437 -0
- domino_sources.py +396 -0
- domino_store.py +98 -0
- domino_subscriptions.py +921 -0
- domino_tui.py +1171 -0
- install_domino.py +2472 -0
domino_agent.py
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
# Copyright (C) 2026 KJaebye
|
|
3
|
+
"""Versioned noninteractive CLI adapter for external agents."""
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import json
|
|
8
|
+
import re
|
|
9
|
+
import subprocess
|
|
10
|
+
import sys
|
|
11
|
+
import hashlib
|
|
12
|
+
import shlex
|
|
13
|
+
from contextlib import contextmanager
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from domino_model import DomainError, Result, operation_id
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Parser(argparse.ArgumentParser):
|
|
19
|
+
def error(self, message):
|
|
20
|
+
raise DomainError('机器接口参数无效。',code='INVALID_ARGUMENT',exit_code=2)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def command_request(args):
|
|
24
|
+
command=args.command
|
|
25
|
+
if command=='call': return args.operation,{}
|
|
26
|
+
if command=='capabilities': return command,{}
|
|
27
|
+
if command=='status': return 'status.get',{}
|
|
28
|
+
if command=='scan':
|
|
29
|
+
if args.source: return 'source.inspect',{'path':args.source}
|
|
30
|
+
return 'source.list',{}
|
|
31
|
+
if command=='nodes': return 'nodes.list',({'group':args.group} if args.group else {})
|
|
32
|
+
if command=='select': return 'nodes.select',{'group':args.group,'node':args.node}
|
|
33
|
+
if command in ['start','stop','restart']: return 'service.'+command,{}
|
|
34
|
+
if command=='rollback': return 'service.rollback',({'backup':args.backup} if args.backup else {})
|
|
35
|
+
if command=='logs':
|
|
36
|
+
if args.follow: raise DomainError('JSON 日志请求需为有界读取。',code='INVALID_ARGUMENT',exit_code=2)
|
|
37
|
+
return 'logs.read',{'lines':args.lines}
|
|
38
|
+
if command in ['mode','log']:
|
|
39
|
+
operation = 'log-level' if command == 'log' else command
|
|
40
|
+
return operation+('.set' if args.set else '.get'),({'value':args.set} if args.set else {})
|
|
41
|
+
if command=='configs':
|
|
42
|
+
action=next((name for name in ['add','use','update','update_all','rename','remove','set_url','import_current'] if getattr(args,name,None)),None)
|
|
43
|
+
if action:
|
|
44
|
+
parameters={} if action=='update_all' else {'name':getattr(args,action)}
|
|
45
|
+
parameters.update({key:getattr(args,key) for key in ['new_name','url'] if getattr(args,key,None) is not None})
|
|
46
|
+
return 'configs.'+{'use':'switch','set_url':'set-url','import_current':'snapshot'}.get(action,action),parameters
|
|
47
|
+
return 'configs.list',{}
|
|
48
|
+
if command=='shell': return 'shell.'+(args.set or 'status'),{}
|
|
49
|
+
if command=='proxy': return 'proxy.'+(args.set or 'status'),({'service':args.service} if args.service else {})
|
|
50
|
+
if command=='connections':
|
|
51
|
+
return ('connections.close',{'id':args.close}) if args.close else ('connections.clear',{}) if args.all else ('connections.list',{})
|
|
52
|
+
if command=='rules':
|
|
53
|
+
if args.add_rule is not None or args.remove_rule is not None: return 'rules.'+('add' if args.add_rule is not None else 'remove'),{'rule':args.add_rule if args.add_rule is not None else args.remove_rule}
|
|
54
|
+
return 'rules.list',{key:getattr(args,key) for key in ['match','limit','custom'] if getattr(args,key,None) is not None}
|
|
55
|
+
if command=='providers':
|
|
56
|
+
return 'providers.'+('update' if args.update else 'list'),dict(kind=args.kind,**({'name':args.update} if args.update else {}))
|
|
57
|
+
if command=='test':
|
|
58
|
+
if not any(getattr(args,key,None) for key in ['name','config','node','group']):
|
|
59
|
+
return 'delay.summary',{key:getattr(args,key) for key in ['url','timeout']}
|
|
60
|
+
return 'delay.test',{key:getattr(args,key) for key in ['name','config','node','group','url','timeout'] if getattr(args,key,None) is not None}
|
|
61
|
+
if command=='traffic':
|
|
62
|
+
if args.watch or getattr(args,'full',False):
|
|
63
|
+
raise DomainError('机器请求仅支持单次流量采样,不支持 --watch 或 --full。',code='INVALID_ARGUMENT',exit_code=2)
|
|
64
|
+
return 'traffic.sample',{'interval':args.interval}
|
|
65
|
+
raise DomainError('该操作尚未接入机器协议。',code='UNSUPPORTED_OPERATION',exit_code=3)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def decode_response(stdout, token):
|
|
69
|
+
marker='DOMINO_RPC_'+token
|
|
70
|
+
lines=stdout.splitlines()
|
|
71
|
+
matches=[index for index,line in enumerate(lines) if line==marker]
|
|
72
|
+
if len(matches)!=2 or matches[1]!=matches[0]+2:
|
|
73
|
+
raise DomainError('目标没有返回有效的机器协议结果。',code='INVALID_REMOTE_RESPONSE',exit_code=5)
|
|
74
|
+
try: result=json.loads(lines[matches[0]+1])
|
|
75
|
+
except ValueError: raise DomainError('目标结果无法解析。',code='INVALID_REMOTE_RESPONSE',exit_code=5) from None
|
|
76
|
+
valid=isinstance(result,dict) and result.get('schema_version')==1 and type(result.get('ok')) is bool
|
|
77
|
+
valid=valid and all(key in result for key in ['operation','target','operation_id','revision','changed','effect','replayed','data','error'])
|
|
78
|
+
valid=valid and isinstance(result.get('operation_id'),str) and bool(re.fullmatch('[a-f0-9]{32}',result['operation_id']))
|
|
79
|
+
valid=valid and result.get('effect') in ['none','applied','rolled_back','unknown'] and type(result.get('replayed')) is bool
|
|
80
|
+
valid=valid and (result.get('changed') is None or type(result.get('changed')) is bool)
|
|
81
|
+
error=result.get('error') if isinstance(result,dict) else None
|
|
82
|
+
valid=valid and ((result['ok'] and error is None) or (not result['ok'] and isinstance(error,dict) and
|
|
83
|
+
isinstance(error.get('code'),str) and isinstance(error.get('message'),str) and type(error.get('retryable')) is bool))
|
|
84
|
+
if not valid:
|
|
85
|
+
raise DomainError('目标结果版本或结构无效。',code='INVALID_REMOTE_RESPONSE',exit_code=5)
|
|
86
|
+
return result
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@contextmanager
|
|
90
|
+
def uploaded_bundle(ssh,parameters):
|
|
91
|
+
path=Path(parameters['bundle']).expanduser()
|
|
92
|
+
if path.is_symlink() or not path.is_file() or path.stat().st_mode & 0o077:
|
|
93
|
+
raise DomainError('安装包需为权限 600 的普通文件。',code='INVALID_BUNDLE',exit_code=2)
|
|
94
|
+
if hashlib.sha256(path.read_bytes()).hexdigest()!=parameters['bundle_sha256']:
|
|
95
|
+
raise DomainError('安装包摘要不一致。',code='BUNDLE_DIGEST_MISMATCH',exit_code=2)
|
|
96
|
+
marker=operation_id()
|
|
97
|
+
code='import pathlib,tempfile,json;print('+repr(marker)+'+json.dumps(tempfile.mkdtemp(prefix=".domino-deploy.",dir=pathlib.Path.home())))'
|
|
98
|
+
response=ssh.call('python3 -c '+shlex.quote(code),capture_output=True,text=True,timeout=30)
|
|
99
|
+
lines=[line[len(marker):] for line in response.stdout.splitlines() if line.startswith(marker)]
|
|
100
|
+
if len(lines)!=1: raise DomainError('目标暂存响应无效。',code='INVALID_REMOTE_RESPONSE',exit_code=5)
|
|
101
|
+
stage=Path(json.loads(lines[0]))
|
|
102
|
+
if not stage.is_absolute() or not re.fullmatch(r'\.domino-deploy\.[A-Za-z0-9_-]+',stage.name):
|
|
103
|
+
raise DomainError('目标暂存路径无效。',code='INVALID_REMOTE_RESPONSE',exit_code=5)
|
|
104
|
+
try:
|
|
105
|
+
destination=str(stage/'bundle.tar.gz')
|
|
106
|
+
with path.open('rb') as source:
|
|
107
|
+
ssh.call('umask 077; cat > '+shlex.quote(destination),stdin=source,capture_output=True,timeout=900)
|
|
108
|
+
yield destination
|
|
109
|
+
finally:
|
|
110
|
+
try: ssh.call('rm -rf -- '+shlex.quote(str(stage)),capture_output=True,timeout=20)
|
|
111
|
+
except Exception: pass
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def main(arguments, cli):
|
|
115
|
+
identifier=operation_id()
|
|
116
|
+
result=Result(None,operation_id=identifier)
|
|
117
|
+
exit_code=1
|
|
118
|
+
dispatched=False
|
|
119
|
+
writing=False
|
|
120
|
+
try:
|
|
121
|
+
parser=Parser(add_help=False,allow_abbrev=False)
|
|
122
|
+
parser.add_argument('--output',choices=['json'],default='json')
|
|
123
|
+
parser.add_argument('--protocol-version',type=int,default=1)
|
|
124
|
+
parser.add_argument('--non-interactive',action='store_true')
|
|
125
|
+
parser.add_argument('--input')
|
|
126
|
+
parser.add_argument('--if-revision')
|
|
127
|
+
parser.add_argument('--request-id')
|
|
128
|
+
parser.add_argument('--dry-run',action='store_true')
|
|
129
|
+
options,remaining=parser.parse_known_args(arguments)
|
|
130
|
+
if any(value.split('=',1)[0]=='--client' for value in remaining):
|
|
131
|
+
raise DomainError('机器接口参数无效。',code='INVALID_ARGUMENT',exit_code=2)
|
|
132
|
+
if options.protocol_version!=1:
|
|
133
|
+
raise DomainError('不支持的协议版本。',code='UNSUPPORTED_PROTOCOL',exit_code=2)
|
|
134
|
+
if any(value in remaining for value in ['-h','--help','--version']): remaining=['capabilities']
|
|
135
|
+
args=cli.normalize_command(cli.build_parser(machine_mode=True).parse_args(remaining))
|
|
136
|
+
args.batch=True
|
|
137
|
+
args.machine_mode=True
|
|
138
|
+
operation,parameters=command_request(args)
|
|
139
|
+
from domino_service import OPERATIONS
|
|
140
|
+
writing=OPERATIONS.get(operation,{}).get('write',False)
|
|
141
|
+
result.operation=operation
|
|
142
|
+
if options.input:
|
|
143
|
+
if options.input=='-': raw=sys.stdin.read(1048577)
|
|
144
|
+
else:
|
|
145
|
+
path=Path(options.input).expanduser()
|
|
146
|
+
if path.stat().st_mode & 0o077: raise DomainError('输入文件权限应为 600 或更严格。',code='INVALID_INPUT_FILE',exit_code=2)
|
|
147
|
+
raw=path.read_text()
|
|
148
|
+
if len(raw.encode())>1048576: raise DomainError('输入内容过大。',code='INVALID_INPUT',exit_code=2)
|
|
149
|
+
try: extra=json.loads(raw)
|
|
150
|
+
except ValueError: raise DomainError('输入必须是 JSON 对象。',code='INVALID_INPUT',exit_code=2) from None
|
|
151
|
+
if not isinstance(extra,dict): raise DomainError('输入必须是 JSON 对象。',code='INVALID_INPUT',exit_code=2)
|
|
152
|
+
parameters.update(extra)
|
|
153
|
+
if options.if_revision is not None and not re.fullmatch('[a-f0-9]{64}',options.if_revision):
|
|
154
|
+
raise DomainError('修订标识格式无效。',code='INVALID_ARGUMENT',exit_code=2)
|
|
155
|
+
if options.request_id is not None and not 1<=len(options.request_id)<=200:
|
|
156
|
+
raise DomainError('请求去重键长度需为 1–200 个字符。',code='INVALID_ARGUMENT',exit_code=2)
|
|
157
|
+
target=getattr(args,'target',None)
|
|
158
|
+
local=cli.is_local_target(target)
|
|
159
|
+
try: result.target='localhost' if local else cli.destination(target,getattr(args,'user',None))
|
|
160
|
+
except cli.ToolError:
|
|
161
|
+
raise DomainError('目标地址或用户格式无效。',code='INVALID_ARGUMENT',exit_code=2) from None
|
|
162
|
+
if local and any(getattr(args,name,None) for name in ['user','ssh_port','identity']):
|
|
163
|
+
raise DomainError('本机请求不能附加 SSH 认证选项。',code='INVALID_ARGUMENT',exit_code=2)
|
|
164
|
+
from domino_service import validate
|
|
165
|
+
if operation not in OPERATIONS: raise DomainError('未支持的操作。',code='UNSUPPORTED_OPERATION',exit_code=3)
|
|
166
|
+
validate(parameters,OPERATIONS[operation]['parameters'])
|
|
167
|
+
token=operation_id()
|
|
168
|
+
request={'schema_version':1,'operation':operation,'arguments':parameters,'operation_id':identifier,
|
|
169
|
+
'target':result.target,'transport_token':token,'non_interactive':True}
|
|
170
|
+
request['client']='domino'
|
|
171
|
+
request.update({key:getattr(options,key) for key in ['if_revision','request_id','dry_run'] if getattr(options,key) is not None})
|
|
172
|
+
payload=json.dumps(request,ensure_ascii=False,allow_nan=False)
|
|
173
|
+
deadline=900 if writing or operation in ['delay.test','delay.summary'] else 90
|
|
174
|
+
if local:
|
|
175
|
+
dispatched=True
|
|
176
|
+
process=subprocess.run([sys.executable,str(cli.REMOTE_SCRIPT),'agent'],input=payload,capture_output=True,text=True,timeout=deadline)
|
|
177
|
+
else:
|
|
178
|
+
try:
|
|
179
|
+
with cli.SSH(args) as ssh:
|
|
180
|
+
if operation=='deployment.apply':
|
|
181
|
+
with uploaded_bundle(ssh,parameters) as destination:
|
|
182
|
+
request['arguments']=dict(parameters,bundle=destination)
|
|
183
|
+
payload=json.dumps(request,ensure_ascii=False,allow_nan=False)
|
|
184
|
+
dispatched=True
|
|
185
|
+
process=subprocess.run(ssh.action_argv('agent'),input=payload,capture_output=True,text=True,timeout=deadline)
|
|
186
|
+
else:
|
|
187
|
+
dispatched=True
|
|
188
|
+
process=subprocess.run(ssh.action_argv('agent'),input=payload,capture_output=True,text=True,timeout=deadline)
|
|
189
|
+
except cli.ToolError:
|
|
190
|
+
raise DomainError('SSH 连接未建立,请检查网络和认证配置。',code='SSH_UNAVAILABLE',exit_code=5) from None
|
|
191
|
+
document=decode_response(process.stdout,token)
|
|
192
|
+
valid_id=document.get('operation_id')==identifier or (options.request_id is not None and (document.get('replayed') or document.get('effect')=='unknown'))
|
|
193
|
+
if not valid_id or document.get('operation')!=operation or document.get('target')!=result.target or document.get('client')!='domino':
|
|
194
|
+
raise DomainError('目标结果与请求不一致。',code='INVALID_REMOTE_RESPONSE',exit_code=5)
|
|
195
|
+
exit_code=process.returncode
|
|
196
|
+
if (document['ok'] and exit_code!=0) or (not document['ok'] and exit_code==0):
|
|
197
|
+
raise DomainError('目标退出码与结果不一致。',code='INVALID_REMOTE_RESPONSE',exit_code=5)
|
|
198
|
+
print(json.dumps(document,ensure_ascii=False,indent=2))
|
|
199
|
+
return exit_code
|
|
200
|
+
except DomainError as error: result.error=error
|
|
201
|
+
except subprocess.TimeoutExpired: result.error=DomainError('请求超时。',code='TIMEOUT',exit_code=7,retryable=True)
|
|
202
|
+
except (OSError,ValueError): result.error=DomainError('无法读取输入或执行目标请求。',code='INVALID_INPUT',exit_code=2)
|
|
203
|
+
except KeyboardInterrupt: result.error=DomainError('请求已中断。',code='CANCELLED',exit_code=7)
|
|
204
|
+
except Exception: result.error=DomainError('机器接口发生内部错误。',code='INTERNAL_ERROR',exit_code=1)
|
|
205
|
+
if dispatched and writing and not options.dry_run:
|
|
206
|
+
result.error.effect='unknown'
|
|
207
|
+
result.effect,result.changed='unknown',None
|
|
208
|
+
print(json.dumps(result.document(),ensure_ascii=False,indent=2))
|
|
209
|
+
return result.exit_code
|
domino_agent_backend.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
# Copyright (C) 2026 KJaebye
|
|
3
|
+
"""Private process transport; protocol data never shares stdout with diagnostics."""
|
|
4
|
+
from contextlib import redirect_stdout
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
import sys
|
|
8
|
+
from domino_model import DomainError, Result
|
|
9
|
+
from domino_service import Application
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def run(context):
|
|
13
|
+
token='ERROR'
|
|
14
|
+
result=Result(None)
|
|
15
|
+
try:
|
|
16
|
+
raw=sys.stdin.read(1048577)
|
|
17
|
+
if len(raw.encode())>1048576: raise ValueError()
|
|
18
|
+
request=json.loads(raw,parse_constant=lambda value:(_ for _ in ()).throw(ValueError()))
|
|
19
|
+
if not isinstance(request,dict): raise ValueError()
|
|
20
|
+
token=request.get('transport_token','')
|
|
21
|
+
if not isinstance(token,str) or not re.fullmatch('[a-f0-9]{32}',token): raise ValueError()
|
|
22
|
+
if not isinstance(request.get('operation'),str) or not isinstance(request.get('arguments',{}),dict): raise ValueError()
|
|
23
|
+
if not isinstance(request.get('operation_id'),str) or not re.fullmatch('[a-f0-9]{32}',request['operation_id']): raise ValueError()
|
|
24
|
+
result=Result(request['operation'],request.get('target','localhost'),operation_id=request['operation_id'])
|
|
25
|
+
with redirect_stdout(sys.stderr):
|
|
26
|
+
result=Application(context).execute(request)
|
|
27
|
+
except (ValueError,TypeError):
|
|
28
|
+
result.error=DomainError('机器请求格式无效。',code='INVALID_REQUEST',exit_code=2)
|
|
29
|
+
except DomainError as error:
|
|
30
|
+
result.error=error
|
|
31
|
+
result.effect=error.effect
|
|
32
|
+
except KeyboardInterrupt:
|
|
33
|
+
result.error=DomainError('请求已中断。',code='CANCELLED',exit_code=7)
|
|
34
|
+
except Exception:
|
|
35
|
+
result.error=DomainError('目标执行出现内部错误。',code='INTERNAL_ERROR',exit_code=1)
|
|
36
|
+
marker='DOMINO_RPC_'+token
|
|
37
|
+
print(marker)
|
|
38
|
+
print(json.dumps(result.document(),ensure_ascii=False,allow_nan=False))
|
|
39
|
+
print(marker)
|
|
40
|
+
return result.exit_code
|