Add registrationID type

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby 2025-01-13 11:51:30 +01:00
parent 6c790e48dd
commit fbd0d5e7ce
No known key found for this signature in database

View file

@ -3,8 +3,10 @@ package types
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"time" "time"
"github.com/juanfont/headscale/hscontrol/util"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/util/ctxkey" "tailscale.com/util/ctxkey"
) )
@ -123,3 +125,32 @@ func NotifyCtx(ctx context.Context, origin, hostname string) context.Context {
ctx2 = NotifyHostnameKey.WithValue(ctx2, hostname) ctx2 = NotifyHostnameKey.WithValue(ctx2, hostname)
return ctx2 return ctx2
} }
const RegistrationIDLength = 24
type RegistrationID string
func NewRegistrationID() (RegistrationID, error) {
rid, err := util.GenerateRandomStringURLSafe(RegistrationIDLength)
if err != nil {
return "", err
}
return RegistrationID(rid), nil
}
func RegistrationIDFromString(str string) (RegistrationID, error) {
if len(str) != RegistrationIDLength {
return "", fmt.Errorf("registration ID must be %d characters long", RegistrationIDLength)
}
return RegistrationID(str), nil
}
func (r RegistrationID) String() string {
return string(r)
}
type RegisterNode struct {
Node Node
Registered chan struct{}
}