mirror of
https://github.com/juanfont/headscale.git
synced 2025-09-02 13:47:00 +02:00
Fixed auth key expired error
This commit is contained in:
parent
657f8948cc
commit
167925b264
12
grpcv1.go
12
grpcv1.go
@ -6,7 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||
"github.com/rs/zerolog/log"
|
||||
"gorm.io/datatypes"
|
||||
"tailscale.com/tailcfg"
|
||||
@ -99,16 +99,18 @@ func (api headscaleV1APIServer) CreatePreAuthKey(
|
||||
ctx context.Context,
|
||||
request *v1.CreatePreAuthKeyRequest,
|
||||
) (*v1.CreatePreAuthKeyResponse, error) {
|
||||
var expiration time.Time
|
||||
var expiration *time.Time
|
||||
if request.GetExpiration() != nil {
|
||||
expiration = request.GetExpiration().AsTime()
|
||||
expirationTime := request.GetExpiration().AsTime()
|
||||
expiration = &expirationTime
|
||||
}
|
||||
|
||||
preAuthKey, err := api.h.CreatePreAuthKey(
|
||||
preAuthKey, err := api.h.CreatePreAuthKeyWithSubnet(
|
||||
request.GetNamespace(),
|
||||
request.GetReusable(),
|
||||
request.GetEphemeral(),
|
||||
&expiration,
|
||||
expiration,
|
||||
request.GetSubnet(),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -26,21 +26,32 @@ type PreAuthKey struct {
|
||||
NamespaceID uint
|
||||
Namespace Namespace
|
||||
Reusable bool
|
||||
Ephemeral bool `gorm:"default:false"`
|
||||
Subnet string `gorm:"default:''"`
|
||||
Used bool `gorm:"default:false"`
|
||||
Ephemeral bool `gorm:"default:false"`
|
||||
Used bool `gorm:"default:false"`
|
||||
Subnet string
|
||||
|
||||
CreatedAt *time.Time
|
||||
Expiration *time.Time
|
||||
}
|
||||
|
||||
// CreatePreAuthKey creates a new PreAuthKey in a namespace for the default subnet, and returns it
|
||||
func (h *Headscale) CreatePreAuthKey(namespaceName string, reusable bool, ephemeral bool, expiration *time.Time) (*PreAuthKey, error) {
|
||||
// CreatePreAuthKey creates a new PreAuthKey in a namespace for the default subnet, and returns it.
|
||||
func (h *Headscale) CreatePreAuthKey(
|
||||
namespaceName string,
|
||||
reusable bool,
|
||||
ephemeral bool,
|
||||
expiration *time.Time,
|
||||
) (*PreAuthKey, error) {
|
||||
return h.CreatePreAuthKeyWithSubnet(namespaceName, reusable, ephemeral, expiration, "")
|
||||
}
|
||||
|
||||
// CreatePreAuthKey creates a new PreAuthKey in a namespace with a subnet, and returns it
|
||||
func (h *Headscale) CreatePreAuthKeyWithSubnet(namespaceName string, reusable bool, ephemeral bool, expiration *time.Time, subnet string) (*PreAuthKey, error) {
|
||||
// CreatePreAuthKeyWithSubnet creates a new PreAuthKey in a namespace with a subnet, and returns it
|
||||
func (h *Headscale) CreatePreAuthKeyWithSubnet(
|
||||
namespaceName string,
|
||||
reusable bool,
|
||||
ephemeral bool,
|
||||
expiration *time.Time,
|
||||
subnet string,
|
||||
) (*PreAuthKey, error) {
|
||||
namespace, err := h.GetNamespace(namespaceName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -164,6 +175,7 @@ func (key *PreAuthKey) toProto() *v1.PreAuthKey {
|
||||
Ephemeral: key.Ephemeral,
|
||||
Reusable: key.Reusable,
|
||||
Used: key.Used,
|
||||
Subnet: key.Subnet,
|
||||
}
|
||||
|
||||
if key.Expiration != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user