This repository was archived by the owner on Feb 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 492
/
Copy pathroles.go
93 lines (85 loc) · 2.63 KB
/
roles.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
package web
import (
"fmt"
"net/http"
"strings"
"github.com/MiniProfiler/go/miniprofiler"
"github.com/captncraig/easyauth"
)
const (
canViewDash easyauth.Role = 1 << iota
canViewConfig
canPutData
canPerformActions
canRunTests
canSaveConfig
canViewAnnotations
canCreateAnnotations
canSilence
canManageTokens
canOverwriteUsername
)
const (
fullyOpen easyauth.Role = 0
roleReader = canViewDash | canViewConfig | canViewAnnotations
roleAdmin = 0xFFFFFFFF
roleWriter = roleAdmin ^ canManageTokens ^ canOverwriteUsername
)
var roleDefs = &roleMetadata{
Permissions: []bitDesc{
{canViewDash, "View Dashboard", "Can view dashboard and alert state data, metrics, and graphs"},
{canViewConfig, "View Config", "Can view bosun configuration page"},
{canPutData, "Put Data", "Can put and index opentsdb data and metadata"},
{canPerformActions, "Actions", "Can acknowlege and close alerts"},
{canRunTests, "Run Tests", "Can execute expressions, graphs, and rule tests"},
{canSaveConfig, "Save Config", "Can alter and save bosun rule config"},
{canViewAnnotations, "View Annotations", "Can view annotations on graph page"},
{canCreateAnnotations, "Create Annotations", "Can add and manage annotations via api"},
{canSilence, "Silence", "Can add and manage silences"},
{canManageTokens, "Manage Tokens", "Can manage authorization tokens"},
{canOverwriteUsername, "Set Username", "Allows external services to set username in api requests"},
},
Roles: []bitDesc{
{roleReader, "Reader", "Read access to dashboard and alert data"},
{roleAdmin, "Admin", "Full access to all functionality"},
{roleWriter, "Writer", "Write access to alert data and actions"},
},
}
type bitDesc struct {
Bits easyauth.Role
Name string
Desc string
}
type roleMetadata struct {
Permissions []bitDesc
Roles []bitDesc
}
func parseRole(s string) (easyauth.Role, error) {
parts := strings.Split(s, ",")
perms := fullyOpen
for _, part := range parts {
this := fullyOpen
for _, perm := range roleDefs.Permissions {
pname := strings.Replace(strings.ToLower(perm.Name), " ", "", -1)
if strings.ToLower(part) == pname {
this = perm.Bits
break
}
}
for _, perm := range roleDefs.Roles {
pname := strings.Replace(strings.ToLower(perm.Name), " ", "", -1)
if strings.ToLower(part) == pname {
this = perm.Bits
break
}
}
if this == fullyOpen {
return this, fmt.Errorf("Unknown permission level: '%s'", part)
}
perms |= this
}
return perms, nil
}
func getRoleDefinitions(_ miniprofiler.Timer, w http.ResponseWriter, r *http.Request) (interface{}, error) {
return roleDefs, nil
}