-
Notifications
You must be signed in to change notification settings - Fork 34
/
utils.go
47 lines (38 loc) · 1003 Bytes
/
utils.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
package internal
import (
"errors"
"unicode"
"github.com/bmc-toolbox/bmclib/cfgresources"
)
// IsntLetterOrNumber check if the give rune is not a letter nor a number
func IsntLetterOrNumber(c rune) bool {
return !unicode.IsLetter(c) && !unicode.IsNumber(c)
}
func IsRoleValid(role string) bool {
return role == "admin" || role == "user" || role == "operator"
}
func ValidateUserConfig(cfgUsers []*cfgresources.User) (err error) {
for _, cfgUser := range cfgUsers {
if cfgUser.Name == "" {
msg := "User resource expects parameter: Name."
return errors.New(msg)
}
if cfgUser.Password == "" {
msg := "User resource expects parameter: Password."
return errors.New(msg)
}
if !IsRoleValid(cfgUser.Role) {
msg := "Parameter \"Role\" is one of ['admin', 'user']. You sent " + cfgUser.Role
return errors.New(msg + "!")
}
}
return nil
}
func StringInSlice(str string, sl []string) bool {
for _, s := range sl {
if str == s {
return true
}
}
return false
}