From 3bab7451429f63f631f8f49bbba66efda906b0e7 Mon Sep 17 00:00:00 2001 From: Pascal Fischer Date: Wed, 29 Mar 2023 17:46:09 +0200 Subject: [PATCH] last_used can be nil --- management/server/http/api/openapi.yml | 1 - management/server/http/api/types.gen.go | 2 +- management/server/http/pat_handler.go | 7 ++++++- management/server/personal_access_token.go | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/management/server/http/api/openapi.yml b/management/server/http/api/openapi.yml index 2668198c4..eaeb5693c 100644 --- a/management/server/http/api/openapi.yml +++ b/management/server/http/api/openapi.yml @@ -316,7 +316,6 @@ components: - expiration_date - created_by - created_at - - last_used PersonalAccessTokenGenerated: type: object properties: diff --git a/management/server/http/api/types.gen.go b/management/server/http/api/types.gen.go index 24abaf829..930a9df54 100644 --- a/management/server/http/api/types.gen.go +++ b/management/server/http/api/types.gen.go @@ -394,7 +394,7 @@ type PersonalAccessToken struct { Id string `json:"id"` // LastUsed Date the token was last used - LastUsed time.Time `json:"last_used"` + LastUsed *time.Time `json:"last_used,omitempty"` // Name Name of the token Name string `json:"name"` diff --git a/management/server/http/pat_handler.go b/management/server/http/pat_handler.go index 7a8175fbf..2f6cb1492 100644 --- a/management/server/http/pat_handler.go +++ b/management/server/http/pat_handler.go @@ -3,6 +3,7 @@ package http import ( "encoding/json" "net/http" + "time" "github.com/gorilla/mux" @@ -187,13 +188,17 @@ func (h *PATHandler) DeleteToken(w http.ResponseWriter, r *http.Request) { } func toPATResponse(pat *server.PersonalAccessToken) *api.PersonalAccessToken { + var lastUsed *time.Time + if !pat.LastUsed.IsZero() { + lastUsed = &pat.LastUsed + } return &api.PersonalAccessToken{ CreatedAt: pat.CreatedAt, CreatedBy: pat.CreatedBy, Name: pat.Name, ExpirationDate: pat.ExpirationDate, Id: pat.ID, - LastUsed: pat.LastUsed, + LastUsed: lastUsed, } } diff --git a/management/server/personal_access_token.go b/management/server/personal_access_token.go index a7c55018f..bdf34e9fd 100644 --- a/management/server/personal_access_token.go +++ b/management/server/personal_access_token.go @@ -57,7 +57,7 @@ func CreateNewPAT(name string, expirationInDays int, createdBy string) (*Persona ExpirationDate: currentTime.AddDate(0, 0, expirationInDays), CreatedBy: createdBy, CreatedAt: currentTime, - LastUsed: currentTime, + LastUsed: time.Time{}, }, PlainToken: plainToken, }, nil