From a163de2ea19aef22374a382ed0eb10c6f4b5d612 Mon Sep 17 00:00:00 2001 From: Arnob Kumar Saha Date: Fri, 8 Nov 2024 17:51:08 +0600 Subject: [PATCH] Calculate expiresAt from ttl, if not present (#148) Signed-off-by: Arnob kumar saha --- pkg/rancherutil/rancher.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/rancherutil/rancher.go b/pkg/rancherutil/rancher.go index f1889ea2..094352c7 100644 --- a/pkg/rancherutil/rancher.go +++ b/pkg/rancherutil/rancher.go @@ -103,9 +103,15 @@ func decodeToken(opts clientbase.ClientOpts) (*rancher.Client, *RancherToken, er if err != nil { return nil, nil, err } - expiresAt, err := time.Parse(time.RFC3339, token.ExpiresAt) - if err != nil { - return nil, nil, err + + var expiresAt time.Time + if token.ExpiresAt != "" { + expiresAt, err = time.Parse(time.RFC3339, token.ExpiresAt) + if err != nil { + return nil, nil, err + } + } else { + expiresAt = time.Now().Add(time.Duration(token.TTLMillis) * time.Millisecond) } return rc, &RancherToken{