From ea96a0206429e6be499b750eba2e1704c0f5001e Mon Sep 17 00:00:00 2001 From: Justin De Burgo Date: Tue, 15 Nov 2022 16:32:05 -0600 Subject: [PATCH] using sources instead of owners Signed-off-by: Lucas De Souza --- app-config.yaml | 3 --- .../src/ingestion/CatalogRules.ts | 19 ++++++++++--------- .../ImportStepper/ImportStepper.tsx | 2 -- .../src/components/ImportStepper/defaults.tsx | 3 +-- .../StepInitAnalyzeUrl/StepInitAnalyzeUrl.tsx | 5 +---- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/app-config.yaml b/app-config.yaml index 3eb8e7e01c..dd72051189 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -218,9 +218,6 @@ catalog: - System - Domain - Location - - owners: - - Spotify - - Backstage processors: ldapOrg: diff --git a/plugins/catalog-backend/src/ingestion/CatalogRules.ts b/plugins/catalog-backend/src/ingestion/CatalogRules.ts index d25e936d1a..a48d29add6 100644 --- a/plugins/catalog-backend/src/ingestion/CatalogRules.ts +++ b/plugins/catalog-backend/src/ingestion/CatalogRules.ts @@ -32,8 +32,8 @@ export type CatalogRule = { target?: string; type: string; }>; - owners?: Array<{ - owner: string + sources?: Array<{ + source: string }>; }; @@ -58,6 +58,7 @@ export class DefaultCatalogRulesEnforcer implements CatalogRulesEnforcer { static readonly defaultRules: CatalogRule[] = [ { allow: ['Component', 'API', 'Location'].map(kind => ({ kind })), + sources: [], }, ]; @@ -97,7 +98,7 @@ export class DefaultCatalogRulesEnforcer implements CatalogRulesEnforcer { if (config.has('catalog.rules')) { const globalRules = config.getConfigArray('catalog.rules').map(sub => ({ allow: sub.getStringArray('allow').map(kind => ({ kind })), - owners: sub.getStringArray('owners').map(kind => ({ kind })), + sources: sub.getStringArray('sources').map(source => ({ source })), })); rules.push(...globalRules); } else { @@ -138,7 +139,7 @@ export class DefaultCatalogRulesEnforcer implements CatalogRulesEnforcer { continue; } - if (!this.matchOwners(entity, rule.owners)) { + if (!this.matchSources(location, rule.sources)) { return false; } @@ -187,15 +188,15 @@ export class DefaultCatalogRulesEnforcer implements CatalogRulesEnforcer { return false; } - private matchOwners(entity: Entity, matchers?: { owner: string }[]): boolean { - if (!matchers) { + private matchSources(location: LocationSpec, matchers?: { source: string }[]): boolean { + if (!matchers || matchers.length === 0) { return true; } - const filteredRegex = new RegExp(`^http[s]?://${`(?:${matchers.map((filter, i) => i === 0 ? filter.owner : `|${filter.owner}`)})`}`); + const filteredRegex = new RegExp(`^http[s]?://${`(?:${matchers.map((filter, i) => i === 0 ? filter.source : `|${filter.source}`)})`}`); - if ( entity?.metadata.links && entity?.metadata?.links?.length > 0) { - return filteredRegex.test(entity?.metadata?.links[0].url); + if ( location.target && location.target.length > 0) { + return filteredRegex.test(location.target); } return false; } diff --git a/plugins/catalog-import/src/components/ImportStepper/ImportStepper.tsx b/plugins/catalog-import/src/components/ImportStepper/ImportStepper.tsx index 7724a3c7d1..7352741326 100644 --- a/plugins/catalog-import/src/components/ImportStepper/ImportStepper.tsx +++ b/plugins/catalog-import/src/components/ImportStepper/ImportStepper.tsx @@ -59,7 +59,6 @@ export const ImportStepper = (props: ImportStepperProps) => { initialUrl, generateStepper = defaultGenerateStepper, variant, - filters = [], } = props; const catalogImportApi = useApi(catalogImportApiRef); @@ -91,7 +90,6 @@ export const ImportStepper = (props: ImportStepperProps) => { states.analyze( state as Extract, { apis: { catalogImportApi } }, - filters, ), )} {render( diff --git a/plugins/catalog-import/src/components/ImportStepper/defaults.tsx b/plugins/catalog-import/src/components/ImportStepper/defaults.tsx index 6d39a38e4e..d44a71dbdb 100644 --- a/plugins/catalog-import/src/components/ImportStepper/defaults.tsx +++ b/plugins/catalog-import/src/components/ImportStepper/defaults.tsx @@ -264,7 +264,7 @@ export function defaultGenerateStepper( } export const defaultStepper: StepperProvider = { - analyze: (state, { apis }, filters=[]) => ({ + analyze: (state, { apis }) => ({ stepLabel: Select URL, content: ( ), }), diff --git a/plugins/catalog-import/src/components/StepInitAnalyzeUrl/StepInitAnalyzeUrl.tsx b/plugins/catalog-import/src/components/StepInitAnalyzeUrl/StepInitAnalyzeUrl.tsx index 51c5a4d3fd..49e4a4fa4a 100644 --- a/plugins/catalog-import/src/components/StepInitAnalyzeUrl/StepInitAnalyzeUrl.tsx +++ b/plugins/catalog-import/src/components/StepInitAnalyzeUrl/StepInitAnalyzeUrl.tsx @@ -59,7 +59,6 @@ export const StepInitAnalyzeUrl = (props: StepInitAnalyzeUrlProps) => { analysisUrl = '', disablePullRequest = false, exampleLocationUrl = 'https://github.com/backstage/backstage/blob/master/catalog-info.yaml', - filters = [], } = props; const errorApi = useApi(errorApiRef); @@ -80,8 +79,6 @@ export const StepInitAnalyzeUrl = (props: StepInitAnalyzeUrlProps) => { const [submitted, setSubmitted] = useState(false); const [error, setError] = useState(undefined); - const filteredRegex = new RegExp(`^http[s]?://${filters ? `[${filters.map((filter, i) => i === 0 ? filter : `|${filter}`)}]` : ''}`) - const handleResult = useCallback( async ({ url }: FormData) => { setSubmitted(true); @@ -143,7 +140,7 @@ export const StepInitAnalyzeUrl = (props: StepInitAnalyzeUrlProps) => { validate: { httpsValidator: (value: any) => (typeof value === 'string' && - value.match(filteredRegex) !== null) || + value.match(/^http[s]?:\/\//) !== null) || 'Must start with http:// or https://.', }, }),