diff --git a/app-config.yaml b/app-config.yaml index dd72051189..3eb8e7e01c 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -218,6 +218,9 @@ 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 548c71d833..d25e936d1a 100644 --- a/plugins/catalog-backend/src/ingestion/CatalogRules.ts +++ b/plugins/catalog-backend/src/ingestion/CatalogRules.ts @@ -32,6 +32,9 @@ export type CatalogRule = { target?: string; type: string; }>; + owners?: Array<{ + owner: string + }>; }; /** @@ -94,6 +97,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 })), })); rules.push(...globalRules); } else { @@ -122,7 +126,7 @@ export class DefaultCatalogRulesEnforcer implements CatalogRulesEnforcer { return new DefaultCatalogRulesEnforcer(rules); } - constructor(private readonly rules: CatalogRule[]) {} + constructor(private readonly rules: CatalogRule[]) { } /** * Checks whether a specific entity/location combination is allowed @@ -134,9 +138,13 @@ export class DefaultCatalogRulesEnforcer implements CatalogRulesEnforcer { continue; } - if (this.matchEntity(entity, rule.allow)) { - return true; + if (!this.matchOwners(entity, rule.owners)) { + return false; } + + if (this.matchEntity(entity, rule.allow)) { + return true; + } } return false; @@ -178,6 +186,19 @@ export class DefaultCatalogRulesEnforcer implements CatalogRulesEnforcer { return false; } + + private matchOwners(entity: Entity, matchers?: { owner: string }[]): boolean { + if (!matchers) { + return true; + } + + const filteredRegex = new RegExp(`^http[s]?://${`(?:${matchers.map((filter, i) => i === 0 ? filter.owner : `|${filter.owner}`)})`}`); + + if ( entity?.metadata.links && entity?.metadata?.links?.length > 0) { + return filteredRegex.test(entity?.metadata?.links[0].url); + } + return false; + } } function resolveTarget(type: string, target: string): string {