| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -2,11 +2,41 @@ import * as https from "https"; | |
|
|
||
| import { HttpsProxyAgent } from "https-proxy-agent"; | ||
|
|
||
| import { DocUrl } from "../doc-url"; | ||
| import { Logger } from "../logging"; | ||
| import { getErrorMessage } from "../util"; | ||
|
|
||
| import { getAddressString, ProxyInfo, Registry } from "./types"; | ||
|
|
||
| /** Represents registry-specific connection test configurations. */ | ||
| export interface ConnectionTestConfig { | ||
| /** An optional path to append to the end of the base url. */ | ||
| path?: string; | ||
| } | ||
|
|
||
| /** A partial mapping of registry types to extra connection test configurations. */ | ||
| export const connectionTestConfig: Partial< | ||
| Record<string, ConnectionTestConfig> | ||
| > = { | ||
| nuget_feed: { path: "v3/index.json" }, | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI presume v3 is old enough that we can rely on this existing / the proxy only supports v3 anyway?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityAFAIK nothing else exists. I.e. I am not aware that v2/index.json was ever a thing. See also https://learn.microsoft.com/en-us/nuget/api/service-index#versioning
Sorry, something went wrong.
All reactions
|
||
| }; | ||
|
|
||
| /** | ||
| * Applies the registry-specific check configuration to the base URL, if any and applicable. | ||
| */ | ||
| export function makeTestUrl( | ||
| config: ConnectionTestConfig | undefined, | ||
| base: URL, | ||
| ): URL { | ||
| if (config?.path === undefined) { | ||
| return base; | ||
| } | ||
| if (base.pathname.endsWith(config.path)) { | ||
| return base; | ||
| } | ||
| return new URL(config.path, base); | ||
| } | ||
|
|
||
| export class ReachabilityError extends Error { | ||
| constructor(public readonly statusCode?: number | undefined) { | ||
| super(); | ||
| Expand Down Expand Up | @@ -41,7 +71,7 @@ class NetworkReachabilityBackend implements ReachabilityBackend { | |
| url, | ||
| { | ||
| agent: this.agent, | ||
| method: "HEAD", | ||
| method: "GET", | ||
| ca: this.proxy.cert, | ||
| timeout: 5 * 1000, // 5 seconds | ||
| }, | ||
| Expand Down Expand Up | @@ -85,13 +115,21 @@ export async function checkConnections( | |
| // Don't do anything if there are no registries. | ||
| if (proxy.registries.length === 0) return result; | ||
|
|
||
| // Start a log group and print a message with a disclaimer with a link to the | ||
| // relevant documentation that these checks are a best-effort process. | ||
| logger.startGroup("Testing connections via the proxy"); | ||
| logger.info( | ||
| `The connection tests performed here are best-effort only and failures here may not affect the subsequent analysis. See ${DocUrl.PRIVATE_REGISTRY_LOGS} for more information.`, | ||
| ); | ||
|
|
||
| try { | ||
| // Initialise a networking backend if no backend was provided. | ||
| if (backend === undefined) { | ||
| backend = new NetworkReachabilityBackend(proxy); | ||
| } | ||
|
|
||
| for (const registry of proxy.registries) { | ||
| const config = connectionTestConfig[registry.type]; | ||
| const address = getAddressString(registry); | ||
| const url = URL.parse(address); | ||
|
|
||
| Expand All | @@ -102,9 +140,11 @@ export async function checkConnections( | |
| continue; | ||
| } | ||
|
|
||
| const testUrl = makeTestUrl(config, url); | ||
|
|
||
| try { | ||
| logger.debug(`Testing connection to ${url}...`); | ||
| const statusCode = await backend.checkConnection(url); | ||
| const statusCode = await backend.checkConnection(testUrl); | ||
|
|
||
| logger.info(`Successfully tested connection to ${url} (${statusCode})`); | ||
| result.add(registry); | ||
| Expand All | @@ -126,5 +166,6 @@ export async function checkConnections( | |
| ); | ||
| } | ||
|
|
||
| logger.endGroup(); | ||
| return result; | ||
| } | ||
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.