-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.go
More file actions
139 lines (122 loc) · 3.66 KB
/
Copy pathmodels.go
File metadata and controls
139 lines (122 loc) · 3.66 KB
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
130
131
132
133
134
135
136
137
138
139
package main
import (
"sync"
"time"
)
// ~~~~~Permissions~~~~~
var Permissions = struct {
SystemAdmin string
ManageDevices string
ManageUsers string
ManagePending string
ViewAuditLogs string
}{
SystemAdmin: "system_admin",
ManageDevices: "manage_devices",
ManageUsers: "manage_users",
ManagePending: "manage_pending",
ViewAuditLogs: "view_audit_logs",
}
// ~~~~~Data structures~~~~~
type Device struct {
DeviceID string `json:"device_id"`
DeviceName string `json:"device_name"`
CertFingerprint string `json:"cert_fingerprint"`
OwnerUser string `json:"owner_user"`
IssuedAt string `json:"issued_at"`
ExpiresAt string `json:"expires_at"`
Revoked bool `json:"revoked"`
LastSeen string `json:"last_seen"`
}
type User struct {
Username string `json:"username"`
DisplayName string `json:"display_name"`
PasswordHash string `json:"password_hash"`
Permissions []string `json:"permissions"`
Devices []string `json:"devices"`
CreatedAt string `json:"created_at"`
}
type Session struct {
ID string
Username string
CertFingerprint string
ExpiresAt time.Time
}
type Config struct {
BasePath string `json:"base_path"`
ServerPort int `json:"server_port"`
SessionTimeoutSec int `json:"session_timeout_seconds"`
MaxLogFileSizeBytes int `json:"max_log_file_size_bytes"`
MaxBufferSizeBytes int `json:"max_buffer_size_bytes"`
LogAutoFlush bool `json:"log_auto_flush"`
AuditLogPath string `json:"audit_log_path"`
MaxLoginAttempts int `json:"max_login_attempts"`
RateLimitWindowSeconds int `json:"rate_limit_window_seconds"`
PermissionsList []string `json:"permissions_list"`
SMTPHost string `json:"smtp_host"`
SMTPPort int `json:"smtp_port"`
SMTPUsername string `json:"smtp_username"`
SMTPPassword string `json:"smtp_password"`
}
type rateLimit struct {
WindowStart int64 `json:"windowStart"`
LastAttempt int64 `json:"lastAttempt"`
RequestCount int `json:"requestCount"`
}
type PendingRequest struct {
Username string `json:"username"`
PasswordHash string `json:"password_hash"`
DeviceName string `json:"device_name"`
CSR string `json:"csr"`
Email string `json:"email"`
SubmittedAt string `json:"submitted_at"`
Status string `json:"status"`
}
type PendingView struct {
Username string `json:"username"`
DeviceName string `json:"device_name"`
SubmittedAt string `json:"submitted_at"`
Status string `json:"status"`
}
type MeView struct {
Username string `json:"username"`
DisplayName string `json:"display_name"`
Permissions []string `json:"permissions"`
Devices []DeviceView `json:"devices"`
}
// For exposing data to front end
type DeviceView struct {
DeviceName string `json:"device_name"`
DeviceID string `json:"device_id"`
IssuedAt string `json:"issued_at"`
ExpiresAt string `json:"expires_at"`
LastSeen string `json:"last_seen"`
}
type UserView struct {
Username string `json:"username"`
DisplayName string `json:"display_name"`
Permissions []string `json:"permissions"`
Devices []string `json:"devices"`
CreatedAt string `json:"created_at"`
}
// Stores
type rateLimiter struct {
mutex sync.Mutex
rateLimitPath string
}
type DeviceStore struct {
mutex sync.Mutex
devicesPath string
}
type UserStore struct {
mutex sync.Mutex
usersPath string
}
type SessionStore struct {
mutex sync.Mutex
sessionsPath string
}
type PendingStore struct {
mutex sync.Mutex
pendingPath string
}