permission-backend: remove manual construction of service discovery

We shouldn't be constructing a service discovery implementation inside
the router, since it removes the ability to provide a different
discovery mechanism.

Signed-off-by: Mike Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
Mike Lewis
2021-11-22 13:23:14 +00:00
parent e9b6b7bf89
commit 0ce2bc4129
4 changed files with 12 additions and 15 deletions
+2 -2
View File
@@ -3,10 +3,10 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { Config } from '@backstage/config';
import express from 'express';
import { Logger as Logger_2 } from 'winston';
import { PermissionPolicy } from '@backstage/plugin-permission-node';
import { PluginEndpointDiscovery } from '@backstage/backend-common';
// Warning: (ae-missing-release-tag) "createRouter" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
@@ -18,7 +18,7 @@ export function createRouter(options: RouterOptions): Promise<express.Router>;
// @public (undocumented)
export interface RouterOptions {
// (undocumented)
config: Config;
discovery: PluginEndpointDiscovery;
// (undocumented)
logger: Logger_2;
// (undocumented)
@@ -17,7 +17,6 @@
import express from 'express';
import request from 'supertest';
import { getVoidLogger } from '@backstage/backend-common';
import { ConfigReader } from '@backstage/config';
import {
AuthorizeResult,
Permission,
@@ -67,12 +66,10 @@ describe('createRouter', () => {
beforeAll(async () => {
const router = await createRouter({
logger: getVoidLogger(),
config: new ConfigReader({
backend: {
baseUrl: 'http://localhost',
listen: { port: 7007 },
},
}),
discovery: {
getBaseUrl: jest.fn(),
getExternalBaseUrl: jest.fn(),
},
policy,
});
@@ -16,7 +16,6 @@
import {
errorHandler,
SingleHostDiscovery,
PluginEndpointDiscovery,
} from '@backstage/backend-common';
import express, { Request, Response } from 'express';
@@ -26,7 +25,6 @@ import {
BackstageIdentity,
IdentityClient,
} from '@backstage/plugin-auth-backend';
import { Config } from '@backstage/config';
import { ConflictError } from '@backstage/errors';
import {
AuthorizeResult,
@@ -39,7 +37,7 @@ import { PermissionIntegrationClient } from './PermissionIntegrationClient';
export interface RouterOptions {
logger: Logger;
config: Config;
discovery: PluginEndpointDiscovery;
policy: PermissionPolicy;
}
@@ -84,8 +82,8 @@ const handleRequest = async (
export async function createRouter(
options: RouterOptions,
): Promise<express.Router> {
const { config, policy } = options;
const discovery = SingleHostDiscovery.fromConfig(config);
const { policy, discovery } = options;
const identity = new IdentityClient({
discovery,
issuer: await discovery.getExternalBaseUrl('auth'),
@@ -17,6 +17,7 @@
import {
createServiceBuilder,
loadBackendConfig,
SingleHostDiscovery,
} from '@backstage/backend-common';
import { Server } from 'http';
import { Logger } from 'winston';
@@ -34,10 +35,11 @@ export async function startStandaloneServer(
): Promise<Server> {
const logger = options.logger.child({ service: 'permission-backend' });
const config = await loadBackendConfig({ logger, argv: process.argv });
const discovery = SingleHostDiscovery.fromConfig(config);
logger.debug('Starting application server...');
const router = await createRouter({
logger,
config,
discovery,
policy: new AllowAllPermissionPolicy(),
});