/
models.go
71 lines (64 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
package config
import (
"time"
"github.com/jinzhu/gorm"
)
// Config is the main config structure and DB Model
type Config struct {
gorm.Model
Expires string `gorm:"default:'48h'"`
PrivateKey []byte `gorm:"type:varbinary(4096);"`
UserPrivateKey []byte `gorm:"type:varbinary(4096);"`
ServerPrivateKey []byte `gorm:"type:varbinary(4096);"`
DefaultHosts string `gorm:"type:MEDIUMTEXT;"`
}
// User is the model for users and their data
type User struct {
gorm.Model
CertExpires time.Time
Email string `gorm:"type:varchar(255);"`
AuthToken string `gorm:"type:MEDIUMTEXT;"`
Cert []byte `gorm:"type:varbinary(4096);"`
PrivateKey []byte `gorm:"type:varbinary(4096);"`
Authorized bool `gorm:"default:false"`
AuthorizedHosts string `gorm:"type:MEDIUMTEXT;"`
Admin bool `gorm:"default:false"`
UnixUser string `gorm:"type:varchar(255);"`
OTPSecret string `gorm:"type:varchar(255);"`
AuthRules []AuthRules `gorm:"many2many:user_auth_rules;"`
}
// AuthRules is the model for different authorization rules (regex)
type AuthRules struct {
gorm.Model
Name string `gorm:"type:varchar(255);"`
AuthorizedHosts string `gorm:"type:MEDIUMTEXT;"`
UnixUser string `gorm:"type:varchar(255);"`
}
// Session is the model for a specific SSH sessions
type Session struct {
gorm.Model
Name string `gorm:"type:MEDIUMTEXT;"`
Time time.Time
Cast string `gorm:"type:LONGTEXT;"`
UserID uint
User *User
Host string `gorm:"type:MEDIUMTEXT;"`
Hostname string `gorm:"type:MEDIUMTEXT;"`
Users string `gorm:"type:LONGTEXT;"`
Command string `gorm:"type:MEDIUMTEXT;"`
}
// LiveSession is the model for a specific live SSH session
type LiveSession struct {
gorm.Model
Name string `gorm:"type:MEDIUMTEXT;"`
WS string `gorm:"type:MEDIUMTEXT;"`
Time time.Time
UserID uint
User *User
Host string `gorm:"type:MEDIUMTEXT;"`
Hostname string `gorm:"type:MEDIUMTEXT;"`
Command string `gorm:"type:MEDIUMTEXT;"`
Bastion string `gorm:"type:MEDIUMTEXT;"`
BastionHostname string `gorm:"type:MEDIUMTEXT;"`
AuthCode string `gorm:"type:MEDIUMTEXT;"`
}