using sources instead of owners
Signed-off-by: Lucas De Souza <lucas.desouza@aa.com>
This commit is contained in:
committed by
Lucas De Souza
parent
8985c47ed2
commit
ea96a02064
@@ -218,9 +218,6 @@ catalog:
|
||||
- System
|
||||
- Domain
|
||||
- Location
|
||||
- owners:
|
||||
- Spotify
|
||||
- Backstage
|
||||
|
||||
processors:
|
||||
ldapOrg:
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<ImportState, { activeState: 'analyze' }>,
|
||||
{ apis: { catalogImportApi } },
|
||||
filters,
|
||||
),
|
||||
)}
|
||||
{render(
|
||||
|
||||
@@ -264,7 +264,7 @@ export function defaultGenerateStepper(
|
||||
}
|
||||
|
||||
export const defaultStepper: StepperProvider = {
|
||||
analyze: (state, { apis }, filters=[]) => ({
|
||||
analyze: (state, { apis }) => ({
|
||||
stepLabel: <StepLabel>Select URL</StepLabel>,
|
||||
content: (
|
||||
<StepInitAnalyzeUrl
|
||||
@@ -272,7 +272,6 @@ export const defaultStepper: StepperProvider = {
|
||||
analysisUrl={state.analysisUrl}
|
||||
onAnalysis={state.onAnalysis}
|
||||
disablePullRequest={!apis.catalogImportApi.preparePullRequest}
|
||||
filters={filters}
|
||||
/>
|
||||
),
|
||||
}),
|
||||
|
||||
@@ -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<string | undefined>(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://.',
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user