mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
130 lines
2.5 KiB
TypeScript
130 lines
2.5 KiB
TypeScript
import pathToRegExp from "path-to-regexp";
|
|
import { apiKubeHelm } from "../index";
|
|
import { stringify } from "querystring";
|
|
import { autobind } from "../../utils";
|
|
|
|
interface IHelmChartList {
|
|
[repo: string]: {
|
|
[name: string]: HelmChart;
|
|
};
|
|
}
|
|
|
|
export interface IHelmChartDetails {
|
|
readme: string;
|
|
versions: HelmChart[];
|
|
}
|
|
|
|
const endpoint = pathToRegExp.compile(`/v2/charts/:repo?/:name?`) as (params?: {
|
|
repo?: string;
|
|
name?: string;
|
|
}) => string;
|
|
|
|
export const helmChartsApi = {
|
|
list() {
|
|
return apiKubeHelm
|
|
.get<IHelmChartList>(endpoint())
|
|
.then(data => {
|
|
return Object
|
|
.values(data)
|
|
.reduce((allCharts, repoCharts) => allCharts.concat(Object.values(repoCharts)), [])
|
|
.map(HelmChart.create);
|
|
});
|
|
},
|
|
|
|
get(repo: string, name: string, readmeVersion?: string) {
|
|
const path = endpoint({ repo, name });
|
|
return apiKubeHelm
|
|
.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 apiKubeHelm
|
|
.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.digest;
|
|
}
|
|
|
|
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 || [];
|
|
}
|
|
}
|