From da01dfdacd6b979cebb567d0256d463aa6917c0c Mon Sep 17 00:00:00 2001 From: Lucas De Souza Date: Mon, 28 Nov 2022 12:04:28 -0600 Subject: [PATCH] use minimatch instead of regex Co-authored-by: Zeky Abubaker Signed-off-by: Lucas De Souza --- plugins/catalog-backend/config.d.ts | 6 +++--- plugins/catalog-backend/package.json | 1 + plugins/catalog-backend/src/ingestion/CatalogRules.test.ts | 2 +- plugins/catalog-backend/src/ingestion/CatalogRules.ts | 3 ++- yarn.lock | 1 + 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/catalog-backend/config.d.ts b/plugins/catalog-backend/config.d.ts index 16094af489..40d423d0d4 100644 --- a/plugins/catalog-backend/config.d.ts +++ b/plugins/catalog-backend/config.d.ts @@ -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; }>; diff --git a/plugins/catalog-backend/package.json b/plugins/catalog-backend/package.json index ea61ca648e..7c26d21a5b 100644 --- a/plugins/catalog-backend/package.json +++ b/plugins/catalog-backend/package.json @@ -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", diff --git a/plugins/catalog-backend/src/ingestion/CatalogRules.test.ts b/plugins/catalog-backend/src/ingestion/CatalogRules.test.ts index 6cf8682129..9432f1df1a 100644 --- a/plugins/catalog-backend/src/ingestion/CatalogRules.test.ts +++ b/plugins/catalog-backend/src/ingestion/CatalogRules.test.ts @@ -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/**' }], }, ], }, diff --git a/plugins/catalog-backend/src/ingestion/CatalogRules.ts b/plugins/catalog-backend/src/ingestion/CatalogRules.ts index 66fe3da54e..3cda33533b 100644 --- a/plugins/catalog-backend/src/ingestion/CatalogRules.ts +++ b/plugins/catalog-backend/src/ingestion/CatalogRules.ts @@ -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; diff --git a/yarn.lock b/yarn.lock index 7537c367f6..49f1f4d5d4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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