-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41df43e
commit 2009aa9
Showing
5 changed files
with
123 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"files": [ | ||
{ | ||
"path": "node_modules/@backstage/plugin-catalog-backend/dist/cjs/CatalogBuilder-CGSl8LEN.cjs.js", | ||
"bookmarks": [ | ||
{ | ||
"line": 2369, | ||
"column": 0, | ||
"label": "FilterQueryBuilder" | ||
}, | ||
{ | ||
"line": 2452, | ||
"column": 0, | ||
"label": "DB Query execution" | ||
}, | ||
{ | ||
"line": 5559, | ||
"column": 0, | ||
"label": "Catalog entities router " | ||
}, | ||
{ | ||
"line": 7111, | ||
"column": 0, | ||
"label": "Catalog permission router" | ||
}, | ||
{ | ||
"line": 7170, | ||
"column": 0, | ||
"label": "CatalogRoute creation" | ||
} | ||
] | ||
}, | ||
{ | ||
"path": "node_modules/@backstage/plugin-permission-node/dist/index.cjs.js", | ||
"bookmarks": [ | ||
{ | ||
"line": 26, | ||
"column": 0, | ||
"label": "Permission JSON creation fn" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { createBackendModule } from '@backstage/backend-plugin-api'; | ||
import { catalogPermissionExtensionPoint } from '@backstage/plugin-catalog-node/alpha'; | ||
import { isHaveRepositoryAccess } from '../premissions/repository.rule'; | ||
|
||
export default createBackendModule({ | ||
pluginId: 'catalog', | ||
moduleId: 'permission-rules', | ||
register(reg) { | ||
reg.registerInit({ | ||
deps: { catalog: catalogPermissionExtensionPoint }, | ||
async init({ catalog }) { | ||
catalog.addPermissionRules(isHaveRepositoryAccess); | ||
}, | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { Entity } from '@backstage/catalog-model'; | ||
import { z } from 'zod'; | ||
import { createCatalogPermissionRule } from '@backstage/plugin-catalog-backend/alpha'; | ||
import { createConditionFactory } from '@backstage/plugin-permission-node'; | ||
|
||
export const isHaveRepositoryAccess = createCatalogPermissionRule({ | ||
name: 'IS_HAVE_REPO_ACCESS', | ||
description: 'Checks if entity have repository access', | ||
resourceType: 'catalog-entity', | ||
paramsSchema: z.object({ | ||
repos: z.string().array().describe('name of repositories to check'), | ||
}), | ||
apply: (resource: Entity, { repos }) => { | ||
if (!resource.relations) { | ||
return false; | ||
} | ||
|
||
return resource.relations | ||
.filter(relation => relation.type === 'partOf') | ||
.some(relation => repos.includes(relation.targetRef)); | ||
}, | ||
toQuery: ({ repos }) => { | ||
// it will add sql query to check repo or all the templates | ||
// "metadata.name" in ["repoName"] or kind in ['template'] | ||
return { | ||
anyOf: [ | ||
{ | ||
key: 'metadata.name', | ||
values: repos, | ||
}, | ||
{ | ||
// Skip from the check it will allow all the templates | ||
key: 'kind', | ||
values: ['template'], | ||
}, | ||
], | ||
}; | ||
}, | ||
}); | ||
export const RepositoryAccessCondition = createConditionFactory( | ||
isHaveRepositoryAccess, | ||
); |