mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Register alternate API base URL if preferred version changes.
Signed-off-by: Trevor Nichols <trevor@nichols.id.au>
This commit is contained in:
parent
42f352b73a
commit
23f38984f7
@ -1,16 +1,35 @@
|
||||
import { stringify } from "querystring";
|
||||
import { KubeObject } from "./kube-object";
|
||||
import { createKubeApiURL } from "./kube-api-parse";
|
||||
import { KubeApi, IKubeApiQueryParams } from "./kube-api";
|
||||
import { KubeApi, IKubeApiQueryParams, IKubeApiOptions } from "./kube-api";
|
||||
import { apiManager } from "./api-manager";
|
||||
|
||||
export class VersionedKubeApi<T extends KubeObject = any> extends KubeApi<T> {
|
||||
private preferredVersion?: string;
|
||||
|
||||
constructor(opts: IKubeApiOptions<T>) {
|
||||
super(opts);
|
||||
|
||||
this.getPreferredVersion().then(() => {
|
||||
if (this.apiBase != opts.apiBase)
|
||||
apiManager.registerApi(this.apiBase, this);
|
||||
});
|
||||
}
|
||||
|
||||
// override this property to make read-write
|
||||
apiBase: string
|
||||
|
||||
async getPreferredVersion() {
|
||||
if (this.preferredVersion) return;
|
||||
|
||||
const apiGroupVersion = await this.request.get<{ preferredVersion: { version: string; }; }>(`${this.apiPrefix}/${this.apiGroup}`);
|
||||
const apiGroupVersion = await this.request.get<{ preferredVersion?: { version: string; }; }>(`${this.apiPrefix}/${this.apiGroup}`);
|
||||
|
||||
if (!apiGroupVersion?.preferredVersion) return;
|
||||
|
||||
this.preferredVersion = apiGroupVersion.preferredVersion.version;
|
||||
|
||||
// update apiBase
|
||||
this.apiBase = this.getUrl();
|
||||
}
|
||||
|
||||
async list({ namespace = "" } = {}, query?: IKubeApiQueryParams): Promise<T[]> {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user