1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Use configured registry by default

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-07-15 17:42:49 -04:00
parent 9d9f9c0072
commit 9b4ca7f0ce
7 changed files with 48 additions and 20 deletions

View File

@ -32,14 +32,16 @@ export * from "./base64";
export * from "./camelCase";
export * from "./cloneJson";
export * from "./cluster-id-url-parsing";
export * from "./convertCpu";
export * from "./convertMemory";
export * from "./debouncePromise";
export * from "./defineGlobal";
export * from "./delay";
export * from "./disposer";
export * from "./downloadFile";
export * from "./formatDuration";
export * from "./escapeRegExp";
export * from "./extended-map";
export * from "./formatDuration";
export * from "./getPath";
export * from "./getRandId";
export * from "./hash-set";
@ -47,6 +49,7 @@ export * from "./local-kubeconfig";
export * from "./n-fircate";
export * from "./openExternal";
export * from "./paths";
export * from "./promise-exec";
export * from "./reject-promise";
export * from "./singleton";
export * from "./sort-compare";
@ -56,8 +59,6 @@ export * from "./toggle-set";
export * from "./toJS";
export * from "./type-narrowing";
export * from "./types";
export * from "./convertMemory";
export * from "./convertCpu";
import * as iter from "./iter";

View File

@ -24,10 +24,9 @@ import v8 from "v8";
import * as yaml from "js-yaml";
import type { HelmRepo } from "./helm-repo-manager";
import logger from "../logger";
import { promiseExec } from "../promise-exec";
import { helmCli } from "./helm-cli";
import type { RepoHelmChartList } from "../../common/k8s-api/endpoints/helm-charts.api";
import { sortCharts } from "../../common/utils";
import { sortCharts, promiseExec } from "../../common/utils";
export class HelmChartManager {
static #cache = new Map<string, Buffer>();

View File

@ -22,10 +22,9 @@
import * as tempy from "tempy";
import fse from "fs-extra";
import * as yaml from "js-yaml";
import { promiseExec } from "../promise-exec";
import { promiseExec, toCamelCase } from "../../common/utils";
import { helmCli } from "./helm-cli";
import type { Cluster } from "../cluster";
import { toCamelCase } from "../../common/utils/camelCase";
export async function listReleases(pathToKubeconfig: string, namespace?: string) {
const helm = await helmCli.binaryPath();

View File

@ -21,9 +21,8 @@
import yaml from "js-yaml";
import { readFile } from "fs-extra";
import { promiseExec } from "../promise-exec";
import { helmCli } from "./helm-cli";
import { Singleton } from "../../common/utils/singleton";
import { Singleton, promiseExec } from "../../common/utils";
import { customRequestPromise } from "../../common/request";
import orderBy from "lodash/orderBy";
import logger from "../logger";

View File

@ -21,17 +21,15 @@
import path from "path";
import fs from "fs";
import { promiseExec } from "./promise-exec";
import logger from "./logger";
import { ensureDir, pathExists } from "fs-extra";
import * as lockFile from "proper-lockfile";
import { helmCli } from "./helm/helm-cli";
import { UserStore } from "../common/user-store";
import { customRequest } from "../common/request";
import { getBundledKubectlVersion } from "../common/utils/app-version";
import { isDevelopment, isWindows, isTestEnv } from "../common/vars";
import { SemVer } from "semver";
import { getPath } from "../common/utils/getPath";
import { getPath, promiseExec, getBundledKubectlVersion } from "../common/utils";
const bundledVersion = getBundledKubectlVersion();
const kubectlMap: Map<string, string> = new Map([

View File

@ -31,7 +31,7 @@ import path from "path";
import React from "react";
import { SemVer } from "semver";
import URLParse from "url-parse";
import { Disposer, disposer, downloadFile, downloadJson, ExtendableDisposer, extractTar, listTarEntries, noop, readFileFromTar, } from "../../../common/utils";
import { Disposer, disposer, downloadFile, downloadJson, ExtendableDisposer, extractTar, listTarEntries, noop, readFileFromTar, getPath, promiseExecFile } from "../../../common/utils";
import { ExtensionDiscovery, InstalledExtension, manifestFilename } from "../../../extensions/extension-discovery";
import { ExtensionLoader } from "../../../extensions/extension-loader";
import { extensionDisplayName, LensExtensionId, LensExtensionManifest, sanitizeExtensionName, } from "../../../extensions/lens-extension";
@ -47,7 +47,6 @@ import { Notice } from "./notice";
import { SettingLayout } from "../layout/setting-layout";
import { docsUrl } from "../../../common/vars";
import { dialog } from "../../remote-helpers";
import { getPath } from "../../../common/utils/getPath";
function getMessageFromError(error: any): string {
if (!error || typeof error !== "object") {
@ -300,16 +299,49 @@ async function unpackExtension(request: InstallRequestValidated, disposeDownload
}
}
const defaultBaseRegistryUrl = "https://registry.npmjs.com";
async function getBaseRegistryUrl(): Promise<string> {
try {
const filteredEnv = Object.fromEntries(
Object.entries(process.env)
.filter(([key]) => !key.startsWith("npm"))
);
const { stdout } = await promiseExecFile("npm", ["config", "get", "registry"], { env: filteredEnv });
return stdout.trim();
} catch (error) {
console.warn("[EXTENSIONS]: failed to get configured registry from .npmrc", error);
return defaultBaseRegistryUrl;
}
}
export async function attemptInstallByInfo({ name, version, requireConfirmation = false }: ExtensionInfo) {
const disposer = ExtensionInstallationStateStore.startPreInstall();
const registryUrl = new URLParse("https://registry.npmjs.com").set("pathname", name).toString();
const { promise } = downloadJson({ url: registryUrl });
const json = await promise.catch(console.error);
const baseRegistryUrl = await getBaseRegistryUrl();
const registryUrl = new URLParse(baseRegistryUrl).set("pathname", name).toString();
let json: any;
if (!json || json.error || typeof json.versions !== "object" || !json.versions) {
const message = json?.error ? `: ${json.error}` : "";
try {
json = await downloadJson({ url: registryUrl }).promise;
Notifications.error(`Failed to get registry information for that extension${message}`);
if (!json || json.error || typeof json.versions !== "object" || !json.versions) {
const message = json?.error ? `: ${json.error}` : "";
Notifications.error(`Failed to get registry information for that extension${message}`);
return disposer();
}
} catch (error) {
if (error instanceof SyntaxError) {
// assume invalid JSON
console.warn("Set registry has invalid json", { url: baseRegistryUrl }, error);
Notifications.error("Failed to get valid registry information for that extension. Registry did not return valid JSON");
} else {
console.error("Failed to download registry information", error);
Notifications.error(`Failed to get valid registry information for that extension. ${error}`);
}
return disposer();
}