mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 14:15:24 +00:00
feat: finish the fleets plugin, add ctx.hosts and host-commands SDK (B4)
This commit is contained in:
1 parent
d2ff5fc78f
commit
3b2c849514
59 files changed
+31807
-2977
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import type { HostSelector } from "../../../../../src/types/automations.js";
|
||||
import { resolveHostById } from "../../../../../src/backend/hosts/host-resolver.js";
|
||||
import { createCurrentFleetRepository } from "../../../../../src/backend/database/repositories/factory.js";
|
||||
import { PermissionManager } from "../../../../../src/backend/utils/permission-manager.js";
|
||||
import { fleetMemberIds } from "../snippets.js";
|
||||
import type { StepExecutionContext } from "./types.js";
|
||||
|
||||
/** A host the caller is allowed to act on. `host` is always resolved. */
|
||||
@@ -63,13 +63,7 @@ async function fleetHostIds(
|
||||
fleetId: number,
|
||||
userId: string,
|
||||
): Promise<number[]> {
|
||||
try {
|
||||
const repository = createCurrentFleetRepository();
|
||||
const members = await repository.listEffectiveMembers(userId, fleetId);
|
||||
return members.map((member) => member.id);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
return fleetMemberIds(userId, fleetId);
|
||||
}
|
||||
|
||||
async function allAccessibleHostIds(userId: string): Promise<number[]> {
|
||||
|
||||
@@ -62,3 +62,30 @@ export async function getSnippet(
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Another plugin's fleets, as ctx.services.get("fleets.access") returns them. */
|
||||
interface FleetsAccess {
|
||||
members: (
|
||||
fleetId: number,
|
||||
) => Promise<Array<{ id: number; name: string | null; ip: string }>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* A fleet's effective member host ids, for a "fleet" target selector. Empty
|
||||
* when the fleets plugin is off, the user may not use it, or the fleet does
|
||||
* not exist - the step then runs against no hosts rather than failing.
|
||||
*/
|
||||
export async function fleetMemberIds(
|
||||
userId: string,
|
||||
fleetId: number,
|
||||
): Promise<number[]> {
|
||||
if (!current) return [];
|
||||
try {
|
||||
const members = await current
|
||||
.get<FleetsAccess>("fleets.access", { userId })
|
||||
.members(fleetId);
|
||||
return members.map((member) => member.id);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user