1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/api/endpoints/helm-charts.api.ts
Alex Andreev 6876d774a5
Fix: deprecated helm chart filtering (#2158)
* Refactor of excludeDeprecated helm service method

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Pick first helm chart from the list on load

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Removing helm filtering in UI

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Cleaning up

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Cleaning up type definitions

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Adding sorting charts by version

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Adding tests for methods that manipute chart listing

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Cleaning up tests a bit

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Adding semver coercion before comparing versions

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
2021-02-24 10:20:06 +03:00

129 lines
2.5 KiB
TypeScript

import { compile } from "path-to-regexp";
import { apiBase } from "../index";
import { stringify } from "querystring";
import { autobind } from "../../utils";
export type RepoHelmChartList = Record<string, HelmChart[]>;
export type HelmChartList = Record<string, RepoHelmChartList>;
export interface IHelmChartDetails {
readme: string;
versions: HelmChart[];
}
const endpoint = compile(`/v2/charts/:repo?/:name?`) as (params?: {
repo?: string;
name?: string;
}) => string;
export const helmChartsApi = {
list() {
return apiBase
.get<HelmChartList>(endpoint())
.then(data => {
return Object
.values(data)
.reduce((allCharts, repoCharts) => allCharts.concat(Object.values(repoCharts)), [])
.map(([chart]) => HelmChart.create(chart));
});
},
get(repo: string, name: string, readmeVersion?: string) {
const path = endpoint({ repo, name });
return apiBase
.get<IHelmChartDetails>(`${path}?${stringify({ version: readmeVersion })}`)
.then(data => {
const versions = data.versions.map(HelmChart.create);
const readme = data.readme;
return {
readme,
versions,
};
});
},
getValues(repo: string, name: string, version: string) {
return apiBase
.get<string>(`/v2/charts/${repo}/${name}/values?${stringify({ version })}`);
}
};
@autobind()
export class HelmChart {
constructor(data: any) {
Object.assign(this, data);
}
static create(data: any) {
return new HelmChart(data);
}
apiVersion: string;
name: string;
version: string;
repo: string;
kubeVersion?: string;
created: string;
description?: string;
digest: string;
keywords?: string[];
home?: string;
sources?: string[];
maintainers?: {
name: string;
email: string;
url: string;
}[];
engine?: string;
icon?: string;
appVersion?: string;
deprecated?: boolean;
tillerVersion?: string;
getId() {
return `${this.apiVersion}/${this.name}@${this.getAppVersion()}`;
}
getName() {
return this.name;
}
getFullName(splitter = "/") {
return [this.getRepository(), this.getName()].join(splitter);
}
getDescription() {
return this.description;
}
getIcon() {
return this.icon;
}
getHome() {
return this.home;
}
getMaintainers() {
return this.maintainers || [];
}
getVersion() {
return this.version;
}
getRepository() {
return this.repo;
}
getAppVersion() {
return this.appVersion || "";
}
getKeywords() {
return this.keywords || [];
}
}