...
1 package file
2
3
4
5
6 import (
7 "context"
8 "fmt"
9
10 "edge-infra.dev/pkg/lib/fog"
11 "edge-infra.dev/pkg/sds/emergencyaccess/eaconst"
12 rulesengine "edge-infra.dev/pkg/sds/emergencyaccess/rules"
13 )
14
15 type jsonData struct {
16 BannerID string `json:"bannerid"`
17 Roles map[string][]string `json:"roles"`
18 }
19
20
21 func (ds Dataset) EARoles(ctx context.Context, bannerID string, command rulesengine.Command) ([]string, error) {
22 reqlog := fog.FromContext(ctx).WithName("dataset")
23
24 if command.Type != eaconst.Command {
25 return nil, fmt.Errorf("file based dataset currently does not support non-command types: %q", command.Type)
26 }
27
28 roleMap := ds.bannerRoleMap[bannerID]
29 roles := checkCommand(command.Name, ds.bannerRoleMap[defaultRolesName])
30 if roleMap == nil {
31 reqlog.V(1).Info("banner id not found", "bannerID", bannerID)
32 return roles, nil
33 }
34
35 roles = append(roles, checkCommand(command.Name, roleMap)...)
36 return roles, nil
37 }
38
39
40
41 func checkCommand(command string, data map[string][]string) []string {
42 res := []string{}
43 for priv, commands := range data {
44 if inList(command, commands) {
45 res = append(res, priv)
46 }
47 }
48 return res
49 }
50
51 func inList(val string, lst []string) bool {
52 for _, item := range lst {
53 if val == item {
54 return true
55 }
56 }
57 return false
58 }
59
View as plain text