-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmapper.go
131 lines (116 loc) · 3.02 KB
/
mapper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package config
import (
"github.com/gosimple/slug"
"github.com/kyverno/policy-reporter-ui/pkg/auth"
"github.com/kyverno/policy-reporter-ui/pkg/server/api"
"github.com/kyverno/policy-reporter-ui/pkg/utils"
)
func MapConfig(c *Config) *api.Config {
clusters := make([]api.Cluster, 0, len(c.Clusters))
for _, cl := range c.Clusters {
plugins := make([]string, 0, len(cl.Plugins))
for _, pl := range cl.Plugins {
plugins = append(plugins, pl.Name)
}
clusters = append(clusters, api.Cluster{
Name: cl.Name,
Slug: slug.Make(cl.Name),
Plugins: plugins,
Permissions: auth.Permissions{
AccessControl: auth.AccessControl(cl.AccessControl),
},
})
}
current := ""
if len(clusters) > 0 {
current = clusters[0].Slug
}
oauth := c.OpenIDConnect.Enabled
if !oauth {
oauth = c.OAuth.Enabled
}
return &api.Config{
Clusters: clusters,
Default: current,
OAuth: oauth,
Banner: c.UI.Banner,
Boards: api.Boards{
Permissions: auth.Permissions{
AccessControl: auth.AccessControl(c.Boards.AccessControl),
},
},
Logo: api.Logo{
Disabled: c.UI.Logo.Disabled,
Path: c.UI.Logo.Path,
},
Sources: utils.Map(c.Sources, func(s Source) api.Source {
return api.Source{
Name: s.Name,
ViewType: s.ViewType,
Exceptions: s.Exceptions,
Excludes: api.Excludes{
NamespaceKinds: s.Excludes.NamespaceKinds,
ClusterKinds: s.Excludes.ClusterKinds,
Results: s.Excludes.Results,
Severities: s.Excludes.Severities,
},
}
}),
}
}
func MapCustomBoards(customBoards []CustomBoard) map[string]api.CustomBoard {
configs := make(map[string]api.CustomBoard, len(customBoards))
for _, c := range customBoards {
id := slug.Make(c.Name)
configs[id] = api.CustomBoard{
Name: c.Name,
ID: id,
Display: c.Display,
Filter: MapFilter(c.Filter.Include),
Namespaces: api.Namespaces{
Selector: c.Namespaces.Selector,
List: c.Namespaces.List,
},
Sources: api.Sources{
List: c.Sources.List,
},
Permissions: auth.Permissions{
AccessControl: auth.AccessControl(c.AccessControl),
},
PolicyReports: api.PolicyReports{
Selector: c.PolicyReports.Selector,
},
ClusterScope: c.ClusterScope.Enabled,
}
}
return configs
}
func MapClusterPermissions(c *Config) map[string]auth.Permissions {
permissions := make(map[string]auth.Permissions, len(c.Clusters))
for _, cluster := range c.Clusters {
permissions[slug.Make(cluster.Name)] = auth.Permissions{
AccessControl: auth.AccessControl(cluster.AccessControl),
}
}
return permissions
}
func MapFilter(f Filter) api.Includes {
if f.NamespaceKinds == nil {
f.NamespaceKinds = make([]string, 0)
}
if f.ClusterKinds == nil {
f.ClusterKinds = make([]string, 0)
}
if f.Results == nil {
f.Results = make([]string, 0)
}
if f.Severities == nil {
f.Severities = make([]string, 0)
}
return api.Includes{
NamespaceKinds: f.NamespaceKinds,
ClusterKinds: f.ClusterKinds,
Results: f.Results,
Severities: f.Severities,
}
}