chore(catalog-backend): rename locationprocessor to catalogprocessor

This commit is contained in:
Fredrik Adelöw
2020-10-15 15:48:03 +02:00
parent 1797d4924c
commit a5cb46bac9
24 changed files with 147 additions and 140 deletions
+10
View File
@@ -0,0 +1,10 @@
---
'@backstage/plugin-catalog-backend': minor
---
Renamed the `LocationProcessor` class to `CatalogProcessor`.
Likewise, renamed `LocationProcessorResult`, `LocationProcessorLocationResult`,
`LocationProcessorDataResult`, `LocationProcessorEntityResult`,
`LocationProcessorErrorResult`, and `LocationProcessorEmit` to their `Catalog*`
counterparts.
@@ -25,13 +25,13 @@ import { Logger } from 'winston';
import { CatalogRulesEnforcer } from './CatalogRules';
import * as result from './processors/results';
import {
LocationProcessor,
LocationProcessorDataResult,
LocationProcessorEmit,
LocationProcessorEntityResult,
LocationProcessorErrorResult,
LocationProcessorLocationResult,
LocationProcessorResult,
CatalogProcessor,
CatalogProcessorDataResult,
CatalogProcessorEmit,
CatalogProcessorEntityResult,
CatalogProcessorErrorResult,
CatalogProcessorLocationResult,
CatalogProcessorResult,
} from './processors/types';
import { LocationReader, ReadLocationResult } from './types';
@@ -42,7 +42,7 @@ type Options = {
reader: UrlReader;
logger: Logger;
config: Config;
processors: LocationProcessor[];
processors: CatalogProcessor[];
rulesEnforcer: CatalogRulesEnforcer;
};
@@ -60,11 +60,11 @@ export class LocationReaders implements LocationReader {
const { rulesEnforcer, logger } = this.options;
const output: ReadLocationResult = { entities: [], errors: [] };
let items: LocationProcessorResult[] = [result.location(location, false)];
let items: CatalogProcessorResult[] = [result.location(location, false)];
for (let depth = 0; depth < MAX_DEPTH; ++depth) {
const newItems: LocationProcessorResult[] = [];
const emit: LocationProcessorEmit = i => newItems.push(i);
const newItems: CatalogProcessorResult[] = [];
const emit: CatalogProcessorEmit = i => newItems.push(i);
for (const item of items) {
if (item.type === 'location') {
@@ -109,8 +109,8 @@ export class LocationReaders implements LocationReader {
}
private async handleLocation(
item: LocationProcessorLocationResult,
emit: LocationProcessorEmit,
item: CatalogProcessorLocationResult,
emit: CatalogProcessorEmit,
) {
const { processors, logger } = this.options;
@@ -136,8 +136,8 @@ export class LocationReaders implements LocationReader {
}
private async handleData(
item: LocationProcessorDataResult,
emit: LocationProcessorEmit,
item: CatalogProcessorDataResult,
emit: CatalogProcessorEmit,
) {
const { processors, logger } = this.options;
@@ -160,8 +160,8 @@ export class LocationReaders implements LocationReader {
}
private async handleEntity(
item: LocationProcessorEntityResult,
emit: LocationProcessorEmit,
item: CatalogProcessorEntityResult,
emit: CatalogProcessorEmit,
): Promise<Entity> {
const { processors, logger } = this.options;
@@ -189,8 +189,8 @@ export class LocationReaders implements LocationReader {
}
private async handleError(
item: LocationProcessorErrorResult,
emit: LocationProcessorEmit,
item: CatalogProcessorErrorResult,
emit: CatalogProcessorEmit,
) {
const { processors, logger } = this.options;
@@ -16,9 +16,9 @@
import { Entity, LocationSpec } from '@backstage/catalog-model';
import lodash from 'lodash';
import { LocationProcessor } from './types';
import { CatalogProcessor } from './types';
export class AnnotateLocationEntityProcessor implements LocationProcessor {
export class AnnotateLocationEntityProcessor implements CatalogProcessor {
async processEntity(entity: Entity, location: LocationSpec): Promise<Entity> {
return lodash.merge(
{
@@ -15,17 +15,17 @@
*/
import { LocationSpec } from '@backstage/catalog-model';
import fetch, { RequestInit, HeadersInit } from 'node-fetch';
import * as result from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
import { Config } from '@backstage/config';
import fetch, { HeadersInit, RequestInit } from 'node-fetch';
import * as result from './results';
import { CatalogProcessor, CatalogProcessorEmit } from './types';
// ***********************************************************************
// * NOTE: This has been replaced by packages/backend-common/src/reading *
// * Don't implement new functionality here as this file will be removed *
// ***********************************************************************
export class AzureApiReaderProcessor implements LocationProcessor {
export class AzureApiReaderProcessor implements CatalogProcessor {
private privateToken: string;
constructor(config: Config) {
@@ -54,7 +54,7 @@ export class AzureApiReaderProcessor implements LocationProcessor {
async readLocation(
location: LocationSpec,
optional: boolean,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<boolean> {
if (location.type !== 'azure/api') {
return false;
@@ -15,17 +15,17 @@
*/
import { LocationSpec } from '@backstage/catalog-model';
import fetch, { RequestInit, HeadersInit } from 'node-fetch';
import * as result from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
import { Config } from '@backstage/config';
import fetch, { HeadersInit, RequestInit } from 'node-fetch';
import * as result from './results';
import { CatalogProcessor, CatalogProcessorEmit } from './types';
// ***********************************************************************
// * NOTE: This has been replaced by packages/backend-common/src/reading *
// * Don't implement new functionality here as this file will be removed *
// ***********************************************************************
export class BitbucketApiReaderProcessor implements LocationProcessor {
export class BitbucketApiReaderProcessor implements CatalogProcessor {
private username: string;
private password: string;
@@ -58,7 +58,7 @@ export class BitbucketApiReaderProcessor implements LocationProcessor {
async readLocation(
location: LocationSpec,
optional: boolean,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<boolean> {
if (location.type !== 'bitbucket/api') {
return false;
@@ -16,14 +16,13 @@
import { UrlReader } from '@backstage/backend-common';
import { Entity, LocationSpec } from '@backstage/catalog-model';
import { LocationProcessor } from './types';
import * as codeowners from 'codeowners-utils';
import { CodeOwnersEntry } from 'codeowners-utils';
import parseGitUri from 'git-url-parse';
import { filter, head, get, pipe, reverse } from 'lodash/fp';
// NOTE: This can be removed when ES2021 is implemented
import 'core-js/features/promise';
import parseGitUri from 'git-url-parse';
import { filter, get, head, pipe, reverse } from 'lodash/fp';
import { CatalogProcessor } from './types';
const ALLOWED_LOCATION_TYPES = [
'azure/api',
@@ -38,7 +37,7 @@ type Options = {
reader: UrlReader;
};
export class CodeOwnersProcessor implements LocationProcessor {
export class CodeOwnersProcessor implements CatalogProcessor {
constructor(private readonly options: Options) {}
async processEntity(entity: Entity, location: LocationSpec): Promise<Entity> {
@@ -15,9 +15,9 @@
*/
import { Entity, EntityPolicy } from '@backstage/catalog-model';
import { LocationProcessor } from './types';
import { CatalogProcessor } from './types';
export class EntityPolicyProcessor implements LocationProcessor {
export class EntityPolicyProcessor implements CatalogProcessor {
private readonly policy: EntityPolicy;
constructor(policy: EntityPolicy) {
@@ -17,13 +17,13 @@
import { LocationSpec } from '@backstage/catalog-model';
import fs from 'fs-extra';
import * as result from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
import { CatalogProcessor, CatalogProcessorEmit } from './types';
export class FileReaderProcessor implements LocationProcessor {
export class FileReaderProcessor implements CatalogProcessor {
async readLocation(
location: LocationSpec,
optional: boolean,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<boolean> {
if (location.type !== 'file') {
return false;
@@ -19,14 +19,14 @@ import { Config } from '@backstage/config';
import { graphql } from '@octokit/graphql';
import { Logger } from 'winston';
import * as results from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
import { CatalogProcessor, CatalogProcessorEmit } from './types';
import { getOrganizationTeams, getOrganizationUsers } from './util/github';
import { buildOrgHierarchy } from './util/org';
/**
* Extracts teams and users out of a GitHub org.
*/
export class GithubOrgReaderProcessor implements LocationProcessor {
export class GithubOrgReaderProcessor implements CatalogProcessor {
private readonly providers: ProviderConfig[];
private readonly logger: Logger;
@@ -45,7 +45,7 @@ export class GithubOrgReaderProcessor implements LocationProcessor {
async readLocation(
location: LocationSpec,
_optional: boolean,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<boolean> {
if (location.type !== 'github-org') {
return false;
@@ -20,7 +20,7 @@ import parseGitUri from 'git-url-parse';
import fetch, { HeadersInit, RequestInit } from 'node-fetch';
import { Logger } from 'winston';
import * as result from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
import { CatalogProcessor, CatalogProcessorEmit } from './types';
// ***********************************************************************
// * NOTE: This has been replaced by packages/backend-common/src/reading *
@@ -210,7 +210,7 @@ export function readConfig(config: Config, logger: Logger): ProviderConfig[] {
* A processor that adds the ability to read files from GitHub v3 APIs, such as
* the one exposed by GitHub itself.
*/
export class GithubReaderProcessor implements LocationProcessor {
export class GithubReaderProcessor implements CatalogProcessor {
private providers: ProviderConfig[];
static fromConfig(config: Config, logger: Logger) {
@@ -224,7 +224,7 @@ export class GithubReaderProcessor implements LocationProcessor {
async readLocation(
location: LocationSpec,
optional: boolean,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<boolean> {
// The github/api type is for backward compatibility
if (location.type !== 'github' && location.type !== 'github/api') {
@@ -15,17 +15,17 @@
*/
import { LocationSpec } from '@backstage/catalog-model';
import fetch, { RequestInit, HeadersInit } from 'node-fetch';
import * as result from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
import { Config } from '@backstage/config';
import fetch, { HeadersInit, RequestInit } from 'node-fetch';
import * as result from './results';
import { CatalogProcessor, CatalogProcessorEmit } from './types';
// ***********************************************************************
// * NOTE: This has been replaced by packages/backend-common/src/reading *
// * Don't implement new functionality here as this file will be removed *
// ***********************************************************************
export class GitlabApiReaderProcessor implements LocationProcessor {
export class GitlabApiReaderProcessor implements CatalogProcessor {
private privateToken: string;
constructor(config: Config) {
@@ -50,7 +50,7 @@ export class GitlabApiReaderProcessor implements LocationProcessor {
async readLocation(
location: LocationSpec,
optional: boolean,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<boolean> {
if (location.type !== 'gitlab/api') {
return false;
@@ -17,18 +17,18 @@
import { LocationSpec } from '@backstage/catalog-model';
import fetch from 'node-fetch';
import * as result from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
import { CatalogProcessor, CatalogProcessorEmit } from './types';
// ***********************************************************************
// * NOTE: This has been replaced by packages/backend-common/src/reading *
// * Don't implement new functionality here as this file will be removed *
// ***********************************************************************
export class GitlabReaderProcessor implements LocationProcessor {
export class GitlabReaderProcessor implements CatalogProcessor {
async readLocation(
location: LocationSpec,
optional: boolean,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<boolean> {
if (location.type !== 'gitlab') {
return false;
@@ -24,12 +24,12 @@ import {
readLdapOrg,
} from './ldap';
import * as results from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
import { CatalogProcessor, CatalogProcessorEmit } from './types';
/**
* Extracts teams and users out of an LDAP server.
*/
export class LdapOrgReaderProcessor implements LocationProcessor {
export class LdapOrgReaderProcessor implements CatalogProcessor {
private readonly providers: LdapProviderConfig[];
private readonly logger: Logger;
@@ -49,7 +49,7 @@ export class LdapOrgReaderProcessor implements LocationProcessor {
async readLocation(
location: LocationSpec,
_optional: boolean,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<boolean> {
if (location.type !== 'ldap-org') {
return false;
@@ -16,13 +16,13 @@
import { Entity, LocationEntity, LocationSpec } from '@backstage/catalog-model';
import * as result from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
import { CatalogProcessor, CatalogProcessorEmit } from './types';
export class LocationRefProcessor implements LocationProcessor {
export class LocationRefProcessor implements CatalogProcessor {
async processEntity(
entity: Entity,
_location: LocationSpec,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<Entity> {
if (entity.kind === 'Location') {
const location = entity as LocationEntity;
@@ -18,7 +18,7 @@ import { UrlReader } from '@backstage/backend-common';
import { Entity, LocationSpec } from '@backstage/catalog-model';
import { JsonValue } from '@backstage/config';
import yaml from 'yaml';
import { LocationProcessor } from './types';
import { CatalogProcessor } from './types';
export type ResolverRead = (url: string) => Promise<Buffer>;
@@ -42,7 +42,7 @@ type Options = {
* Traverses raw entity JSON looking for occurrences of $-prefixed placeholders
* that it then fills in with actual data.
*/
export class PlaceholderProcessor implements LocationProcessor {
export class PlaceholderProcessor implements CatalogProcessor {
constructor(private readonly options: Options) {}
async processEntity(entity: Entity, location: LocationSpec): Promise<Entity> {
@@ -15,9 +15,9 @@
*/
import { LocationSpec } from '@backstage/catalog-model';
import * as result from './results';
import { Config } from '@backstage/config';
import { LocationProcessorEmit } from './types';
import * as result from './results';
import { CatalogProcessorEmit } from './types';
export class StaticLocationProcessor implements StaticLocationProcessor {
static fromConfig(config: Config): StaticLocationProcessor {
@@ -38,7 +38,7 @@ export class StaticLocationProcessor implements StaticLocationProcessor {
async readLocation(
location: LocationSpec,
_optional: boolean,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<boolean> {
if (location.type !== 'bootstrap') {
return false;
@@ -14,16 +14,16 @@
* limitations under the License.
*/
import { UrlReaderProcessor } from './UrlReaderProcessor';
import {
LocationProcessorDataResult,
LocationProcessorResult,
LocationProcessorErrorResult,
} from './types';
import { setupServer } from 'msw/node';
import { rest } from 'msw';
import { getVoidLogger, UrlReaders } from '@backstage/backend-common';
import { ConfigReader } from '@backstage/config';
import { rest } from 'msw';
import { setupServer } from 'msw/node';
import {
CatalogProcessorDataResult,
CatalogProcessorErrorResult,
CatalogProcessorResult,
} from './types';
import { UrlReaderProcessor } from './UrlReaderProcessor';
describe('UrlReaderProcessor', () => {
const mockApiOrigin = 'http://localhost:23000';
@@ -48,9 +48,9 @@ describe('UrlReaderProcessor', () => {
),
);
const generated = (await new Promise<LocationProcessorResult>(emit =>
const generated = (await new Promise<CatalogProcessorResult>(emit =>
processor.readLocation(spec, false, emit),
)) as LocationProcessorDataResult;
)) as CatalogProcessorDataResult;
expect(generated.type).toBe('data');
expect(generated.location).toBe(spec);
@@ -72,9 +72,9 @@ describe('UrlReaderProcessor', () => {
}),
);
const generated = (await new Promise<LocationProcessorResult>(emit =>
const generated = (await new Promise<CatalogProcessorResult>(emit =>
processor.readLocation(spec, false, emit),
)) as LocationProcessorErrorResult;
)) as CatalogProcessorErrorResult;
expect(generated.type).toBe('error');
expect(generated.location).toBe(spec);
@@ -14,11 +14,11 @@
* limitations under the License.
*/
import { Logger } from 'winston';
import { UrlReader } from '@backstage/backend-common';
import { LocationSpec } from '@backstage/catalog-model';
import { Logger } from 'winston';
import * as result from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
import { CatalogProcessor, CatalogProcessorEmit } from './types';
// TODO(Rugvip): Added for backwards compatibility when moving to UrlReader, this
// can be removed in a bit
@@ -35,13 +35,13 @@ type Options = {
logger: Logger;
};
export class UrlReaderProcessor implements LocationProcessor {
export class UrlReaderProcessor implements CatalogProcessor {
constructor(private readonly options: Options) {}
async readLocation(
location: LocationSpec,
optional: boolean,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<boolean> {
if (deprecatedTypes.includes(location.type)) {
// TODO(Rugvip): Let's not enable this warning yet, as we want to move over the example YAMLs
@@ -14,14 +14,14 @@
* limitations under the License.
*/
import { YamlProcessor } from './YamlProcessor';
import { Entity } from '@backstage/catalog-model';
import yaml from 'yaml';
import { TextEncoder } from 'util';
import yaml from 'yaml';
import {
LocationProcessorEntityResult,
LocationProcessorErrorResult,
CatalogProcessorEntityResult,
CatalogProcessorErrorResult,
} from './types';
import { YamlProcessor } from './YamlProcessor';
describe('YamlProcessor', () => {
const processor = new YamlProcessor();
@@ -82,7 +82,7 @@ describe('YamlProcessor', () => {
expect(await processor.parseData(buffer, locationSpec, emit)).toBe(true);
const e = emit.mock.calls[0][0] as LocationProcessorEntityResult;
const e = emit.mock.calls[0][0] as CatalogProcessorEntityResult;
expect(e.type).toBe('entity');
expect(e.location).toBe(locationSpec);
expect(e.entity).toEqual(entity);
@@ -114,12 +114,12 @@ describe('YamlProcessor', () => {
expect(await processor.parseData(buffer, locationSpec, emit)).toBe(true);
const eComponent = emit.mock.calls[0][0] as LocationProcessorEntityResult;
const eComponent = emit.mock.calls[0][0] as CatalogProcessorEntityResult;
expect(eComponent.type).toBe('entity');
expect(eComponent.location).toBe(locationSpec);
expect(eComponent.entity).toEqual(entityComponent);
const eApi = emit.mock.calls[1][0] as LocationProcessorEntityResult;
const eApi = emit.mock.calls[1][0] as CatalogProcessorEntityResult;
expect(eApi.type).toBe('entity');
expect(eApi.location).toBe(locationSpec);
expect(eApi.entity).toEqual(entityApi);
@@ -131,7 +131,7 @@ describe('YamlProcessor', () => {
expect(await processor.parseData(buffer, locationSpec, emit)).toBe(true);
const e = emit.mock.calls[0][0] as LocationProcessorErrorResult;
const e = emit.mock.calls[0][0] as CatalogProcessorErrorResult;
expect(e.error.message).toMatch(/^YAML error, /);
expect(e.type).toBe('error');
expect(e.location).toBe(locationSpec);
@@ -143,7 +143,7 @@ describe('YamlProcessor', () => {
expect(await processor.parseData(buffer, locationSpec, emit)).toBe(true);
const e = emit.mock.calls[0][0] as LocationProcessorErrorResult;
const e = emit.mock.calls[0][0] as CatalogProcessorErrorResult;
expect(e.error.message).toMatch(/^Expected object at root, got /);
expect(e.type).toBe('error');
expect(e.location).toBe(locationSpec);
@@ -18,18 +18,18 @@ import { Entity, LocationSpec } from '@backstage/catalog-model';
import lodash from 'lodash';
import yaml from 'yaml';
import * as result from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
import { CatalogProcessor, CatalogProcessorEmit } from './types';
/**
* Handles incoming raw data buffers, and if they have a yaml extension,
* attempts to parse them into structured data and emitting them as un-
* validated entities.
*/
export class YamlProcessor implements LocationProcessor {
export class YamlProcessor implements CatalogProcessor {
async parseData(
data: Buffer,
location: LocationSpec,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<boolean> {
if (!location.target.match(/\.ya?ml/)) {
return false;
@@ -16,12 +16,12 @@
import { InputError, NotFoundError } from '@backstage/backend-common';
import { Entity, LocationSpec } from '@backstage/catalog-model';
import { LocationProcessorResult } from './types';
import { CatalogProcessorResult } from './types';
export function notFoundError(
atLocation: LocationSpec,
message: string,
): LocationProcessorResult {
): CatalogProcessorResult {
return {
type: 'error',
location: atLocation,
@@ -32,7 +32,7 @@ export function notFoundError(
export function inputError(
atLocation: LocationSpec,
message: string,
): LocationProcessorResult {
): CatalogProcessorResult {
return {
type: 'error',
location: atLocation,
@@ -43,27 +43,27 @@ export function inputError(
export function generalError(
atLocation: LocationSpec,
message: string,
): LocationProcessorResult {
): CatalogProcessorResult {
return { type: 'error', location: atLocation, error: new Error(message) };
}
export function data(
atLocation: LocationSpec,
newData: Buffer,
): LocationProcessorResult {
): CatalogProcessorResult {
return { type: 'data', location: atLocation, data: newData };
}
export function location(
newLocation: LocationSpec,
optional: boolean,
): LocationProcessorResult {
): CatalogProcessorResult {
return { type: 'location', location: newLocation, optional };
}
export function entity(
atLocation: LocationSpec,
newEntity: Entity,
): LocationProcessorResult {
): CatalogProcessorResult {
return { type: 'entity', location: atLocation, entity: newEntity };
}
@@ -16,7 +16,7 @@
import { Entity, LocationSpec } from '@backstage/catalog-model';
export type LocationProcessor = {
export type CatalogProcessor = {
/**
* Reads the contents of a location.
*
@@ -28,7 +28,7 @@ export type LocationProcessor = {
readLocation?(
location: LocationSpec,
optional: boolean,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<boolean>;
/**
@@ -42,7 +42,7 @@ export type LocationProcessor = {
parseData?(
data: Buffer,
location: LocationSpec,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<boolean>;
/**
@@ -57,7 +57,7 @@ export type LocationProcessor = {
processEntity?(
entity: Entity,
location: LocationSpec,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<Entity>;
/**
@@ -71,40 +71,38 @@ export type LocationProcessor = {
handleError?(
error: Error,
location: LocationSpec,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
): Promise<void>;
};
export type LocationProcessorEmit = (
generated: LocationProcessorResult,
) => void;
export type CatalogProcessorEmit = (generated: CatalogProcessorResult) => void;
export type LocationProcessorLocationResult = {
export type CatalogProcessorLocationResult = {
type: 'location';
location: LocationSpec;
optional: boolean;
};
export type LocationProcessorDataResult = {
export type CatalogProcessorDataResult = {
type: 'data';
data: Buffer;
location: LocationSpec;
};
export type LocationProcessorEntityResult = {
export type CatalogProcessorEntityResult = {
type: 'entity';
entity: Entity;
location: LocationSpec;
};
export type LocationProcessorErrorResult = {
export type CatalogProcessorErrorResult = {
type: 'error';
error: Error;
location: LocationSpec;
};
export type LocationProcessorResult =
| LocationProcessorLocationResult
| LocationProcessorDataResult
| LocationProcessorEntityResult
| LocationProcessorErrorResult;
export type CatalogProcessorResult =
| CatalogProcessorLocationResult
| CatalogProcessorDataResult
| CatalogProcessorEntityResult
| CatalogProcessorErrorResult;
@@ -18,9 +18,9 @@ import { getVoidLogger, UrlReader } from '@backstage/backend-common';
import { Entity, LocationSpec } from '@backstage/catalog-model';
import { ConfigReader } from '@backstage/config';
import { DatabaseManager } from '../database';
import { LocationProcessorEmit } from '../ingestion';
import { CatalogBuilder, CatalogEnvironment } from './CatalogBuilder';
import { CatalogProcessorEmit } from '../ingestion';
import * as result from '../ingestion/processors/results';
import { CatalogBuilder, CatalogEnvironment } from './CatalogBuilder';
describe('CatalogBuilder', () => {
const db = DatabaseManager.createTestDatabaseConnection();
@@ -54,7 +54,7 @@ describe('CatalogBuilder', () => {
async readLocation(
location: LocationSpec,
_optional: boolean,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
) {
expect(location.type).toBe('test');
emit(result.data(location, await reader.read('ignored')));
@@ -67,7 +67,7 @@ describe('CatalogBuilder', () => {
async parseData(
data: Buffer,
location: LocationSpec,
emit: LocationProcessorEmit,
emit: CatalogProcessorEmit,
) {
expect(data.toString()).toEqual('junk');
emit(
@@ -46,6 +46,7 @@ import {
AnnotateLocationEntityProcessor,
AzureApiReaderProcessor,
BitbucketApiReaderProcessor,
CatalogProcessor,
CodeOwnersProcessor,
EntityPolicyProcessor,
FileReaderProcessor,
@@ -55,7 +56,6 @@ import {
GitlabReaderProcessor,
HigherOrderOperation,
HigherOrderOperations,
LocationProcessor,
LocationReaders,
LocationRefProcessor,
PlaceholderProcessor,
@@ -121,13 +121,13 @@ export class CatalogBuilder {
private entityPoliciesReplace: boolean;
private entityKinds: EntityPolicy[];
private entityKindsReplace: boolean;
private readerProcessors: LocationProcessor[];
private readerProcessors: CatalogProcessor[];
private readerProcessorsReplace: boolean;
private parserProcessors: LocationProcessor[];
private parserProcessors: CatalogProcessor[];
private parserProcessorsReplace: boolean;
private preProcessors: LocationProcessor[];
private preProcessors: CatalogProcessor[];
private preProcessorsReplace: boolean;
private postProcessors: LocationProcessor[];
private postProcessors: CatalogProcessor[];
private postProcessorsReplace: boolean;
private placeholderResolvers: Record<string, PlaceholderResolver>;
private fieldFormatValidators: Partial<Validators>;
@@ -219,7 +219,7 @@ export class CatalogBuilder {
*
* @param processors One or more processors
*/
addReaderProcessor(...processors: LocationProcessor[]): CatalogBuilder {
addReaderProcessor(...processors: CatalogProcessor[]): CatalogBuilder {
this.readerProcessors.push(...processors);
return this;
}
@@ -234,7 +234,7 @@ export class CatalogBuilder {
*
* @param processors One or more processors
*/
replaceReaderProcessors(processors: LocationProcessor[]): CatalogBuilder {
replaceReaderProcessors(processors: CatalogProcessor[]): CatalogBuilder {
this.readerProcessors = [...processors];
this.readerProcessorsReplace = true;
return this;
@@ -247,7 +247,7 @@ export class CatalogBuilder {
*
* @param processors One or more processors
*/
addParserProcessor(...processors: LocationProcessor[]): CatalogBuilder {
addParserProcessor(...processors: CatalogProcessor[]): CatalogBuilder {
this.parserProcessors.push(...processors);
return this;
}
@@ -262,7 +262,7 @@ export class CatalogBuilder {
*
* @param processors One or more processors
*/
replaceParserProcessors(processors: LocationProcessor[]): CatalogBuilder {
replaceParserProcessors(processors: CatalogProcessor[]): CatalogBuilder {
this.parserProcessors = [...processors];
this.parserProcessorsReplace = true;
return this;
@@ -274,7 +274,7 @@ export class CatalogBuilder {
*
* @param processors One or more processors
*/
addPreProcessor(...processors: LocationProcessor[]): CatalogBuilder {
addPreProcessor(...processors: CatalogProcessor[]): CatalogBuilder {
this.preProcessors.push(...processors);
return this;
}
@@ -288,7 +288,7 @@ export class CatalogBuilder {
*
* @param processors One or more processors
*/
replacePreProcessors(processors: LocationProcessor[]): CatalogBuilder {
replacePreProcessors(processors: CatalogProcessor[]): CatalogBuilder {
this.preProcessors = [...processors];
this.preProcessorsReplace = true;
return this;
@@ -300,7 +300,7 @@ export class CatalogBuilder {
*
* @param processors One or more processors
*/
addPostProcessor(...processors: LocationProcessor[]): CatalogBuilder {
addPostProcessor(...processors: CatalogProcessor[]): CatalogBuilder {
this.postProcessors.push(...processors);
return this;
}
@@ -314,7 +314,7 @@ export class CatalogBuilder {
*
* @param processors One or more processors
*/
replacePostProcessors(processors: LocationProcessor[]): CatalogBuilder {
replacePostProcessors(processors: CatalogProcessor[]): CatalogBuilder {
this.postProcessors = [...processors];
this.postProcessorsReplace = true;
return this;
@@ -418,7 +418,7 @@ export class CatalogBuilder {
]);
}
private buildProcessors(entityPolicy: EntityPolicy): LocationProcessor[] {
private buildProcessors(entityPolicy: EntityPolicy): CatalogProcessor[] {
const { config, reader } = this.env;
const placeholderResolvers = lodash.merge(
@@ -441,7 +441,7 @@ export class CatalogBuilder {
];
}
private buildReaderProcessors(): LocationProcessor[] {
private buildReaderProcessors(): CatalogProcessor[] {
const { config, logger, reader } = this.env;
if (this.readerProcessorsReplace) {
@@ -491,7 +491,7 @@ export class CatalogBuilder {
];
}
private buildParserProcessors(): LocationProcessor[] {
private buildParserProcessors(): CatalogProcessor[] {
if (this.parserProcessorsReplace) {
return this.parserProcessors;
}
@@ -499,7 +499,7 @@ export class CatalogBuilder {
return [new YamlProcessor(), ...this.parserProcessors];
}
private buildPreProcessors(): LocationProcessor[] {
private buildPreProcessors(): CatalogProcessor[] {
const { reader } = this.env;
if (this.preProcessorsReplace) {
@@ -509,7 +509,7 @@ export class CatalogBuilder {
return [new CodeOwnersProcessor({ reader }), ...this.preProcessors];
}
private buildPostProcessors(): LocationProcessor[] {
private buildPostProcessors(): CatalogProcessor[] {
if (this.postProcessorsReplace) {
return this.postProcessors;
}