feat: add headless agent management to CLI and both desktop clients
This commit is contained in:
1 parent
e91fa0235c
commit
6916dd54fb
50 files changed
+4837
-148
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'agent_models.dart';
|
||||
import 'agent_service.dart';
|
||||
|
||||
class AgentRepository {
|
||||
const AgentRepository(this.api);
|
||||
final AgentApi api;
|
||||
String get connectionKey => api.connectionKey;
|
||||
String redact(String text) => api.redact(text);
|
||||
Future<List<ManagedAgent>> list({
|
||||
required bool local,
|
||||
required String config,
|
||||
}) async {
|
||||
final values = local
|
||||
? [
|
||||
<String, Object?>{
|
||||
'id': '',
|
||||
'online': true,
|
||||
'status': await api.local(config, {'op': 'status'}),
|
||||
},
|
||||
]
|
||||
: await api.list();
|
||||
if (local) {
|
||||
final status = Map<String, Object?>.from(
|
||||
values[0]['status']! as Map<String, Object?>,
|
||||
);
|
||||
values[0]['id'] = status['id'];
|
||||
}
|
||||
return values.map(ManagedAgent.fromMap).toList(growable: false);
|
||||
}
|
||||
|
||||
Future<Object?> call(
|
||||
bool local,
|
||||
String config,
|
||||
String agent,
|
||||
JsonMap operation,
|
||||
) => local ? api.local(config, operation) : api.request(agent, operation);
|
||||
Future<void> importAdmin(String path) => api.importAdmin(path);
|
||||
Future<String> enrollment(String path) async {
|
||||
final file = File(path);
|
||||
if (await file.length() > 65536) {
|
||||
throw const FormatException('凭据文件过大');
|
||||
}
|
||||
final line = (await file.readAsLines())
|
||||
.where((v) => v.startsWith('ADS_AGENT_TOKEN='))
|
||||
.firstOrNull;
|
||||
final value = line?.substring(16).trim() ?? '';
|
||||
if (value.length < 32) {
|
||||
throw const FormatException('请选择包含 ADS_AGENT_TOKEN 的 agent.env');
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user