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:
Lucas De Souza
2022-11-28 12:04:28 -06:00
parent 4c84c3d6ee
commit da01dfdacd
5 changed files with 8 additions and 5 deletions
+3 -3
View File
@@ -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;
}>;
+1
View File
@@ -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;
+1
View File
@@ -5236,6 +5236,7 @@ __metadata:
knex: ^2.0.0
lodash: ^4.17.21
luxon: ^3.0.0
minimatch: ^5.0.0
msw: ^0.49.0
node-fetch: ^2.6.7
p-limit: ^3.0.2