-
Notifications
You must be signed in to change notification settings - Fork 2
/
device.go
71 lines (60 loc) · 2.75 KB
/
device.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 models
import (
"time"
)
type DeviceStatus string
const (
DeviceNoIdentity DeviceStatus = "NO_IDENTITY"
DeviceActive DeviceStatus = "ACTIVE"
DeviceRenewalWindow DeviceStatus = "RENEWAL_PENDING" //A slot should be ReEnrolled
DeviceAboutToExpire DeviceStatus = "EXPIRING_SOON" //A slot has a Critical certificate and should be ReEnrolled
DeviceExpired DeviceStatus = "EXPIRED"
DeviceRevoked DeviceStatus = "REVOKED"
DeviceDecommissioned DeviceStatus = "DECOMMISSIONED"
)
type SlotStatus string
const (
SlotActive SlotStatus = "ACTIVE"
SlotRenewalWindow SlotStatus = "RENEWAL_PENDING" //PreventiveEnroll
SlotAboutToExpire SlotStatus = "EXPIRING_SOON"
SlotExpired SlotStatus = "EXPIRED"
SlotRevoke SlotStatus = "REVOKED"
)
type Device struct {
ID string `json:"id" gorm:"primaryKey"`
Tags []string `json:"tags" gorm:"serializer:json"`
Status DeviceStatus `json:"status"`
Icon string `json:"icon"`
IconColor string `json:"icon_color"`
CreationTimestamp time.Time `json:"creation_timestamp"`
Metadata map[string]any `json:"metadata" gorm:"serializer:json"`
DMSOwner string `json:"dms_owner"`
IdentitySlot *Slot[string] `json:"identity,omitempty" gorm:"serializer:json"`
ExtraSlots map[string]*Slot[any] `json:"slots" gorm:"serializer:json"`
Events map[time.Time]DeviceEvent `json:"events" gorm:"serializer:json"`
}
type Slot[E any] struct {
Status SlotStatus `json:"status"`
ActiveVersion int `json:"active_version"`
SecretType CryptoSecretType `json:"type"`
Secrets map[int]E `json:"versions"` // version -> secret
Events map[time.Time]DeviceEvent `json:"events" gorm:"serializer:json"`
}
type DeviceEventType string
const (
DeviceEventTypeCreated DeviceEventType = "CREATED"
DeviceEventTypeProvisioned DeviceEventType = "PROVISIONED"
DeviceEventTypeReProvisioned DeviceEventType = "RE-PROVISIONED"
DeviceEventTypeRenewed DeviceEventType = "RENEWED"
DeviceEventTypeShadowUpdated DeviceEventType = "SHADOW-UPDATED"
DeviceEventTypeStatusUpdated DeviceEventType = "STATUS-UPDATED"
DeviceEventTypeStatusDecommissioned DeviceEventType = "DECOMMISSIONED"
)
type DeviceEvent struct {
EvenType DeviceEventType `json:"type"`
EventDescriptions string `json:"description"`
}
type DevicesStats struct {
TotalDevices int `json:"total"`
DevicesStatus map[DeviceStatus]int `json:"status_distribution"`
}