mirror of
https://github.com/tale/headplane.git
synced 2026-07-26 07:48:14 +00:00
feat: create type-safe API object for Headscale
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { defineApiEndpoints } from '../factory';
|
||||
|
||||
export interface PolicyEndpoints {
|
||||
/**
|
||||
* Retrieves the current ACL policy from the Headscale instance.
|
||||
*
|
||||
* @returns The ACL policy as a string.
|
||||
*/
|
||||
getPolicy(): Promise<string>;
|
||||
|
||||
/**
|
||||
* Sets the ACL policy for the Headscale instance.
|
||||
*
|
||||
* @param policy The ACL policy as a string.
|
||||
* @returns The expiration date of the new policy.
|
||||
*/
|
||||
setPolicy(policy: string): Promise<Date>;
|
||||
}
|
||||
|
||||
export default defineApiEndpoints<PolicyEndpoints>((client, apiKey) => ({
|
||||
getPolicy: async () => {
|
||||
const { policy } = await client.apiFetch<{ policy: string }>(
|
||||
'GET',
|
||||
'v1/policy',
|
||||
apiKey,
|
||||
);
|
||||
|
||||
return policy;
|
||||
},
|
||||
|
||||
setPolicy: async (policy) => {
|
||||
const { updatedAt } = await client.apiFetch<{ updatedAt: string }>(
|
||||
'PUT',
|
||||
'v1/policy',
|
||||
apiKey,
|
||||
{ policy },
|
||||
);
|
||||
|
||||
return new Date(updatedAt);
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user