mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
work on helm-charts api
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
b2d4311e94
commit
361baaf247
@ -187,6 +187,7 @@
|
|||||||
"@hapi/call": "^8.0.0",
|
"@hapi/call": "^8.0.0",
|
||||||
"@hapi/subtext": "^7.0.3",
|
"@hapi/subtext": "^7.0.3",
|
||||||
"@kubernetes/client-node": "^0.12.0",
|
"@kubernetes/client-node": "^0.12.0",
|
||||||
|
"@types/url-parse": "^1.4.3",
|
||||||
"array-move": "^3.0.0",
|
"array-move": "^3.0.0",
|
||||||
"await-lock": "^2.1.0",
|
"await-lock": "^2.1.0",
|
||||||
"byline": "^5.0.0",
|
"byline": "^5.0.0",
|
||||||
@ -232,6 +233,7 @@
|
|||||||
"tar": "^6.0.5",
|
"tar": "^6.0.5",
|
||||||
"tcp-port-used": "^1.0.1",
|
"tcp-port-used": "^1.0.1",
|
||||||
"tempy": "^0.5.0",
|
"tempy": "^0.5.0",
|
||||||
|
"url-parse": "^1.5.1",
|
||||||
"uuid": "^8.3.2",
|
"uuid": "^8.3.2",
|
||||||
"win-ca": "^3.2.0",
|
"win-ca": "^3.2.0",
|
||||||
"winston": "^3.2.1",
|
"winston": "^3.2.1",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { compile } from "path-to-regexp";
|
import { compile } from "path-to-regexp";
|
||||||
import { apiBase } from "../index";
|
import { apiBase } from "../index";
|
||||||
import { stringify } from "querystring";
|
import * as querystring from "querystring";
|
||||||
import { autobind } from "../../utils";
|
import { autobind } from "../../utils";
|
||||||
|
|
||||||
interface IHelmChartList {
|
interface IHelmChartList {
|
||||||
@ -19,39 +19,44 @@ const endpoint = compile(`/v2/charts/:repo?/:name?`) as (params?: {
|
|||||||
name?: string;
|
name?: string;
|
||||||
}) => string;
|
}) => string;
|
||||||
|
|
||||||
export const helmChartsApi = {
|
export async function list(): Promise<HelmChart[]> {
|
||||||
list() {
|
const data = await apiBase.get<IHelmChartList>(endpoint());
|
||||||
return apiBase
|
|
||||||
.get<IHelmChartList>(endpoint())
|
|
||||||
.then(data => {
|
|
||||||
return Object
|
return Object
|
||||||
.values(data)
|
.values(data)
|
||||||
.reduce((allCharts, repoCharts) => allCharts.concat(Object.values(repoCharts)), [])
|
.reduce((allCharts, repoCharts) => allCharts.concat(Object.values(repoCharts)), [])
|
||||||
.map(HelmChart.create);
|
.map(HelmChart.create);
|
||||||
});
|
}
|
||||||
},
|
|
||||||
|
|
||||||
get(repo: string, name: string, readmeVersion?: string) {
|
interface GetHelmChartInfoOptions {
|
||||||
|
readmeVersion?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface HelmChartInfo {
|
||||||
|
readme: string;
|
||||||
|
versions: HelmChart[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function get(repo: string, name: string, { readmeVersion }: GetHelmChartInfoOptions = {}): Promise<HelmChartInfo> {
|
||||||
const path = endpoint({ repo, name });
|
const path = endpoint({ repo, name });
|
||||||
|
const qs = querystring.stringify({ version: readmeVersion });
|
||||||
return apiBase
|
const url = `${path}?${qs}`;
|
||||||
.get<IHelmChartDetails>(`${path}?${stringify({ version: readmeVersion })}`)
|
const { readme, versions: rawVersions } = await apiBase.get<IHelmChartDetails>(url);
|
||||||
.then(data => {
|
const versions = rawVersions.map(HelmChart.create);
|
||||||
const versions = data.versions.map(HelmChart.create);
|
|
||||||
const readme = data.readme;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
readme,
|
readme,
|
||||||
versions,
|
versions,
|
||||||
};
|
};
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
getValues(repo: string, name: string, version: string) {
|
|
||||||
return apiBase
|
|
||||||
.get<string>(`/v2/charts/${repo}/${name}/values?${stringify({ version })}`);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
export async function getValues(repo: string, name: string, readmeVersion: string): Promise<string> {
|
||||||
|
const path = endpoint({ repo, name });
|
||||||
|
const qs = querystring.stringify({ version: readmeVersion });
|
||||||
|
const url = `${path}/values?${qs}`;
|
||||||
|
|
||||||
|
return apiBase.get<string>(url);
|
||||||
|
}
|
||||||
|
|
||||||
@autobind()
|
@autobind()
|
||||||
export class HelmChart {
|
export class HelmChart {
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
// Base http-service / json-api class
|
// Base http-service / json-api class
|
||||||
|
|
||||||
import { stringify } from "querystring";
|
|
||||||
import { EventEmitter } from "../../common/event-emitter";
|
import { EventEmitter } from "../../common/event-emitter";
|
||||||
import { cancelableFetch } from "../utils/cancelableFetch";
|
import { cancelableFetch } from "../utils/cancelableFetch";
|
||||||
import { randomBytes } from "crypto";
|
import { randomBytes } from "crypto";
|
||||||
|
import Url from "url-parse";
|
||||||
export interface JsonApiData {
|
export interface JsonApiData {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,19 +58,13 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
|||||||
getResponse(path: string, params?: P, init: RequestInit = {}): Promise<Response> {
|
getResponse(path: string, params?: P, init: RequestInit = {}): Promise<Response> {
|
||||||
const reqPath = `${this.config.apiBase}${path}`;
|
const reqPath = `${this.config.apiBase}${path}`;
|
||||||
const subdomain = randomBytes(2).toString("hex");
|
const subdomain = randomBytes(2).toString("hex");
|
||||||
let reqUrl = `http://${subdomain}.${window.location.host}${reqPath}`; // hack around browser connection limits (chromium allows 6 per domain)
|
const reqUrl = new Url(`http://${subdomain}.${window.location.host}${reqPath}`); // hack around browser connection limits (chromium allows 6 per domain)
|
||||||
const reqInit: RequestInit = { ...init };
|
const reqInit: RequestInit = { ...init, method: "get" };
|
||||||
const { query } = params || {} as P;
|
|
||||||
|
|
||||||
if (!reqInit.method) {
|
reqUrl.set("query", {
|
||||||
reqInit.method = "get";
|
...(params?.query ?? {}),
|
||||||
}
|
...reqUrl.query,
|
||||||
|
});
|
||||||
if (query) {
|
|
||||||
const queryString = stringify(query);
|
|
||||||
|
|
||||||
reqUrl += (reqUrl.includes("?") ? "&" : "?") + queryString;
|
|
||||||
}
|
|
||||||
|
|
||||||
const infoLog: JsonApiLog = {
|
const infoLog: JsonApiLog = {
|
||||||
method: reqInit.method.toUpperCase(),
|
method: reqInit.method.toUpperCase(),
|
||||||
@ -80,7 +74,7 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
|||||||
|
|
||||||
this.writeLog({ ...infoLog });
|
this.writeLog({ ...infoLog });
|
||||||
|
|
||||||
return fetch(reqUrl, reqInit);
|
return fetch(reqUrl.toString(), reqInit);
|
||||||
}
|
}
|
||||||
|
|
||||||
post<T = D>(path: string, params?: P, reqInit: RequestInit = {}) {
|
post<T = D>(path: string, params?: P, reqInit: RequestInit = {}) {
|
||||||
@ -100,19 +94,19 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected request<D>(path: string, params?: P, init: RequestInit = {}) {
|
protected request<D>(path: string, params?: P, init: RequestInit = {}) {
|
||||||
let reqUrl = this.config.apiBase + path;
|
const targetUrl = new Url(this.config.apiBase + path);
|
||||||
const reqInit: RequestInit = { ...this.reqInit, ...init };
|
const reqInit = { ...this.reqInit, ...init };
|
||||||
const { data, query } = params || {} as P;
|
|
||||||
|
|
||||||
if (data && !reqInit.body) {
|
if (params?.data && !reqInit.body) {
|
||||||
reqInit.body = JSON.stringify(data);
|
reqInit.body = JSON.stringify(params?.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query) {
|
targetUrl.set("query", {
|
||||||
const queryString = stringify(query);
|
...(params?.query ?? {}),
|
||||||
|
...targetUrl.query,
|
||||||
|
});
|
||||||
|
|
||||||
reqUrl += (reqUrl.includes("?") ? "&" : "?") + queryString;
|
const reqUrl = targetUrl.toString();
|
||||||
}
|
|
||||||
const infoLog: JsonApiLog = {
|
const infoLog: JsonApiLog = {
|
||||||
method: reqInit.method.toUpperCase(),
|
method: reqInit.method.toUpperCase(),
|
||||||
reqUrl,
|
reqUrl,
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import { action, autorun } from "mobx";
|
import { action, autorun } from "mobx";
|
||||||
import { dockStore, IDockTab, TabId, TabKind } from "./dock.store";
|
import { dockStore, IDockTab, TabId, TabKind } from "./dock.store";
|
||||||
import { DockTabStore } from "./dock-tab.store";
|
import { DockTabStore } from "./dock-tab.store";
|
||||||
import { HelmChart, helmChartsApi } from "../../api/endpoints/helm-charts.api";
|
import { HelmChart } from "../../api/endpoints/helm-charts.api";
|
||||||
|
import * as helmChartsApi from "../../api/endpoints/helm-charts.api";
|
||||||
import { IReleaseUpdateDetails } from "../../api/endpoints/helm-releases.api";
|
import { IReleaseUpdateDetails } from "../../api/endpoints/helm-releases.api";
|
||||||
import { Notifications } from "../notifications";
|
import { Notifications } from "../notifications";
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ export class InstallChartStore extends DockTabStore<IChartInstallData> {
|
|||||||
const { repo, name, version } = this.getData(tabId);
|
const { repo, name, version } = this.getData(tabId);
|
||||||
|
|
||||||
this.versions.clearData(tabId); // reset
|
this.versions.clearData(tabId); // reset
|
||||||
const charts = await helmChartsApi.get(repo, name, version);
|
const charts = await helmChartsApi.get(repo, name, { readmeVersion: version });
|
||||||
const versions = charts.versions.map(chartVersion => chartVersion.version);
|
const versions = charts.versions.map(chartVersion => chartVersion.version);
|
||||||
|
|
||||||
this.versions.setData(tabId, versions);
|
this.versions.setData(tabId, versions);
|
||||||
|
|||||||
13
yarn.lock
13
yarn.lock
@ -1771,6 +1771,11 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@types/universal-analytics/-/universal-analytics-0.4.4.tgz#496a52b92b599a0112bec7c12414062de6ea8449"
|
resolved "https://registry.yarnpkg.com/@types/universal-analytics/-/universal-analytics-0.4.4.tgz#496a52b92b599a0112bec7c12414062de6ea8449"
|
||||||
integrity sha512-9g3F0SGxVr4UDd6y07bWtFnkpSSX1Ake7U7AGHgSFrwM6pF53/fV85bfxT2JLWS/3sjLCcyzoYzQlCxpkVo7wA==
|
integrity sha512-9g3F0SGxVr4UDd6y07bWtFnkpSSX1Ake7U7AGHgSFrwM6pF53/fV85bfxT2JLWS/3sjLCcyzoYzQlCxpkVo7wA==
|
||||||
|
|
||||||
|
"@types/url-parse@^1.4.3":
|
||||||
|
version "1.4.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/url-parse/-/url-parse-1.4.3.tgz#fba49d90f834951cb000a674efee3d6f20968329"
|
||||||
|
integrity sha512-4kHAkbV/OfW2kb5BLVUuUMoumB3CP8rHqlw48aHvFy5tf9ER0AfOonBlX29l/DD68G70DmyhRlSYfQPSYpC5Vw==
|
||||||
|
|
||||||
"@types/uuid@^8.3.0":
|
"@types/uuid@^8.3.0":
|
||||||
version "8.3.0"
|
version "8.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.0.tgz#215c231dff736d5ba92410e6d602050cce7e273f"
|
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.0.tgz#215c231dff736d5ba92410e6d602050cce7e273f"
|
||||||
@ -13762,6 +13767,14 @@ url-parse@^1.4.3:
|
|||||||
querystringify "^2.1.1"
|
querystringify "^2.1.1"
|
||||||
requires-port "^1.0.0"
|
requires-port "^1.0.0"
|
||||||
|
|
||||||
|
url-parse@^1.5.1:
|
||||||
|
version "1.5.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.1.tgz#d5fa9890af8a5e1f274a2c98376510f6425f6e3b"
|
||||||
|
integrity sha512-HOfCOUJt7iSYzEx/UqgtwKRMC6EU91NFhsCHMv9oM03VJcVo2Qrp8T8kI9D7amFf1cu+/3CEhgb3rF9zL7k85Q==
|
||||||
|
dependencies:
|
||||||
|
querystringify "^2.1.1"
|
||||||
|
requires-port "^1.0.0"
|
||||||
|
|
||||||
url-to-options@^1.0.1:
|
url-to-options@^1.0.1:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/url-to-options/-/url-to-options-1.0.1.tgz#1505a03a289a48cbd7a434efbaeec5055f5633a9"
|
resolved "https://registry.yarnpkg.com/url-to-options/-/url-to-options-1.0.1.tgz#1505a03a289a48cbd7a434efbaeec5055f5633a9"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user