1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

moves around extension API

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-05-25 15:28:24 -04:00
parent 4d05eff051
commit 5ff438ba42
23 changed files with 150 additions and 121 deletions

View File

@ -19,29 +19,21 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
// Lens-extensions api developer's kit
export { LensMainExtension } from "../lens-main-extension";
export { LensRendererExtension } from "../lens-renderer-extension";
// APIs // APIs
import * as App from "./app"; import * as App from "./app";
import * as EventBus from "./event-bus"; import * as EventBus from "./event-bus";
import * as Store from "./stores"; import * as Store from "./stores";
import * as Util from "./utils"; import * as Util from "./utils";
import * as Interface from "../interfaces";
import * as Main from "./main";
import * as Renderer from "./renderer";
import * as Catalog from "../../common/catalog"; import * as Catalog from "../../common/catalog";
import * as Types from "./types"; import * as Types from "./types";
import * as Registrations from "./registrations";
export { export {
App, App,
EventBus, EventBus,
Main,
Renderer,
Catalog, Catalog,
Interface,
Store, Store,
Types, Types,
Registrations,
Util, Util,
}; };

View File

@ -1,71 +0,0 @@
/**
* Copyright (c) 2021 OpenLens Authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import { CatalogEntityRegistry as InternalCatalogEntityRegistry, CatalogCategoryRegistry as InternalCatalogCategoryRegistry, CatalogEntity, CategoryHandlerNames, CatalogHandler, EntityContextHandlers, CategoryHandlers, GlobalContextHandlers } from "../../../renderer/catalog";
import type { CatalogCategoryRegistration } from "../../../renderer/catalog";
export type {
CatalogEntity,
} from "../../../renderer/catalog";
export class CatalogEntityRegistry {
static getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] {
return InternalCatalogEntityRegistry.getInstance().getItemsForApiKind<T>(apiVersion, kind);
}
}
export class CatalogCategoryRegistry {
static add(category: CatalogCategoryRegistration) {
return InternalCatalogCategoryRegistry.getInstance().add(category);
}
static get items() {
return InternalCatalogCategoryRegistry.getInstance().items;
}
static getForGroupKind(group: string, version: string, kind: string) {
return InternalCatalogCategoryRegistry.getInstance().getForGroupKind(group, version, kind);
}
static hasForGroupKind(group: string, version: string, kind: string) {
return InternalCatalogCategoryRegistry.getInstance().hasForGroupKind(group, version, kind);
}
static getCategoryForEntity(data: CatalogEntity) {
return InternalCatalogCategoryRegistry.getInstance().getCategoryForEntity(data);
}
static registerHandler(apiVersion: string, kind: string, handlerName: CategoryHandlerNames, handler: CatalogHandler<typeof handlerName>) {
return InternalCatalogCategoryRegistry.getInstance().registerHandler(apiVersion, kind, handlerName, handler);
}
static runEntityHandlersFor(entity: CatalogEntity, handlerName: "onContextMenuOpen"): ReturnType<CategoryHandlers[typeof handlerName]>;
static runEntityHandlersFor(entity: CatalogEntity, handlerName: "onSettingsOpen"): ReturnType<CategoryHandlers[typeof handlerName]>;
static runEntityHandlersFor(entity: CatalogEntity, handlerName: EntityContextHandlers): ReturnType<CategoryHandlers[typeof handlerName]> {
return InternalCatalogCategoryRegistry.getInstance().runEntityHandlersFor(entity, handlerName as any);
}
static runGlobalHandlersFor(reg: CatalogCategoryRegistration, handlerName: "onCatalogAddMenu"): ReturnType<CategoryHandlers[typeof handlerName]>;
static runGlobalHandlersFor(reg: CatalogCategoryRegistration, handlerName: GlobalContextHandlers): ReturnType<CategoryHandlers[typeof handlerName]> {
return InternalCatalogCategoryRegistry.getInstance().runGlobalHandlersFor(reg, handlerName as any);
}
}

View File

@ -22,5 +22,6 @@
// Extensions-api types bundle (main + renderer) // Extensions-api types bundle (main + renderer)
// Available for lens-extensions via NPM-package "@k8slens/extensions" // Available for lens-extensions via NPM-package "@k8slens/extensions"
export * from "./core-api"; export * as Common from "./common-api";
export * from "./renderer-api"; export * as Renderer from "./renderer-api";
export * as Main from "./main-api";

View File

@ -19,41 +19,42 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
import * as internal from "../../main/catalog";
import { CatalogEntityRegistry as InternalCatalogEntityRegistry, CatalogCategoryRegistry as InternalCatalogCategoryRegistry, CatalogEntity, CatalogCategoryRegistration, SpecEnhancer } from "../../../main/catalog";
export type { export type {
CatalogEntity, CatalogEntity,
} from "../../../main/catalog"; } from "../../main/catalog";
export * from "../../main/catalog-entities";
export class CatalogEntityRegistry { export class CatalogEntityRegistry {
static get items() { static get items() {
return InternalCatalogEntityRegistry.getInstance().items; return internal.CatalogEntityRegistry.getInstance().items;
} }
} }
export class CatalogCategoryRegistry { export class CatalogCategoryRegistry {
static add(category: CatalogCategoryRegistration) { static add(category: internal.CatalogCategoryRegistration) {
return InternalCatalogCategoryRegistry.getInstance().add(category); return internal.CatalogCategoryRegistry.getInstance().add(category);
} }
static get items() { static get items() {
return InternalCatalogCategoryRegistry.getInstance().items; return internal.CatalogCategoryRegistry.getInstance().items;
} }
static getForGroupKind(group: string, version: string, kind: string) { static getForGroupKind(group: string, version: string, kind: string) {
return InternalCatalogCategoryRegistry.getInstance().getForGroupKind(group, version, kind); return internal.CatalogCategoryRegistry.getInstance().getForGroupKind(group, version, kind);
} }
static hasForGroupKind(group: string, version: string, kind: string) { static hasForGroupKind(group: string, version: string, kind: string) {
return InternalCatalogCategoryRegistry.getInstance().hasForGroupKind(group, version, kind); return internal.CatalogCategoryRegistry.getInstance().hasForGroupKind(group, version, kind);
} }
static getCategoryForEntity(data: CatalogEntity) { static getCategoryForEntity(data: internal.CatalogEntity) {
return InternalCatalogCategoryRegistry.getInstance().getCategoryForEntity(data); return internal.CatalogCategoryRegistry.getInstance().getCategoryForEntity(data);
} }
static registerSpecEnhancer(apiVersion: string, kind: string, handler: SpecEnhancer) { static registerSpecEnhancer(apiVersion: string, kind: string, handler: internal.SpecEnhancer) {
return InternalCatalogCategoryRegistry.getInstance().registerSpecEnhancer(apiVersion, kind, handler); return internal.CatalogCategoryRegistry.getInstance().registerSpecEnhancer(apiVersion, kind, handler);
} }
} }

View File

@ -19,5 +19,10 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
export * from "./registrations"; import * as Catalog from "./catalog";
export * from "./catalog";
export { LensMainExtension } from "../lens-main-extension";
export {
Catalog,
};

View File

@ -0,0 +1,74 @@
/**
* Copyright (c) 2021 OpenLens Authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import * as internal from "../../renderer/catalog";
export type {
CatalogEntity,
CatalogCategoryRegistration,
} from "../../renderer/catalog";
export type {
KubernetesCluster,
} from "../../renderer/catalog-entities";
export class CatalogEntityRegistry {
static getItemsForApiKind<T extends internal.CatalogEntity>(apiVersion: string, kind: string): T[] {
return internal.CatalogEntityRegistry.getInstance().getItemsForApiKind<T>(apiVersion, kind);
}
}
export class CatalogCategoryRegistry {
static add(category: internal.CatalogCategoryRegistration) {
return internal.CatalogCategoryRegistry.getInstance().add(category);
}
static get items() {
return internal.CatalogCategoryRegistry.getInstance().items;
}
static getForGroupKind(group: string, version: string, kind: string) {
return internal.CatalogCategoryRegistry.getInstance().getForGroupKind(group, version, kind);
}
static hasForGroupKind(group: string, version: string, kind: string) {
return internal.CatalogCategoryRegistry.getInstance().hasForGroupKind(group, version, kind);
}
static getCategoryForEntity(data: internal.CatalogEntity) {
return internal.CatalogCategoryRegistry.getInstance().getCategoryForEntity(data);
}
static registerHandler(apiVersion: string, kind: string, handlerName: internal.CategoryHandlerNames, handler: internal.CatalogHandler<typeof handlerName>) {
return internal.CatalogCategoryRegistry.getInstance().registerHandler(apiVersion, kind, handlerName, handler);
}
static runEntityHandlersFor(entity: internal.CatalogEntity, handlerName: "onContextMenuOpen"): ReturnType<internal.CategoryHandlers[typeof handlerName]>;
static runEntityHandlersFor(entity: internal.CatalogEntity, handlerName: "onSettingsOpen"): ReturnType<internal.CategoryHandlers[typeof handlerName]>;
static runEntityHandlersFor(entity: internal.CatalogEntity, handlerName: internal.EntityContextHandlers): ReturnType<internal.CategoryHandlers[typeof handlerName]> {
return internal.CatalogCategoryRegistry.getInstance().runEntityHandlersFor(entity, handlerName as any);
}
static runGlobalHandlersFor(reg: internal.CatalogCategoryRegistration, handlerName: "onCatalogAddMenu"): ReturnType<internal.CategoryHandlers[typeof handlerName]>;
static runGlobalHandlersFor(reg: internal.CatalogCategoryRegistration, handlerName: internal.GlobalContextHandlers): ReturnType<internal.CategoryHandlers[typeof handlerName]> {
return internal.CatalogCategoryRegistry.getInstance().runGlobalHandlersFor(reg, handlerName as any);
}
}

View File

@ -20,16 +20,19 @@
*/ */
// Lens-extensions apis, required in renderer process runtime // Lens-extensions apis, required in renderer process runtime
export { LensRendererExtension } from "../lens-renderer-extension";
// APIs // APIs
import * as Component from "./components"; import * as Component from "./components";
import * as K8sApi from "./k8s-api"; import * as K8sApi from "./k8s-api";
import * as Navigation from "./navigation"; import * as Navigation from "./navigation";
import * as Theme from "./theming"; import * as Theme from "./theming";
import * as Catalog from "./catalog";
export { export {
Component, Component,
K8sApi, K8sApi,
Navigation, Navigation,
Theme, Theme,
Catalog,
}; };

View File

@ -19,4 +19,10 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
export * as Catalog from "./catalog"; import * as KubernetesCluster from "./kubernetes-cluster";
import * as WebLink from "./web-link";
export {
KubernetesCluster,
WebLink,
};

View File

@ -19,4 +19,15 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
export * as Catalog from "./catalog"; import type { CatalogEntityMetadata } from "../../common/catalog";
import type { KubernetesClusterSpec } from "../../common/catalog-entities";
import type { CatalogEntity } from "../catalog/catalog-entity";
export function v1alpha1(metadata: CatalogEntityMetadata, spec: KubernetesClusterSpec): CatalogEntity<CatalogEntityMetadata, KubernetesClusterSpec> {
return {
apiVersion: "entity.k8slens.dev/v1alpha1",
kind: "KubernetesCluster",
metadata,
spec,
};
}

View File

@ -19,4 +19,15 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
export * from "../../common/catalog/catalog-entity"; import type { CatalogEntityMetadata } from "../../common/catalog";
import type { WebLinkSpec } from "../../common/catalog-entities";
import type { CatalogEntity } from "../catalog";
export function v1alpha1(metadata: CatalogEntityMetadata, spec: WebLinkSpec): CatalogEntity<CatalogEntityMetadata, WebLinkSpec> {
return {
apiVersion: "entity.k8slens.dev/v1alpha1",
kind: "WebLink",
metadata,
spec,
};
}

View File

@ -31,6 +31,7 @@ import { noop, Singleton } from "../common/utils";
import { CatalogCategoryRegistry, CatalogEntity } from "./catalog"; import { CatalogCategoryRegistry, CatalogEntity } from "./catalog";
import type { KubernetesClusterSpec } from "../common/catalog-entities/kubernetes-cluster"; import type { KubernetesClusterSpec } from "../common/catalog-entities/kubernetes-cluster";
import type { CatalogEntityMetadata } from "../common/catalog"; import type { CatalogEntityMetadata } from "../common/catalog";
import { KubernetesCluster } from "./catalog-entities";
export class ClusterManager extends Singleton { export class ClusterManager extends Singleton {
protected clusters = observable.map<string, Cluster>(); protected clusters = observable.map<string, Cluster>();
@ -155,10 +156,8 @@ export class ClusterManager extends Singleton {
} }
export function catalogEntityFromCluster(cluster: ClusterModel): CatalogEntity<CatalogEntityMetadata, KubernetesClusterSpec> { export function catalogEntityFromCluster(cluster: ClusterModel): CatalogEntity<CatalogEntityMetadata, KubernetesClusterSpec> {
return { return KubernetesCluster.v1alpha1(
apiVersion: "entity.k8slens.dev/v1alpha1", {
kind: "KubernetesCluster",
metadata: {
uid: cluster.id, uid: cluster.id,
name: cluster.contextName, name: cluster.contextName,
source: "local", source: "local",
@ -166,9 +165,9 @@ export function catalogEntityFromCluster(cluster: ClusterModel): CatalogEntity<C
distro: cluster.metadata.distribution?.toString() || "unknown", distro: cluster.metadata.distribution?.toString() || "unknown",
} }
}, },
spec: { {
kubeconfigPath: cluster.kubeConfigPath, kubeconfigPath: cluster.kubeConfigPath,
kubeconfigContext: cluster.contextName kubeconfigContext: cluster.contextName
}, }
}; );
} }

View File

@ -24,7 +24,7 @@
import "../common/system-ca"; import "../common/system-ca";
import "../common/prometheus-providers"; import "../common/prometheus-providers";
import * as Mobx from "mobx"; import * as Mobx from "mobx";
import * as LensExtensionsCoreApi from "../extensions/core-api"; import * as LensExtensionsCoreApi from "../extensions/common-api";
import { app, autoUpdater, ipcMain, dialog, powerMonitor } from "electron"; import { app, autoUpdater, ipcMain, dialog, powerMonitor } from "electron";
import { appName, isMac, productName } from "../common/vars"; import { appName, isMac, productName } from "../common/vars";
import path from "path"; import path from "path";

View File

@ -24,7 +24,7 @@ import * as uuid from "uuid";
import { broadcastMessage } from "../../../common/ipc"; import { broadcastMessage } from "../../../common/ipc";
import { ProtocolHandlerExtension, ProtocolHandlerInternal } from "../../../common/protocol-handler"; import { ProtocolHandlerExtension, ProtocolHandlerInternal } from "../../../common/protocol-handler";
import { noop } from "../../../common/utils"; import { noop } from "../../../common/utils";
import { LensMainExtension } from "../../../extensions/core-api"; import { LensMainExtension } from "../../../extensions/main-api";
import { ExtensionLoader } from "../../../extensions/extension-loader"; import { ExtensionLoader } from "../../../extensions/extension-loader";
import { ExtensionsStore } from "../../../extensions/extensions-store"; import { ExtensionsStore } from "../../../extensions/extensions-store";
import { LensProtocolRouterMain } from "../router"; import { LensProtocolRouterMain } from "../router";

View File

@ -26,7 +26,7 @@ import * as Mobx from "mobx";
import * as MobxReact from "mobx-react"; import * as MobxReact from "mobx-react";
import * as ReactRouter from "react-router"; import * as ReactRouter from "react-router";
import * as ReactRouterDom from "react-router-dom"; import * as ReactRouterDom from "react-router-dom";
import * as LensExtensionsCoreApi from "../extensions/core-api"; import * as LensExtensionsCoreApi from "../extensions/common-api";
import * as LensExtensionsRendererApi from "../extensions/renderer-api"; import * as LensExtensionsRendererApi from "../extensions/renderer-api";
import { render, unmountComponentAtNode } from "react-dom"; import { render, unmountComponentAtNode } from "react-dom";
import { delay } from "../common/utils"; import { delay } from "../common/utils";
@ -48,11 +48,6 @@ import configurePackages from "../common/configure-packages";
configurePackages(); configurePackages();
async function attachChromeDebugger() { async function attachChromeDebugger() {
if (isDevelopment) { if (isDevelopment) {
await delay(1000); await delay(1000);

View File

@ -37,7 +37,7 @@ export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, Kube
return requestMain(clusterDisconnectHandler, this.metadata.uid, false); return requestMain(clusterDisconnectHandler, this.metadata.uid, false);
} }
onRun = (context: CatalogEntityActionContext) => { onRun(context: CatalogEntityActionContext) {
context.navigate(`/cluster/${this.metadata.uid}`); context.navigate(`/cluster/${this.metadata.uid}`);
}; }
} }

View File

@ -27,7 +27,7 @@ export class WebLink extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
public readonly apiVersion = "entity.k8slens.dev/v1alpha1"; public readonly apiVersion = "entity.k8slens.dev/v1alpha1";
public readonly kind = "WebLink"; public readonly kind = "WebLink";
onRun = () => { onRun() {
window.open(this.spec.url, "_blank"); window.open(this.spec.url, "_blank");
}; }
} }

View File

@ -118,5 +118,7 @@ export class CatalogEntity<
this.name = this.metadata.name; this.name = this.metadata.name;
} }
onRun?(context: CatalogEntityActionContext): void; onRun(context: CatalogEntityActionContext): void {
void context;
}
} }