From 9801ef453de24b66b436ba30157b88846cd7744e Mon Sep 17 00:00:00 2001 From: Aarnav Tale Date: Fri, 23 Aug 2024 16:12:46 -0400 Subject: [PATCH] fix(TALE-29): remove all old ACL_FILE handling No longer required if the minimum is beta2 --- app/routes/_data.acls._index/route.tsx | 80 ++++++-------------------- app/utils/config/headscale.ts | 1 - 2 files changed, 17 insertions(+), 64 deletions(-) diff --git a/app/routes/_data.acls._index/route.tsx b/app/routes/_data.acls._index/route.tsx index 2311b75..d6d7467 100644 --- a/app/routes/_data.acls._index/route.tsx +++ b/app/routes/_data.acls._index/route.tsx @@ -12,7 +12,7 @@ import Notice from '~/components/Notice' import Spinner from '~/components/Spinner' import { toast } from '~/components/Toaster' import { cn } from '~/utils/cn' -import { loadAcl, loadContext, patchAcl } from '~/utils/config/headplane' +import { loadContext } from '~/utils/config/headplane' import { HeadscaleError, pull, put } from '~/utils/headscale' import { getSession } from '~/utils/sessions' @@ -27,7 +27,6 @@ export async function loader({ request }: LoaderFunctionArgs) { session.get('hsApiKey')!, ) - console.log(policy) try { // We have read access, now do we have write access? // Attempt to set the policy to what we just got @@ -37,7 +36,6 @@ export async function loader({ request }: LoaderFunctionArgs) { return { hasAclWrite: true, - isPolicyApi: true, currentAcl: policy, aclType: 'json', } as const @@ -49,35 +47,15 @@ export async function loader({ request }: LoaderFunctionArgs) { if (error.status === 500) { return { hasAclWrite: false, - isPolicyApi: true, currentAcl: policy, aclType: 'json', } as const } } - } catch (error) { - // Propagate our errors through normal error handling - if (!(error instanceof HeadscaleError)) { - throw error - } - - // Not on 0.23-beta1 or later - if (error.status === 404) { - const { data, type, read, write } = await loadAcl() - return { - hasAclWrite: write, - isPolicyApi: false, - currentAcl: read ? data : '', - aclType: type, - } - } - - throw error - } + } catch {} return { hasAclWrite: true, - isPolicyApi: true, currentAcl: '', aclType: 'json', } as const @@ -91,30 +69,19 @@ export async function action({ request }: ActionFunctionArgs) { }) } - const data = await request.json() as { acl: string, api: boolean } - if (data.api) { - try { - await put('v1/policy', session.get('hsApiKey')!, { - policy: data.acl, - }) + const { acl } = await request.json() as { acl: string, api: boolean } + try { + await put('v1/policy', session.get('hsApiKey')!, { + policy: acl, + }) - return json({ success: true }) - } catch (error) { - return json({ success: false }, { - status: error instanceof HeadscaleError ? error.status : 500, - }) - } - } - - const context = await loadContext() - if (!context.acl.write) { + return json({ success: true }) + } catch (error) { return json({ success: false }, { - status: 403, + status: error instanceof HeadscaleError ? error.status : 500, }) } - await patchAcl(data.acl) - if (context.integration?.onAclChange) { await context.integration.onAclChange(context.integration.context) } @@ -225,25 +192,13 @@ export default function Page() { ? undefined : (
- {data.isPolicyApi - ? ( - - The ACL policy is read-only. You can view the current policy - but you cannot make changes to it. -
- To resolve this, you need to set the ACL policy mode to - database in your Headscale configuration. -
- ) - : ( - - The ACL policy is read-only. You can view the current policy - but you cannot make changes to it. -
- To resolve this, you need to configure a Headplane integration - or make the ACL_FILE environment variable available. -
- )} + + The ACL policy is read-only. You can view the current policy + but you cannot make changes to it. +
+ To resolve this, you need to set the ACL policy mode to + database in your Headscale configuration. +
)} @@ -357,7 +312,6 @@ export default function Page() { setToasted(false) fetcher.submit({ acl, - api: data.isPolicyApi, }, { method: 'PATCH', encType: 'application/json', diff --git a/app/utils/config/headscale.ts b/app/utils/config/headscale.ts index b50992d..20d8cbe 100644 --- a/app/utils/config/headscale.ts +++ b/app/utils/config/headscale.ts @@ -45,7 +45,6 @@ const HeadscaleConfig = z.object({ disable_check_updates: goBool.default(false), ephemeral_node_inactivity_timeout: goDuration.default('120s'), randomize_client_port: goBool.default(false), - acl_policy_path: z.string().optional(), acme_email: z.string().optional(), acme_url: z.string().optional(),