-
Notifications
You must be signed in to change notification settings - Fork 452
Improve connection tests #3853
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
Improve connection tests #3853
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
|---|---|---|
|
|
@@ -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 { | ||
|
mbg marked this conversation as resolved.
|
||
| /** 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" }, | ||
|
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. I presume v3 is old enough that we can rely on this existing / the proxy only supports v3 anyway?
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. AFAIK nothing else exists. I.e. I am not aware that |
||
| }; | ||
|
|
||
| /** | ||
| * 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(); | ||
|
|
@@ -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 | ||
| }, | ||
|
|
@@ -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); | ||
|
|
||
|
|
@@ -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); | ||
|
|
@@ -126,5 +166,6 @@ export async function checkConnections( | |
| ); | ||
| } | ||
|
|
||
| logger.endGroup(); | ||
| return result; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.