scaffolder-backend: remove matchesinput rule

Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
Vincenzo Scamporlino
2023-03-24 12:02:28 +01:00
parent faeb730c9f
commit ec13659446
3 changed files with 14 additions and 51 deletions
-1
View File
@@ -66,7 +66,6 @@
"@gitbeaker/core": "^35.6.0",
"@gitbeaker/node": "^35.1.0",
"@octokit/webhooks": "^10.0.0",
"ajv": "^8.12.0",
"azure-devops-node-api": "^11.0.1",
"command-exists": "^1.2.9",
"compression": "^1.7.4",
+14 -49
View File
@@ -14,7 +14,6 @@
* limitations under the License.
*/
import Ajv from 'ajv';
import { makeCreatePermissionRule } from '@backstage/plugin-permission-node';
import {
RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,
@@ -36,7 +35,19 @@ export const createTemplatePermissionRule = makeCreatePermissionRule<
typeof RESOURCE_TYPE_SCAFFOLDER_TEMPLATE
>();
const ajv = new Ajv({ allErrors: true });
export const hasTag = createTemplatePermissionRule({
name: 'HAS_TAG',
resourceType: RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,
description: `Match parameters or steps with the given tag`,
paramsSchema: z.object({
tag: z.string().describe('Name of the tag to match on'),
}),
apply: (resource, { tag }) => {
return resource['backstage:permissions']?.tags?.includes(tag) ?? false;
},
toQuery: () => ({}),
});
export const createActionPermissionRule = makeCreatePermissionRule<
{
action: string;
@@ -59,39 +70,6 @@ export const hasActionId = createActionPermissionRule({
toQuery: () => ({}),
});
export const matchesInput = createActionPermissionRule({
name: 'MATCHES_INPUT',
resourceType: RESOURCE_TYPE_SCAFFOLDER_ACTION,
description: `Matches actionId and the input given`,
paramsSchema: z.object({
action: z.string().describe('Name of the actionId to match on'),
input: z
.any()
.optional()
.describe('JSON schema to validate input against')
.superRefine((value, ctx) => {
if (value && ajv.validateSchema(value)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Invalid JSON schema',
});
}
}),
}),
apply: (resource, { action, input }) => {
if (resource.action !== action) {
return true;
}
if (!input) {
return true;
}
return ajv.validate(input, resource.input);
},
toQuery: () => ({}),
});
export const hasInputProperty = createActionPermissionRule({
name: 'HAS_INPUT',
resourceType: RESOURCE_TYPE_SCAFFOLDER_ACTION,
@@ -122,18 +100,5 @@ export const hasInputProperty = createActionPermissionRule({
toQuery: () => ({}),
});
export const hasTag = createTemplatePermissionRule({
name: 'HAS_TAG',
resourceType: RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,
description: `Match parameters or steps with the given tag`,
paramsSchema: z.object({
tag: z.string().describe('Name of the tag to match on'),
}),
apply: (resource, { tag }) => {
return resource['backstage:permissions']?.tags?.includes(tag) ?? false;
},
toQuery: () => ({}),
});
export const scaffolderTemplateRules = { hasTag };
export const scaffolderActionRules = { matchesInput, hasInputProperty };
export const scaffolderActionRules = { hasActionId, hasInputProperty };
-1
View File
@@ -8020,7 +8020,6 @@ __metadata:
"@types/nunjucks": ^3.1.4
"@types/supertest": ^2.0.8
"@types/zen-observable": ^0.8.0
ajv: ^8.12.0
azure-devops-node-api: ^11.0.1
command-exists: ^1.2.9
compression: ^1.7.4