mirror of
https://github.com/juanfont/headscale.git
synced 2025-08-14 13:51:01 +02:00
Show if a authkey has been used already (fixes #154)
This commit is contained in:
parent
dd1e425d02
commit
999c7ee287
@ -57,7 +57,7 @@ var listPreAuthKeys = &cobra.Command{
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
d := pterm.TableData{{"ID", "Key", "Reusable", "Ephemeral", "Expiration", "Created"}}
|
d := pterm.TableData{{"ID", "Key", "Reusable", "Ephemeral", "AlreadyUsed", "Expiration", "Created"}}
|
||||||
for _, k := range *keys {
|
for _, k := range *keys {
|
||||||
expiration := "-"
|
expiration := "-"
|
||||||
if k.Expiration != nil {
|
if k.Expiration != nil {
|
||||||
@ -76,6 +76,7 @@ var listPreAuthKeys = &cobra.Command{
|
|||||||
k.Key,
|
k.Key,
|
||||||
reusable,
|
reusable,
|
||||||
strconv.FormatBool(k.Ephemeral),
|
strconv.FormatBool(k.Ephemeral),
|
||||||
|
fmt.Sprintf("%v", k.AlreadyUsed),
|
||||||
expiration,
|
expiration,
|
||||||
k.CreatedAt.Format("2006-01-02 15:04:05"),
|
k.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||||
})
|
})
|
||||||
|
@ -22,6 +22,8 @@ type PreAuthKey struct {
|
|||||||
Reusable bool
|
Reusable bool
|
||||||
Ephemeral bool `gorm:"default:false"`
|
Ephemeral bool `gorm:"default:false"`
|
||||||
|
|
||||||
|
AlreadyUsed bool `gorm:"-"` // this field is not stored in the DB, has to be manually filled
|
||||||
|
|
||||||
CreatedAt *time.Time
|
CreatedAt *time.Time
|
||||||
Expiration *time.Time
|
Expiration *time.Time
|
||||||
}
|
}
|
||||||
@ -64,6 +66,16 @@ func (h *Headscale) GetPreAuthKeys(namespaceName string) (*[]PreAuthKey, error)
|
|||||||
if err := h.db.Preload("Namespace").Where(&PreAuthKey{NamespaceID: n.ID}).Find(&keys).Error; err != nil {
|
if err := h.db.Preload("Namespace").Where(&PreAuthKey{NamespaceID: n.ID}).Find(&keys).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i, k := range keys {
|
||||||
|
machines := []Machine{}
|
||||||
|
if err := h.db.Preload("AuthKey").Where(&Machine{AuthKeyID: uint(k.ID)}).Find(&machines).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(machines) > 0 {
|
||||||
|
keys[i].AlreadyUsed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
return &keys, nil
|
return &keys, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user