Merge branch 'master' of github.com:ryan-hanchett/backstage into feat/doc-table-pagesize

This commit is contained in:
Ryan Hanchett
2023-01-23 15:38:05 -08:00
205 changed files with 5101 additions and 1328 deletions
+1 -1
View File
@@ -84,7 +84,7 @@
},
"devDependencies": {
"@backstage/test-utils": "workspace:^",
"@testing-library/cypress": "^8.0.2",
"@testing-library/cypress": "^9.0.0",
"@testing-library/jest-dom": "^5.10.1",
"@testing-library/react": "^12.1.3",
"@testing-library/user-event": "^14.0.0",
+3
View File
@@ -244,6 +244,9 @@ const routes = (
<ScaffolderFieldExtensions>
<DelayingComponentFieldExtension />
</ScaffolderFieldExtensions>
<ScaffolderLayouts>
<TwoColumnLayout />
</ScaffolderLayouts>
</Route>
<Route path="/explore" element={<ExplorePage />} />
<Route
+1 -1
View File
@@ -125,7 +125,7 @@ export const httpRouterFactory: (
// @public (undocumented)
export interface HttpRouterFactoryOptions {
getPath(pluginId: string): string;
getPath?(pluginId: string): string;
}
// @public
@@ -27,7 +27,7 @@ export interface HttpRouterFactoryOptions {
/**
* A callback used to generate the path for each plugin, defaults to `/api/{pluginId}`.
*/
getPath(pluginId: string): string;
getPath?(pluginId: string): string;
}
/** @public */
@@ -21,7 +21,7 @@ import {
createServiceRef,
createSharedEnvironment,
} from '@backstage/backend-plugin-api';
import { mockConfigFactory } from '@backstage/backend-test-utils';
import { mockServices } from '@backstage/backend-test-utils';
import { createBackend } from './CreateBackend';
const fooServiceRef = createServiceRef<string>({ id: 'foo', scope: 'root' });
@@ -112,7 +112,7 @@ describe('createBackend', () => {
};
},
}),
mockConfigFactory({
mockServices.config.factory({
data: { root: 'root-env' },
}),
createServiceFactory({
@@ -74,10 +74,10 @@ export interface BackendModuleConfig {
*
* @remarks
*
* The `moduleId` should be equal to the module-specific prefix of the exported name, such
* that the full name is `moduleId + PluginId + "Module"`. For example, a GitHub entity
* The `moduleId` should be equal to the module-specific suffix of the exported name, such
* that the full name is `pluginId + "Module" + ModuleId`. For example, a GitHub entity
* provider module for the `catalog` plugin might have the module ID `'githubEntityProvider'`,
* and the full exported name would be `githubEntityProviderCatalogModule`.
* and the full exported name would be `catalogModuleGithubEntityProvider`.
*
* The `pluginId` should exactly match the `id` of the plugin that the module extends.
*/
+132 -7
View File
@@ -5,25 +5,150 @@
```ts
import { Backend } from '@backstage/backend-app-api';
import { BackendFeature } from '@backstage/backend-plugin-api';
import { CacheService } from '@backstage/backend-plugin-api';
import { ConfigReader } from '@backstage/config';
import { ConfigService } from '@backstage/backend-plugin-api';
import { DatabaseService } from '@backstage/backend-plugin-api';
import { ExtendedHttpServer } from '@backstage/backend-app-api';
import { ExtensionPoint } from '@backstage/backend-plugin-api';
import { HttpRouterFactoryOptions } from '@backstage/backend-app-api';
import { HttpRouterService } from '@backstage/backend-plugin-api';
import { IdentityService } from '@backstage/backend-plugin-api';
import { JsonObject } from '@backstage/types';
import { Knex } from 'knex';
import { LifecycleService } from '@backstage/backend-plugin-api';
import { LoggerService } from '@backstage/backend-plugin-api';
import { PermissionsService } from '@backstage/backend-plugin-api';
import { RootLifecycleService } from '@backstage/backend-plugin-api';
import { RootLoggerService } from '@backstage/backend-plugin-api';
import { SchedulerService } from '@backstage/backend-plugin-api';
import { ServiceFactory } from '@backstage/backend-plugin-api';
import { ServiceRef } from '@backstage/backend-plugin-api';
import { TokenManagerService } from '@backstage/backend-plugin-api';
import { UrlReaderService } from '@backstage/backend-plugin-api';
// @public (undocumented)
export function isDockerDisabledForTests(): boolean;
// @alpha (undocumented)
export const mockConfigFactory: (
options?:
| {
data?: JsonObject | undefined;
}
| undefined,
) => ServiceFactory<ConfigService>;
export namespace mockServices {
// (undocumented)
export namespace cache {
const // (undocumented)
ref: ServiceRef<CacheService, 'plugin'>;
const // (undocumented)
factory: () => ServiceFactory<CacheService>;
}
// (undocumented)
export function config(options?: config.Options): ConfigReader;
// (undocumented)
export namespace config {
// (undocumented)
export type Options = {
data?: JsonObject;
};
const // (undocumented)
ref: ServiceRef<ConfigService, 'root'>;
const // (undocumented)
factory: (options?: Options | undefined) => ServiceFactory<ConfigService>;
}
// (undocumented)
export namespace database {
const // (undocumented)
ref: ServiceRef<DatabaseService, 'plugin'>;
const // (undocumented)
factory: () => ServiceFactory<DatabaseService>;
}
// (undocumented)
export namespace httpRouter {
const // (undocumented)
ref: ServiceRef<HttpRouterService, 'plugin'>;
const // (undocumented)
factory: (
options?: HttpRouterFactoryOptions | undefined,
) => ServiceFactory<HttpRouterService>;
}
// (undocumented)
export function identity(): IdentityService;
// (undocumented)
export namespace identity {
const // (undocumented)
ref: ServiceRef<IdentityService, 'plugin'>;
const // (undocumented)
factory: () => ServiceFactory<IdentityService>;
}
// (undocumented)
export namespace lifecycle {
const // (undocumented)
ref: ServiceRef<LifecycleService, 'plugin'>;
const // (undocumented)
factory: () => ServiceFactory<LifecycleService>;
}
// (undocumented)
export namespace logger {
const // (undocumented)
ref: ServiceRef<LoggerService, 'plugin'>;
const // (undocumented)
factory: () => ServiceFactory<LoggerService>;
}
// (undocumented)
export namespace permissions {
const // (undocumented)
ref: ServiceRef<PermissionsService, 'plugin'>;
const // (undocumented)
factory: () => ServiceFactory<PermissionsService>;
}
// (undocumented)
export namespace rootLifecycle {
const // (undocumented)
ref: ServiceRef<RootLifecycleService, 'root'>;
const // (undocumented)
factory: () => ServiceFactory<RootLifecycleService>;
}
// (undocumented)
export function rootLogger(options?: rootLogger.Options): LoggerService;
// (undocumented)
export namespace rootLogger {
// (undocumented)
export type Options = {
levels:
| boolean
| {
error: boolean;
warn: boolean;
info: boolean;
debug: boolean;
};
};
const // (undocumented)
ref: ServiceRef<RootLoggerService, 'root'>;
const // (undocumented)
factory: (options?: Options | undefined) => ServiceFactory<LoggerService>;
}
// (undocumented)
export namespace scheduler {
const // (undocumented)
ref: ServiceRef<SchedulerService, 'plugin'>;
const // (undocumented)
factory: () => ServiceFactory<SchedulerService>;
}
// (undocumented)
export function tokenManager(): TokenManagerService;
// (undocumented)
export namespace tokenManager {
const // (undocumented)
ref: ServiceRef<TokenManagerService, 'plugin'>;
const // (undocumented)
factory: () => ServiceFactory<TokenManagerService>;
}
// (undocumented)
export namespace urlReader {
const // (undocumented)
ref: ServiceRef<UrlReaderService, 'plugin'>;
const // (undocumented)
factory: () => ServiceFactory<UrlReaderService>;
}
}
// @public
export function setupRequestMockHandlers(worker: {
@@ -1,33 +0,0 @@
/*
* Copyright 2022 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
coreServices,
createServiceFactory,
} from '@backstage/backend-plugin-api';
import { ConfigReader } from '@backstage/config';
import { JsonObject } from '@backstage/types';
/** @alpha */
export const mockConfigFactory = createServiceFactory(
(options?: { data?: JsonObject }) => ({
service: coreServices.config,
deps: {},
async factory() {
return new ConfigReader(options?.data, 'mock-config');
},
}),
);
@@ -1,40 +0,0 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { TokenManager } from '@backstage/backend-common';
import {
coreServices,
createServiceFactory,
} from '@backstage/backend-plugin-api';
class TokenManagerMock implements TokenManager {
async getToken(): Promise<{ token: string }> {
return { token: 'mock-token' };
}
async authenticate(token: string): Promise<void> {
if (token !== 'mock-token') {
throw new Error('Invalid token');
}
}
}
/** @alpha */
export const mockTokenManagerFactory = createServiceFactory({
service: coreServices.tokenManager,
deps: {},
async factory() {
return new TokenManagerMock();
},
});
@@ -15,4 +15,4 @@
*/
export * from './wiring';
export * from './implementations';
export * from './services';
@@ -13,17 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
coreServices,
createServiceFactory,
IdentityService,
} from '@backstage/backend-plugin-api';
import { IdentityService } from '@backstage/backend-plugin-api';
import {
IdentityApiGetIdentityRequest,
BackstageIdentityResponse,
} from '@backstage/plugin-auth-node';
class MockIdentityServiceImpl implements IdentityService {
export class MockIdentityService implements IdentityService {
getIdentity(
_options: IdentityApiGetIdentityRequest,
): Promise<BackstageIdentityResponse | undefined> {
@@ -37,11 +33,3 @@ class MockIdentityServiceImpl implements IdentityService {
});
}
}
export const mockIdentityFactory = createServiceFactory({
service: coreServices.identity,
deps: {},
async factory() {
return new MockIdentityServiceImpl();
},
});
@@ -15,21 +15,14 @@
*/
import {
coreServices,
createServiceFactory,
LoggerService,
LogMeta,
RootLoggerService,
} from '@backstage/backend-plugin-api';
import type { mockServices } from './mockServices';
interface MockLoggerOptions {
levels:
| boolean
| { error: boolean; warn: boolean; info: boolean; debug: boolean };
}
class MockLogger implements RootLoggerService {
#levels: Exclude<MockLoggerOptions['levels'], boolean>;
export class MockRootLoggerService implements RootLoggerService {
#levels: Exclude<mockServices.rootLogger.Options['levels'], boolean>;
#meta: LogMeta;
error(message: string, meta?: LogMeta | Error | undefined): void {
@@ -49,10 +42,13 @@ class MockLogger implements RootLoggerService {
}
child(meta: LogMeta): LoggerService {
return new MockLogger(this.#levels, { ...this.#meta, ...meta });
return new MockRootLoggerService(this.#levels, { ...this.#meta, ...meta });
}
constructor(levels: MockLoggerOptions['levels'], meta: LogMeta) {
constructor(
levels: mockServices.rootLogger.Options['levels'],
meta: LogMeta,
) {
if (typeof levels === 'boolean') {
this.#levels = {
error: levels,
@@ -79,12 +75,3 @@ class MockLogger implements RootLoggerService {
}
}
}
/** @alpha */
export const mockRootLoggerService = createServiceFactory({
service: coreServices.rootLogger,
deps: {},
async factory(_deps) {
return new MockLogger(false, {});
},
});
@@ -13,4 +13,4 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { mockConfigFactory } from './mockConfigService';
export { mockServices } from './mockServices';
@@ -0,0 +1,147 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
coreServices,
createServiceFactory,
IdentityService,
LoggerService,
ServiceFactory,
ServiceRef,
TokenManagerService,
} from '@backstage/backend-plugin-api';
import {
cacheFactory,
databaseFactory,
httpRouterFactory,
lifecycleFactory,
loggerFactory,
permissionsFactory,
rootLifecycleFactory,
schedulerFactory,
urlReaderFactory,
} from '@backstage/backend-app-api';
import { ConfigReader } from '@backstage/config';
import { JsonObject } from '@backstage/types';
import { MockIdentityService } from './MockIdentityService';
import { MockRootLoggerService } from './MockRootLoggerService';
function simpleFactory<TService, TOptions extends [options?: object] = []>(
ref: ServiceRef<TService>,
factory: (...options: TOptions) => TService,
): (...options: TOptions) => ServiceFactory<TService> {
return createServiceFactory((options: unknown) => ({
service: ref as ServiceRef<TService, any>,
deps: {},
async factory() {
return (factory as any)(options);
},
}));
}
/**
* @alpha
*/
export namespace mockServices {
export function config(options?: config.Options) {
return new ConfigReader(options?.data, 'mock-config');
}
export namespace config {
export type Options = { data?: JsonObject };
export const ref = coreServices.config;
export const factory = simpleFactory(ref, config);
}
export function rootLogger(options?: rootLogger.Options): LoggerService {
return new MockRootLoggerService(options?.levels ?? false, {});
}
export namespace rootLogger {
export type Options = {
levels:
| boolean
| { error: boolean; warn: boolean; info: boolean; debug: boolean };
};
export const ref = coreServices.rootLogger;
export const factory = simpleFactory(ref, rootLogger);
}
export function tokenManager(): TokenManagerService {
return {
async getToken(): Promise<{ token: string }> {
return { token: 'mock-token' };
},
async authenticate(token: string): Promise<void> {
if (token !== 'mock-token') {
throw new Error('Invalid token');
}
},
};
}
export namespace tokenManager {
export const ref = coreServices.tokenManager;
export const factory = simpleFactory(ref, tokenManager);
}
export function identity(): IdentityService {
return new MockIdentityService();
}
export namespace identity {
export const ref = coreServices.identity;
export const factory = simpleFactory(ref, identity);
}
// TODO(Rugvip): Not all core services have implementations available here yet.
// some may need a bit more refactoring for it to be simpler to
// re-implement functioning mock versions here.
export namespace cache {
export const ref = coreServices.cache;
export const factory = cacheFactory;
}
export namespace database {
export const ref = coreServices.database;
export const factory = databaseFactory;
}
export namespace httpRouter {
export const ref = coreServices.httpRouter;
export const factory = httpRouterFactory;
}
export namespace lifecycle {
export const ref = coreServices.lifecycle;
export const factory = lifecycleFactory;
}
export namespace logger {
export const ref = coreServices.logger;
export const factory = loggerFactory;
}
export namespace permissions {
export const ref = coreServices.permissions;
export const factory = permissionsFactory;
}
export namespace rootLifecycle {
export const ref = coreServices.rootLifecycle;
export const factory = rootLifecycleFactory;
}
export namespace scheduler {
export const ref = coreServices.scheduler;
export const factory = schedulerFactory;
}
export namespace urlReader {
export const ref = coreServices.urlReader;
export const factory = urlReaderFactory;
}
}
@@ -17,15 +17,6 @@
import {
Backend,
createSpecializedBackend,
lifecycleFactory,
rootLifecycleFactory,
loggerFactory,
cacheFactory,
permissionsFactory,
schedulerFactory,
urlReaderFactory,
databaseFactory,
httpRouterFactory,
MiddlewareFactory,
createHttpServer,
ExtendedHttpServer,
@@ -40,13 +31,9 @@ import {
ExtensionPoint,
coreServices,
} from '@backstage/backend-plugin-api';
import { mockConfigFactory } from '../implementations/mockConfigService';
import { mockRootLoggerService } from '../implementations/mockRootLoggerService';
import { mockTokenManagerFactory } from '../implementations/mockTokenManagerService';
import { mockServices } from '../services';
import { ConfigReader } from '@backstage/config';
import express from 'express';
import { mockIdentityFactory } from '../implementations/mockIdentityService';
/** @alpha */
export interface TestBackendOptions<
@@ -84,19 +71,19 @@ export interface TestBackend extends Backend {
}
const defaultServiceFactories = [
cacheFactory(),
databaseFactory(),
httpRouterFactory(),
lifecycleFactory(),
loggerFactory(),
mockConfigFactory(),
mockRootLoggerService(),
mockIdentityFactory(),
mockTokenManagerFactory(),
permissionsFactory(),
rootLifecycleFactory(),
schedulerFactory(),
urlReaderFactory(),
mockServices.cache.factory(),
mockServices.config.factory(),
mockServices.database.factory(),
mockServices.httpRouter.factory(),
mockServices.identity.factory(),
mockServices.lifecycle.factory(),
mockServices.logger.factory(),
mockServices.permissions.factory(),
mockServices.rootLifecycle.factory(),
mockServices.rootLogger.factory(),
mockServices.scheduler.factory(),
mockServices.tokenManager.factory(),
mockServices.urlReader.factory(),
];
const backendInstancesToCleanUp = new Array<Backend>();
+2 -2
View File
@@ -52,7 +52,6 @@ Options:
--awsRoleArn <AWS ROLE ARN>
--awsEndpoint <AWS ENDPOINT>
--awsS3ForcePathStyle
--awsBucketRootPath
--osCredentialId <OPENSTACK SWIFT APPLICATION CREDENTIAL ID>
--osSecret <OPENSTACK SWIFT APPLICATION CREDENTIAL SECRET>
--osAuthUrl <OPENSTACK SWIFT AUTHURL>
@@ -79,11 +78,12 @@ Options:
--awsEndpoint <AWS ENDPOINT>
--awsS3sse <AWS SSE>
--awsS3ForcePathStyle
--awsBucketRootPath <AWS BUCKET ROOT PATH>
--osCredentialId <OPENSTACK SWIFT APPLICATION CREDENTIAL ID>
--osSecret <OPENSTACK SWIFT APPLICATION CREDENTIAL SECRET>
--osAuthUrl <OPENSTACK SWIFT AUTHURL>
--osSwiftUrl <OPENSTACK SWIFT SWIFTURL>
--gcsBucketRootPath
--gcsBucketRootPath <GCS BUCKET ROOT PATH>
--directory <PATH>
-h, --help
```
+5 -5
View File
@@ -101,10 +101,6 @@ export function registerCommands(program: Command) {
'--awsS3ForcePathStyle',
'Optional AWS S3 option to force path style.',
)
.option(
'--awsBucketRootPath',
'Optional sub-directory to store files in Amazon S3',
)
.option(
'--osCredentialId <OPENSTACK SWIFT APPLICATION CREDENTIAL ID>',
'(Required for OpenStack) specify when --publisher-type openStackSwift',
@@ -177,6 +173,10 @@ export function registerCommands(program: Command) {
'--awsS3ForcePathStyle',
'Optional AWS S3 option to force path style.',
)
.option(
'--awsBucketRootPath <AWS BUCKET ROOT PATH>',
'Optional sub-directory to store files in Amazon S3',
)
.option(
'--osCredentialId <OPENSTACK SWIFT APPLICATION CREDENTIAL ID>',
'(Required for OpenStack) specify when --publisher-type openStackSwift',
@@ -194,7 +194,7 @@ export function registerCommands(program: Command) {
'(Required for OpenStack) specify when --publisher-type openStackSwift',
)
.option(
'--gcsBucketRootPath',
'--gcsBucketRootPath <GCS BUCKET ROOT PATH>',
'Optional sub-directory to store files in Google cloud storage',
)
.option(