removing filter from component and add to rules

Co-authored-by: Zeky Abubaker <zekyabu@users.noreply.github.com>
Signed-off-by: Lucas De Souza <lucas.desouza@aa.com>
This commit is contained in:
Justin De Burgo
2022-11-15 12:16:58 -06:00
committed by Lucas De Souza
parent b4c84ca06b
commit 8985c47ed2
2 changed files with 27 additions and 3 deletions
+3
View File
@@ -218,6 +218,9 @@ catalog:
- System
- Domain
- Location
- owners:
- Spotify
- Backstage
processors:
ldapOrg:
@@ -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 {