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"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/juanfont/headscale/gen/go/headscale/v1"
|
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"gorm.io/datatypes"
|
"gorm.io/datatypes"
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
@ -99,16 +99,18 @@ func (api headscaleV1APIServer) CreatePreAuthKey(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *v1.CreatePreAuthKeyRequest,
|
request *v1.CreatePreAuthKeyRequest,
|
||||||
) (*v1.CreatePreAuthKeyResponse, error) {
|
) (*v1.CreatePreAuthKeyResponse, error) {
|
||||||
var expiration time.Time
|
var expiration *time.Time
|
||||||
if request.GetExpiration() != nil {
|
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.GetNamespace(),
|
||||||
request.GetReusable(),
|
request.GetReusable(),
|
||||||
request.GetEphemeral(),
|
request.GetEphemeral(),
|
||||||
&expiration,
|
expiration,
|
||||||
|
request.GetSubnet(),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -26,21 +26,32 @@ type PreAuthKey struct {
|
|||||||
NamespaceID uint
|
NamespaceID uint
|
||||||
Namespace Namespace
|
Namespace Namespace
|
||||||
Reusable bool
|
Reusable bool
|
||||||
Ephemeral bool `gorm:"default:false"`
|
Ephemeral bool `gorm:"default:false"`
|
||||||
Subnet string `gorm:"default:''"`
|
Used bool `gorm:"default:false"`
|
||||||
Used bool `gorm:"default:false"`
|
Subnet string
|
||||||
|
|
||||||
CreatedAt *time.Time
|
CreatedAt *time.Time
|
||||||
Expiration *time.Time
|
Expiration *time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreatePreAuthKey creates a new PreAuthKey in a namespace for the default subnet, and returns it
|
// 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) {
|
func (h *Headscale) CreatePreAuthKey(
|
||||||
|
namespaceName string,
|
||||||
|
reusable bool,
|
||||||
|
ephemeral bool,
|
||||||
|
expiration *time.Time,
|
||||||
|
) (*PreAuthKey, error) {
|
||||||
return h.CreatePreAuthKeyWithSubnet(namespaceName, reusable, ephemeral, expiration, "")
|
return h.CreatePreAuthKeyWithSubnet(namespaceName, reusable, ephemeral, expiration, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreatePreAuthKey creates a new PreAuthKey in a namespace with a subnet, and returns it
|
// 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) {
|
func (h *Headscale) CreatePreAuthKeyWithSubnet(
|
||||||
|
namespaceName string,
|
||||||
|
reusable bool,
|
||||||
|
ephemeral bool,
|
||||||
|
expiration *time.Time,
|
||||||
|
subnet string,
|
||||||
|
) (*PreAuthKey, error) {
|
||||||
namespace, err := h.GetNamespace(namespaceName)
|
namespace, err := h.GetNamespace(namespaceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -164,6 +175,7 @@ func (key *PreAuthKey) toProto() *v1.PreAuthKey {
|
|||||||
Ephemeral: key.Ephemeral,
|
Ephemeral: key.Ephemeral,
|
||||||
Reusable: key.Reusable,
|
Reusable: key.Reusable,
|
||||||
Used: key.Used,
|
Used: key.Used,
|
||||||
|
Subnet: key.Subnet,
|
||||||
}
|
}
|
||||||
|
|
||||||
if key.Expiration != nil {
|
if key.Expiration != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user