1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/dashboard/client/config.store.ts
Jari Kolehmainen 1d0815abd2
Lens app source code (#119)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
2020-03-15 09:52:02 +02:00

59 lines
1.3 KiB
TypeScript
Executable File

// Client-side config
import { observable, when } from "mobx";
import { autobind, interval } from "./utils";
import { IConfig } from "../server/common/config";
import { IClientVars } from "../server/config";
import { configApi } from "./api/endpoints/config.api";
const { IS_PRODUCTION, API_PREFIX, LOCAL_SERVER_PORT, BUILD_VERSION } = process.env as any as IClientVars;
@autobind()
export class ConfigStore {
readonly isDevelopment = !IS_PRODUCTION;
readonly apiPrefix = API_PREFIX;
readonly buildVersion = BUILD_VERSION;
// auto-update config
protected updater = interval(60, this.load);
@observable config: Partial<IConfig> = {};
@observable isLoaded = false;
constructor() {
this.updater.start();
}
load() {
return configApi.getConfig().then((config: any) => {
this.config = config;
this.isLoaded = true;
});
}
async getToken() {
await when(() => this.isLoaded);
return this.config.token;
}
get serverPort() {
const port = location.port;
return port ? `:${port}` : "";
}
get allowedNamespaces() {
return this.config.allowedNamespaces || [];
}
get isClusterAdmin() {
return this.config.isClusterAdmin;
}
reset() {
this.isLoaded = false;
this.config = {};
}
}
export const configStore = new ConfigStore();