mirror of
https://github.com/tale/headplane.git
synced 2026-07-26 07:48:14 +00:00
0512565f8e
Apparently I didn't use my brain cells and rely on the /version endpoint that Headscale has exposed since 0.26 (our lowest supported version). Switching to that significantly simplifies the API surface.
34 lines
1010 B
TypeScript
34 lines
1010 B
TypeScript
import type { Capabilities } from "../capabilities";
|
|
import type { Transport } from "../transport";
|
|
|
|
export interface PolicyApi {
|
|
get(): Promise<{ policy: string; updatedAt: Date | null }>;
|
|
set(policy: string): Promise<{ policy: string; updatedAt: Date }>;
|
|
}
|
|
|
|
export function makePolicyApi(
|
|
transport: Transport,
|
|
_capabilities: Capabilities,
|
|
apiKey: string,
|
|
): PolicyApi {
|
|
return {
|
|
get: async () => {
|
|
const { policy, updatedAt } = await transport.request<{
|
|
policy: string;
|
|
updatedAt: string;
|
|
}>({ method: "GET", path: "v1/policy", apiKey });
|
|
return {
|
|
policy,
|
|
updatedAt: updatedAt !== null ? new Date(updatedAt) : null,
|
|
};
|
|
},
|
|
set: async (policy) => {
|
|
const { policy: newPolicy, updatedAt } = await transport.request<{
|
|
policy: string;
|
|
updatedAt: string;
|
|
}>({ method: "PUT", path: "v1/policy", apiKey, body: { policy } });
|
|
return { policy: newPolicy, updatedAt: new Date(updatedAt) };
|
|
},
|
|
};
|
|
}
|