From 63711354599651ea33d29ff872ef5f12b8d46907 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Mon, 8 Nov 2021 20:48:20 +0000 Subject: [PATCH] Try to address issue raised by cure --- preauth_keys.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/preauth_keys.go b/preauth_keys.go index 304e345b..1cb9c112 100644 --- a/preauth_keys.go +++ b/preauth_keys.go @@ -139,14 +139,22 @@ func (h *Headscale) generateKey() (string, error) { } func (key *PreAuthKey) toProto() *v1.PreAuthKey { - return &v1.PreAuthKey{ - Namespace: key.Namespace.Name, - Id: strconv.FormatUint(key.ID, 10), - Key: key.Key, - Resuable: key.Reusable, - Ephemeral: key.Ephemeral, - Used: key.Used, - Expiration: timestamppb.New(*key.Expiration), - CreatedAt: timestamppb.New(*key.CreatedAt), + protoKey := v1.PreAuthKey{ + Namespace: key.Namespace.Name, + Id: strconv.FormatUint(key.ID, 10), + Key: key.Key, + Ephemeral: key.Ephemeral, + Reusable: key.Reusable, + Used: key.Used, } + + if key.Expiration != nil { + protoKey.Expiration = timestamppb.New(*key.Expiration) + } + + if key.CreatedAt != nil { + protoKey.CreatedAt = timestamppb.New(*key.CreatedAt) + } + + return &protoKey }