From c729bc642f0e0c13a330e70ef7e816e39c19e0ec Mon Sep 17 00:00:00 2001 From: pablomendezroyo Date: Thu, 22 Feb 2024 10:38:00 +0100 Subject: [PATCH] Add internal mappings --- .../components/Network/HttpsMappings.tsx | 4 +++- packages/httpsPortal/src/apiClient.ts | 23 +++++++++++++++---- packages/httpsPortal/src/httpsPortal.ts | 1 + packages/types/src/calls.ts | 1 + 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/admin-ui/src/pages/system/components/Network/HttpsMappings.tsx b/packages/admin-ui/src/pages/system/components/Network/HttpsMappings.tsx index a1a80ce11..97e5a9701 100644 --- a/packages/admin-ui/src/pages/system/components/Network/HttpsMappings.tsx +++ b/packages/admin-ui/src/pages/system/components/Network/HttpsMappings.tsx @@ -175,7 +175,9 @@ export function HttpsMappings() { - mapping.exposed ? removeMapping(mapping) : addMapping(mapping) + mapping.exposed + ? removeMapping(mapping) + : addMapping({ ...mapping, external: false }) } /> diff --git a/packages/httpsPortal/src/apiClient.ts b/packages/httpsPortal/src/apiClient.ts index 34f8c08fb..7b0520470 100644 --- a/packages/httpsPortal/src/apiClient.ts +++ b/packages/httpsPortal/src/apiClient.ts @@ -17,6 +17,12 @@ export interface HttpPortalEntry { * `"validator-prysm"`, `"internal-docker-dns-based-host"` */ toHost: string; + /** + * Whether the mapping is external or not + * external=true makes the mapping accessible from everywhere + * external=false makes the mapping accessible only from the local network + */ + external?: boolean; } export const httpsPortalResponseSchema = { @@ -54,12 +60,18 @@ export class HttpsPortalApiClient { * GET /add?from=&to= * Empty reply */ - async add({ fromSubdomain, toHost }: HttpPortalEntry): Promise { + async add({ + fromSubdomain, + toHost, + external = true, + }: HttpPortalEntry): Promise { const search = querystring.encode({ from: fromSubdomain, to: toHost, }); - await this.get(urlJoin(this.baseUrl, `/add?${search}`)); + await this.get( + urlJoin(this.baseUrl, `/add?${search}&external=${external}`) + ); } /** @@ -84,9 +96,9 @@ export class HttpsPortalApiClient { * [{"from":"validator-prysm-pyrmont.1ba499fcc3aff025.dyndns.dappnode.io","to":"validator-prysm-pyrmont"}] */ async list(): Promise { - const entries = await this.get<{ from: string; to: string }[]>( - urlJoin(this.baseUrl, `/?format=json`) - ); + const entries = await this.get< + { from: string; to: string; external: boolean }[] + >(urlJoin(this.baseUrl, `/?format=json`)); if (!ajv.validate(httpsPortalResponseSchema, entries)) { throw Error(`Invalid response: ${JSON.stringify(ajv.errors, null, 2)}`); @@ -95,6 +107,7 @@ export class HttpsPortalApiClient { return entries.map((entry) => ({ fromSubdomain: entry.from, toHost: entry.to, + external: entry.external, })); } diff --git a/packages/httpsPortal/src/httpsPortal.ts b/packages/httpsPortal/src/httpsPortal.ts index 63c10c0fb..d17fb75fe 100644 --- a/packages/httpsPortal/src/httpsPortal.ts +++ b/packages/httpsPortal/src/httpsPortal.ts @@ -64,6 +64,7 @@ export class HttpsPortal { await this.httpsPortalApiClient.add({ fromSubdomain: mapping.fromSubdomain, toHost: `${externalNetworkAlias}:${mapping.port}`, + external: mapping.external, }); // Edit compose to persist the setting diff --git a/packages/types/src/calls.ts b/packages/types/src/calls.ts index 16956edbf..99f093f1a 100644 --- a/packages/types/src/calls.ts +++ b/packages/types/src/calls.ts @@ -26,6 +26,7 @@ export interface HttpsPortalMapping { dnpName: string; serviceName: string; port: number; + external?: boolean; } export interface ExposableServiceInfo extends HttpsPortalMapping {