-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server-portal): SEINT-409 create allowlist mechanism (#328)
**Main logic**: When a site is premium, it uses a `premiumRPCSelector`. If it's not, it uses public full nodes via the `stanadrdRPCSelector`. - The allowlist is an Edge Config store on vercel. It's implemented in a way that even if it's not defined, the portal can still run locally for independent developers. - Created `allowlist_checker.ts` - Update `configuration-loader` to include `ENABLE_ALLOWLIST` and `EDGE_CONFIG_ALLOWLIST` env variables. --------- Co-authored-by: giac-mysten <[email protected]> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
- Loading branch information
1 parent
15497a3
commit 090ac9a
Showing
4 changed files
with
93 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { createClient, EdgeConfigClient } from '@vercel/edge-config'; | ||
import { config } from 'configuration_loader'; | ||
|
||
let edgeConfigAllowlistClient: EdgeConfigClient | undefined; | ||
if (config.enableAllowlist){ | ||
edgeConfigAllowlistClient = createClient(config.edgeConfigAllowlist); | ||
} | ||
/** | ||
* Check if a given subdomain is allowed to be served by the walrus site. | ||
* @param subdomain The walrus site subdomain to inspect | ||
* @returns true if the subdomain is allowed (has premium), false otherwise | ||
*/ | ||
export async function isAllowed(subdomain: string): Promise<boolean> { | ||
if (!config.enableAllowlist){ | ||
return false | ||
} | ||
|
||
if (!edgeConfigAllowlistClient){ | ||
throw new Error('Edge config allowlist client not initialized!') | ||
} | ||
|
||
const allowed: boolean = await edgeConfigAllowlistClient.has( | ||
subdomain, | ||
); | ||
|
||
return allowed | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { UrlFetcher } from "@lib/url_fetcher"; | ||
import { ResourceFetcher } from "@lib/resource"; | ||
import { RPCSelector } from "@lib/rpc_selector"; | ||
import { SuiNSResolver } from "@lib/suins"; | ||
import { WalrusSitesRouter } from "@lib/routing"; | ||
import { config } from "configuration_loader"; | ||
|
||
/** | ||
* A factory class for creating page fetchers. | ||
* Page fetchers can be either premium or standard. | ||
* Premium fetchers use premium RPC nodes that can serve content faster and more reliably, | ||
* while standard fetchers use standard RPC nodes. | ||
*/ | ||
class UrlFetcherFactory { | ||
private static readonly premiumRpcSelector = new RPCSelector(config.premiumRpcUrlList); | ||
private static readonly standardRpcSelector = new RPCSelector(config.rpcUrlList); | ||
|
||
public static premiumUrlFetcher(): UrlFetcher { | ||
return new UrlFetcher( | ||
new ResourceFetcher(this.standardRpcSelector), | ||
new SuiNSResolver(this.standardRpcSelector), | ||
new WalrusSitesRouter(this.standardRpcSelector) | ||
); | ||
} | ||
|
||
public static standardUrlFetcher(): UrlFetcher { | ||
return new UrlFetcher( | ||
new ResourceFetcher(this.premiumRpcSelector), | ||
new SuiNSResolver(this.premiumRpcSelector), | ||
new WalrusSitesRouter(this.premiumRpcSelector) | ||
); | ||
} | ||
} | ||
|
||
export const standardUrlFetcher = UrlFetcherFactory.standardUrlFetcher(); | ||
export const premiumUrlFetcher = UrlFetcherFactory.premiumUrlFetcher(); |