-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.go
86 lines (73 loc) · 2.27 KB
/
models.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
package main
const (
mgoUserColl = "users"
mgoPosixGroupColl = "posix_groups"
mgoFilterTagColl = "filter_tags"
mgoCounterColl = "counters"
)
// keymaps
var userldap2bson = map[string]string{
"uidNumber": "_id",
"gidNumber": "gid",
"mail": "email",
"uid": "username",
"cn": "username",
"loginShell": "login_shell",
}
var groupldap2bson = map[string]string{
"gidNumber": "gid",
"cn": "name",
"memberUid": "members",
}
var ldapIntegerFields = map[string]bool{
"gidNumber": true,
"uidNumber": true,
}
// A User is a tuna account
type User struct {
UID int `bson:"_id" json:"uid" ldap:"uidNumber"`
GID int `bson:"gid" json:"gid" ldap:"gidNumber"`
Name string `bson:"name" json:"name"`
Email string `bson:"email" json:"email" ldap:"mail"`
Phone string `bson:"phone" json:"phone"`
Username string `bson:"username" json:"username" ldap:"uid,cn"`
Password string `bson:"password" json:"password" ldap:"userPassword"`
LoginShell string `bson:"login_shell" json:"login_shell" ldap:"loginShell"`
IsActive bool `bson:"is_active" json:"is_active"`
IsAdmin bool `bson:"is_admin" json:"is_admin"`
SSHKeys []string `bson:"ssh_keys"`
Tags []string `bson:"tags" json:"tags"`
}
// Authenticate user with passwd
func (u *User) Authenticate(password string) bool {
return validateSSHA(password, u.Password)
}
// Passwd set user's password
func (u *User) Passwd(password string) *User {
u.Password = generateSSHA(password)
return u
}
// A PosixGroup maps to a posix user group
type PosixGroup struct {
GID int `bson:"gid" json:"gid" ldap:"gidNumber"`
Name string `bson:"name" json:"name" ldap:"cn"`
Tag string `bson:"tag" json:"tag"`
IsActive bool `bson:"is_active" json:"is_active"`
Members []string `bson:"members" json:"members" ldap:"memberUid"`
}
// A FilterTag can be used to filter users and groups
// a typical filterTag is the server hostname
type FilterTag struct {
Name string `bson:"_id" json:"name"`
Desc string `bson:"desc" json:"desc"`
}
type mongoCounter struct {
ID string `bson:"_id"`
Seq int `bson:"seq"`
}
// A DBDump contains data exported by or
// can be imported to tunaccount
type DBDump struct {
Users []User `json:"users"`
PosixGroups []PosixGroup `json:"posix_groups"`
}