denormalise PreAuthKey tags (#2155)
this commit denormalises the Tags related to a Pre auth key back onto the preauthkey table and struct as a string list. There was not really any real normalisation here as we just added a bunch of duplicate tags with new IDs and preauthkeyIDs, lots of GORM cermony but no actual advantage. This work is the start to fixup tags which currently are not working as they should. Updates #1369 Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
49ce5734fc
commit
5eda9c8d2d
5 changed files with 133 additions and 38 deletions
|
@ -16,21 +16,14 @@ type PreAuthKey struct {
|
|||
UserID uint
|
||||
User User `gorm:"constraint:OnDelete:CASCADE;"`
|
||||
Reusable bool
|
||||
Ephemeral bool `gorm:"default:false"`
|
||||
Used bool `gorm:"default:false"`
|
||||
ACLTags []PreAuthKeyACLTag `gorm:"constraint:OnDelete:CASCADE;"`
|
||||
Ephemeral bool `gorm:"default:false"`
|
||||
Used bool `gorm:"default:false"`
|
||||
Tags []string `gorm:"serializer:json"`
|
||||
|
||||
CreatedAt *time.Time
|
||||
Expiration *time.Time
|
||||
}
|
||||
|
||||
// PreAuthKeyACLTag describes an autmatic tag applied to a node when registered with the associated PreAuthKey.
|
||||
type PreAuthKeyACLTag struct {
|
||||
ID uint64 `gorm:"primary_key"`
|
||||
PreAuthKeyID uint64
|
||||
Tag string
|
||||
}
|
||||
|
||||
func (key *PreAuthKey) Proto() *v1.PreAuthKey {
|
||||
protoKey := v1.PreAuthKey{
|
||||
User: key.User.Name,
|
||||
|
@ -39,7 +32,7 @@ func (key *PreAuthKey) Proto() *v1.PreAuthKey {
|
|||
Ephemeral: key.Ephemeral,
|
||||
Reusable: key.Reusable,
|
||||
Used: key.Used,
|
||||
AclTags: make([]string, len(key.ACLTags)),
|
||||
AclTags: key.Tags,
|
||||
}
|
||||
|
||||
if key.Expiration != nil {
|
||||
|
@ -50,9 +43,5 @@ func (key *PreAuthKey) Proto() *v1.PreAuthKey {
|
|||
protoKey.CreatedAt = timestamppb.New(*key.CreatedAt)
|
||||
}
|
||||
|
||||
for idx := range key.ACLTags {
|
||||
protoKey.AclTags[idx] = key.ACLTags[idx].Tag
|
||||
}
|
||||
|
||||
return &protoKey
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue