-
Notifications
You must be signed in to change notification settings - Fork 0
/
collaborators.go
58 lines (51 loc) · 1.39 KB
/
collaborators.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
// Copyright © 2017 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
package cmd
import (
"fmt"
"strings"
"github.com/TheThingsNetwork/go-account-lib/account"
"github.com/TheThingsNetwork/go-account-lib/rights"
"github.com/TheThingsNetwork/ttn/core/types"
)
func printCollaborators(collaborators []account.Collaborator) {
for _, collaborator := range collaborators {
fmt.Println(" - Username:", collaborator.Username)
fmt.Println(" Rights:", joinRights(collaborator.Rights, ", "))
}
}
var applicationRights = []types.Right{
rights.AppSettings,
rights.AppCollaborators,
rights.AppDelete,
rights.Devices,
}
var gatewayRights = []types.Right{
rights.GatewaySettings,
rights.GatewayCollaborators,
rights.GatewayDelete,
rights.GatewayLocation,
rights.GatewayStatus,
rights.GatewayOwner,
rights.GatewayMessages,
}
var componentsRights = []types.Right{
rights.ComponentSettings,
rights.ComponentDelete,
rights.ComponentCollaborators,
}
func validRight(available []types.Right, right types.Right) bool {
for _, available := range available {
if right == available {
return true
}
}
return false
}
func joinRights(rights []types.Right, sep string) string {
rightStrings := make([]string, len(rights))
for i, right := range rights {
rightStrings[i] = string(right)
}
return strings.Join(rightStrings, sep)
}