mirror of
https://github.com/juanfont/headscale.git
synced 2025-09-25 17:51:11 +02:00
This is a massive commit that restructures the code into modules: db/ All functions related to modifying the Database types/ All type definitions and methods that can be exclusivly used on these types without dependencies policy/ All Policy related code, now without dependencies on the Database. policy/matcher/ Dedicated code to match machines in a list of FilterRules Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
42 lines
809 B
Go
42 lines
809 B
Go
package types
|
|
|
|
import (
|
|
"time"
|
|
|
|
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
// APIKey describes the datamodel for API keys used to remotely authenticate with
|
|
// headscale.
|
|
type APIKey struct {
|
|
ID uint64 `gorm:"primary_key"`
|
|
Prefix string `gorm:"uniqueIndex"`
|
|
Hash []byte
|
|
|
|
CreatedAt *time.Time
|
|
Expiration *time.Time
|
|
LastSeen *time.Time
|
|
}
|
|
|
|
func (key *APIKey) Proto() *v1.ApiKey {
|
|
protoKey := v1.ApiKey{
|
|
Id: key.ID,
|
|
Prefix: key.Prefix,
|
|
}
|
|
|
|
if key.Expiration != nil {
|
|
protoKey.Expiration = timestamppb.New(*key.Expiration)
|
|
}
|
|
|
|
if key.CreatedAt != nil {
|
|
protoKey.CreatedAt = timestamppb.New(*key.CreatedAt)
|
|
}
|
|
|
|
if key.LastSeen != nil {
|
|
protoKey.LastSeen = timestamppb.New(*key.LastSeen)
|
|
}
|
|
|
|
return &protoKey
|
|
}
|