This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuyuser.go
129 lines (111 loc) · 2.84 KB
/
uyuser.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
package ldapsync
import (
"strings"
)
type UyuniUser struct {
Dn string
Uid string
Name string
Secondname string
Email string
Err error
roles []string
new bool
removed bool
outdated bool
roleschanged bool
accountchanged bool
POSSIBLE_ROLES [7]string
}
// Constructor
func NewUyuniUser() *UyuniUser {
uu := new(UyuniUser)
uu.roles = make([]string, 0)
uu.new, uu.outdated = false, false
uu.POSSIBLE_ROLES = [7]string{
"satellite_admin",
"org_admin",
"channel_admin",
"config_admin",
"system_group_admin",
"activation_key_admin",
"image_admin",
}
return uu
}
// AddRole allows add distinct roles to the user
func (u *UyuniUser) AddRoles(newRoles ...string) {
for _, role := range newRoles {
role = strings.ToLower(role)
// Org admin gets everything
if role == "org_admin" {
u.FlushRoles()
for _, sr := range u.POSSIBLE_ROLES {
u.roles = append(u.roles, sr)
}
return
}
for _, userRole := range u.roles {
if userRole == role {
goto Skip
}
}
u.roles = append(u.roles, role)
Skip:
}
}
// FlushRoles removes set roles inside the instance
func (u *UyuniUser) FlushRoles() *UyuniUser {
u.roles = nil
return u
}
// GetRoles returns all roles, assigned to the user
func (u *UyuniUser) GetRoles() []string {
return u.roles
}
// IsValid validates if the user data is compliant
// for the synchronisation
func (u *UyuniUser) IsValid() bool {
return u.Uid != "" && u.Email != "" && u.Name != "" && u.Secondname != "" && u.Err == nil
}
// IsNew resturns a flag, indicating if that user
// is new to Uyuni (i.e. is not yet created)
func (u *UyuniUser) IsNew() bool {
return u.new
}
// IsOutdated returns a flag, indicating that user's
// data has been changed in the LDAP and it needs to be updated.
func (u *UyuniUser) IsOutdated() bool {
return u.outdated
}
// IsRemoved returns a flag, indicating that the user was removed
// from the LDAP (exists in Uyuni, does not exists in LDAP)
func (u *UyuniUser) IsRemoved() bool {
return u.removed
}
// IsAccontDataChanged returns a flag, indicated that account data,
// such as email, name/second name etc has been changed.
func (u *UyuniUser) IsAccountDataChanged() bool {
return u.accountchanged
}
// IsRolesChanged returns a flag, indicated that roles data has been changed.
func (u *UyuniUser) IsRolesChanged() bool {
return u.roleschanged
}
// Clone creates a new user instance with the same data
func (u *UyuniUser) Clone() *UyuniUser {
user := NewUyuniUser()
user.Dn = u.Dn
user.Uid = u.Uid
user.Email = u.Email
user.Name = u.Name
user.Secondname = u.Secondname
user.Err = u.Err
user.new = u.new
user.outdated = u.outdated
user.removed = u.removed
user.accountchanged = u.accountchanged
user.roleschanged = u.roleschanged
user.AddRoles(u.GetRoles()...)
return user
}