backstage
104 строки · 2.8 Кб
1/*
2* Copyright 2022 The Backstage Authors
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
17import { createPermission } from '@backstage/plugin-permission-common';
18
19/**
20* Permission resource type which corresponds to a scaffolder templates.
21*
22* @alpha
23*/
24export const RESOURCE_TYPE_SCAFFOLDER_TEMPLATE = 'scaffolder-template';
25
26/**
27* Permission resource type which corresponds to a scaffolder action.
28*
29* @alpha
30*/
31export const RESOURCE_TYPE_SCAFFOLDER_ACTION = 'scaffolder-action';
32
33/**
34* This permission is used to authorize actions that involve executing
35* an action from a template.
36*
37* @alpha
38*/
39export const actionExecutePermission = createPermission({
40name: 'scaffolder.action.execute',
41attributes: {},
42resourceType: RESOURCE_TYPE_SCAFFOLDER_ACTION,
43});
44
45/**
46* This permission is used to authorize actions that involve reading
47* one or more parameters from a template.
48*
49* If this permission is not authorized, it will appear that the
50* parameter does not exist in the template — both in the frontend
51* and in API responses.
52*
53* @alpha
54*/
55export const templateParameterReadPermission = createPermission({
56name: 'scaffolder.template.parameter.read',
57attributes: {
58action: 'read',
59},
60resourceType: RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,
61});
62
63/**
64* This permission is used to authorize actions that involve reading
65* one or more steps from a template.
66*
67* If this permission is not authorized, it will appear that the
68* step does not exist in the template — both in the frontend
69* and in API responses. Steps will also not be executed.
70*
71* @alpha
72*/
73export const templateStepReadPermission = createPermission({
74name: 'scaffolder.template.step.read',
75attributes: {
76action: 'read',
77},
78resourceType: RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,
79});
80
81/**
82* List of all the scaffolder permissions
83* @alpha
84*/
85export const scaffolderPermissions = [
86actionExecutePermission,
87templateParameterReadPermission,
88templateStepReadPermission,
89];
90
91/**
92* List of the scaffolder permissions that are associated with template steps and parameters.
93* @alpha
94*/
95export const scaffolderTemplatePermissions = [
96templateParameterReadPermission,
97templateStepReadPermission,
98];
99
100/**
101* List of the scaffolder permissions that are associated with scaffolder actions.
102* @alpha
103*/
104export const scaffolderActionPermissions = [actionExecutePermission];
105