Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add internal mappings [BLOCKED] #1851

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ export function HttpsMappings() {
<Switch
checked={mapping.exposed}
onToggle={() =>
mapping.exposed ? removeMapping(mapping) : addMapping(mapping)
mapping.exposed
? removeMapping(mapping)
: addMapping({ ...mapping, external: false })
}
/>
</React.Fragment>
Expand Down
23 changes: 18 additions & 5 deletions packages/httpsPortal/src/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -54,12 +60,18 @@ export class HttpsPortalApiClient {
* GET /add?from=<chosen-subodomain>&to=<internal-resource>
* Empty reply
*/
async add({ fromSubdomain, toHost }: HttpPortalEntry): Promise<void> {
async add({
fromSubdomain,
toHost,
external = true,
}: HttpPortalEntry): Promise<void> {
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}`)
);
}

/**
Expand All @@ -84,9 +96,9 @@ export class HttpsPortalApiClient {
* [{"from":"validator-prysm-pyrmont.1ba499fcc3aff025.dyndns.dappnode.io","to":"validator-prysm-pyrmont"}]
*/
async list(): Promise<HttpPortalEntry[]> {
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)}`);
Expand All @@ -95,6 +107,7 @@ export class HttpsPortalApiClient {
return entries.map((entry) => ({
fromSubdomain: entry.from,
toHost: entry.to,
external: entry.external,
}));
}

Expand Down
1 change: 1 addition & 0 deletions packages/httpsPortal/src/httpsPortal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface HttpsPortalMapping {
dnpName: string;
serviceName: string;
port: number;
external?: boolean;
}

export interface ExposableServiceInfo extends HttpsPortalMapping {
Expand Down
Loading