From 6f02d23b01c46e6ff8b021e5ef30577f28be0118 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 3 Jan 2023 14:58:31 +0100 Subject: [PATCH] backend-common: Move PluginEndpointDiscovery type to backend-plugin-api Signed-off-by: Johan Haals --- .changeset/nervous-ravens-cough.md | 6 +++ packages/backend-common/api-report.md | 7 +-- .../backend-common/src/discovery/types.ts | 48 +----------------- packages/backend-plugin-api/api-report.md | 10 ++-- .../definitions/discoveryServiceRef.ts | 50 +++++++++++++++++-- 5 files changed, 62 insertions(+), 59 deletions(-) create mode 100644 .changeset/nervous-ravens-cough.md diff --git a/.changeset/nervous-ravens-cough.md b/.changeset/nervous-ravens-cough.md new file mode 100644 index 0000000000..8b371a2413 --- /dev/null +++ b/.changeset/nervous-ravens-cough.md @@ -0,0 +1,6 @@ +--- +'@backstage/backend-plugin-api': patch +'@backstage/backend-common': patch +--- + +Moved `PluginEndpointDiscovery` type from backend-common to backend-plugin-api. diff --git a/packages/backend-common/api-report.md b/packages/backend-common/api-report.md index abb45b0fe7..e8b41e21bb 100644 --- a/packages/backend-common/api-report.md +++ b/packages/backend-common/api-report.md @@ -30,6 +30,7 @@ import { KubeConfig } from '@kubernetes/client-node'; import { LoadConfigOptionsRemote } from '@backstage/config-loader'; import { Logger } from 'winston'; import { MergeResult } from 'isomorphic-git'; +import { DiscoveryService as PluginEndpointDiscovery } from '@backstage/backend-plugin-api'; import { PushResult } from 'isomorphic-git'; import { Readable } from 'stream'; import { ReadCommitResult } from 'isomorphic-git'; @@ -530,11 +531,7 @@ export interface PluginDatabaseManager { }; } -// @public -export type PluginEndpointDiscovery = { - getBaseUrl(pluginId: string): Promise; - getExternalBaseUrl(pluginId: string): Promise; -}; +export { PluginEndpointDiscovery }; // @public export type ReaderFactory = (options: { diff --git a/packages/backend-common/src/discovery/types.ts b/packages/backend-common/src/discovery/types.ts index 0b502bf88c..3ecdb7aa39 100644 --- a/packages/backend-common/src/discovery/types.ts +++ b/packages/backend-common/src/discovery/types.ts @@ -14,50 +14,4 @@ * limitations under the License. */ -/** - * The PluginEndpointDiscovery is used to provide a mechanism for backend - * plugins to discover the endpoints for itself or other backend plugins. - * - * The purpose of the discovery API is to allow for many different deployment - * setups and routing methods through a central configuration, instead - * of letting each individual plugin manage that configuration. - * - * Implementations of the discovery API can be as simple as a URL pattern - * using the pluginId, but could also have overrides for individual plugins, - * or query a separate discovery service. - * - * @public - */ -export type PluginEndpointDiscovery = { - /** - * Returns the internal HTTP base URL for a given plugin, without a trailing slash. - * - * The returned URL should point to an internal endpoint for the plugin, with - * the shortest route possible. The URL should be used for service-to-service - * communication within a Backstage backend deployment. - * - * This method must always be called just before making a request, as opposed to - * fetching the URL when constructing an API client. That is to ensure that more - * flexible routing patterns can be supported. - * - * For example, asking for the URL for `catalog` may return something - * like `http://10.1.2.3/api/catalog` - */ - getBaseUrl(pluginId: string): Promise; - - /** - * Returns the external HTTP base backend URL for a given plugin, without a trailing slash. - * - * The returned URL should point to an external endpoint for the plugin, such that - * it is reachable from the Backstage frontend and other external services. The returned - * URL should be usable for example as a callback / webhook URL. - * - * The returned URL should be stable and in general not change unless other static - * or external configuration is changed. Changes should not come as a surprise - * to an operator of the Backstage backend. - * - * For example, asking for the URL for `catalog` may return something - * like `https://backstage.example.com/api/catalog` - */ - getExternalBaseUrl(pluginId: string): Promise; -}; +export type { DiscoveryService as PluginEndpointDiscovery } from '@backstage/backend-plugin-api'; diff --git a/packages/backend-plugin-api/api-report.md b/packages/backend-plugin-api/api-report.md index 1b7e5a4b7e..e0fa44eb20 100644 --- a/packages/backend-plugin-api/api-report.md +++ b/packages/backend-plugin-api/api-report.md @@ -12,7 +12,6 @@ import { PermissionAuthorizer } from '@backstage/plugin-permission-common'; import { PermissionEvaluator } from '@backstage/plugin-permission-common'; import { PluginCacheManager } from '@backstage/backend-common'; import { PluginDatabaseManager } from '@backstage/backend-common'; -import { PluginEndpointDiscovery } from '@backstage/backend-common'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; import { Readable } from 'stream'; import { TokenManager } from '@backstage/backend-common'; @@ -169,11 +168,14 @@ export type DatabaseService = PluginDatabaseManager; // @public (undocumented) const databaseServiceRef: ServiceRef; -// @public (undocumented) -export type DiscoveryService = PluginEndpointDiscovery; +// @public +export type DiscoveryService = { + getBaseUrl(pluginId: string): Promise; + getExternalBaseUrl(pluginId: string): Promise; +}; // @public (undocumented) -const discoveryServiceRef: ServiceRef; +const discoveryServiceRef: ServiceRef; // @public export type ExtensionPoint = { diff --git a/packages/backend-plugin-api/src/services/definitions/discoveryServiceRef.ts b/packages/backend-plugin-api/src/services/definitions/discoveryServiceRef.ts index 41505e7756..fb508a7ae1 100644 --- a/packages/backend-plugin-api/src/services/definitions/discoveryServiceRef.ts +++ b/packages/backend-plugin-api/src/services/definitions/discoveryServiceRef.ts @@ -15,10 +15,54 @@ */ import { createServiceRef } from '../system/types'; -import { PluginEndpointDiscovery } from '@backstage/backend-common'; -/** @public */ -export type DiscoveryService = PluginEndpointDiscovery; +/** + * The DiscoveryService is used to provide a mechanism for backend + * plugins to discover the endpoints for itself or other backend plugins. + * + * The purpose of the discovery API is to allow for many different deployment + * setups and routing methods through a central configuration, instead + * of letting each individual plugin manage that configuration. + * + * Implementations of the discovery API can be as simple as a URL pattern + * using the pluginId, but could also have overrides for individual plugins, + * or query a separate discovery service. + * + * @public + */ +export type DiscoveryService = { + /** + * Returns the internal HTTP base URL for a given plugin, without a trailing slash. + * + * The returned URL should point to an internal endpoint for the plugin, with + * the shortest route possible. The URL should be used for service-to-service + * communication within a Backstage backend deployment. + * + * This method must always be called just before making a request, as opposed to + * fetching the URL when constructing an API client. That is to ensure that more + * flexible routing patterns can be supported. + * + * For example, asking for the URL for `catalog` may return something + * like `http://10.1.2.3/api/catalog` + */ + getBaseUrl(pluginId: string): Promise; + + /** + * Returns the external HTTP base backend URL for a given plugin, without a trailing slash. + * + * The returned URL should point to an external endpoint for the plugin, such that + * it is reachable from the Backstage frontend and other external services. The returned + * URL should be usable for example as a callback / webhook URL. + * + * The returned URL should be stable and in general not change unless other static + * or external configuration is changed. Changes should not come as a surprise + * to an operator of the Backstage backend. + * + * For example, asking for the URL for `catalog` may return something + * like `https://backstage.example.com/api/catalog` + */ + getExternalBaseUrl(pluginId: string): Promise; +}; /** * @public