use minimatch instead of regex
Co-authored-by: Zeky Abubaker <zeky.abubaker@aa.com> Signed-off-by: Lucas De Souza <lucas.desouza@aa.com>
This commit is contained in:
Vendored
+3
-3
@@ -48,7 +48,7 @@ export interface Config {
|
||||
* { "type": "url", "match": "https://github.com/a/*}
|
||||
*
|
||||
*/
|
||||
location?: Array<{
|
||||
locations?: Array<{
|
||||
/**
|
||||
* The type of location, e.g. "url".
|
||||
*/
|
||||
@@ -59,8 +59,8 @@ export interface Config {
|
||||
*/
|
||||
target?: string;
|
||||
/**
|
||||
* The target Regex of the location, e.g.
|
||||
* "https://github.com/org/*.
|
||||
* The pattern allowed for the location, e.g.
|
||||
* "https://github.com/org/*\/blob/master/*.yaml.
|
||||
*/
|
||||
match?: string;
|
||||
}>;
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
"knex": "^2.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"luxon": "^3.0.0",
|
||||
"minimatch": "^5.0.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
"p-limit": "^3.0.2",
|
||||
"prom-client": "^14.0.1",
|
||||
|
||||
@@ -228,7 +228,7 @@ describe('DefaultCatalogRulesEnforcer', () => {
|
||||
rules: [
|
||||
{
|
||||
allow: ['Component'],
|
||||
locations: [{ type: 'url', match: 'https://github.com/b/*' }],
|
||||
locations: [{ type: 'url', match: 'https://github.com/b/**' }],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -18,6 +18,7 @@ import { Config } from '@backstage/config';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import path from 'path';
|
||||
import { LocationSpec } from '@backstage/plugin-catalog-common';
|
||||
import minimatch from 'minimatch';
|
||||
|
||||
/**
|
||||
* Rules to apply to catalog entities.
|
||||
@@ -172,7 +173,7 @@ export class DefaultCatalogRulesEnforcer implements CatalogRulesEnforcer {
|
||||
if (matcher.target && matcher.target !== location?.target) {
|
||||
continue;
|
||||
}
|
||||
if (matcher.match && !location?.target.match(matcher.match)) {
|
||||
if (matcher.match && !minimatch(location?.target, matcher.match, { nocase: true })) {
|
||||
continue;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user