From 363db6352e3e43efc42037c9926164fdce149346 Mon Sep 17 00:00:00 2001 From: Steven Tan Date: Wed, 6 Apr 2022 03:16:51 +0000 Subject: [PATCH] Added a mechanism to stop proxty if it couldn't reauth during the window --- src/tools/aws.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/tools/aws.go b/src/tools/aws.go index 89a82a3..ff826ec 100644 --- a/src/tools/aws.go +++ b/src/tools/aws.go @@ -89,8 +89,14 @@ func Authenticate() { // CheckReauth checks if we have not yet authenticated, or need to authenticate within the next 15 minutes func CheckReauth() { for { - if CodeArtifactAuthInfo.AuthorizationToken == "" || time.Now().Sub(CodeArtifactAuthInfo.LastAuth) > 45*time.Minute { - log.Printf("%d minutes until the CodeArtifact token expires, attempting a reauth.", time.Now().Sub(CodeArtifactAuthInfo.LastAuth)/time.Minute) + timeSince := time.Since(CodeArtifactAuthInfo.LastAuth).Minutes() + // Panic and shut down the proxy if we couldn't reauthenticate within the 15 minute window for some reason. + if timeSince > float64(60) { + log.Panic("Was unable to re-authenticate prior to our token expiring, shutting down proxty...") + } + + if CodeArtifactAuthInfo.AuthorizationToken == "" || timeSince > float64(45) { + log.Printf("%f minutes until the CodeArtifact token expires, attempting a reauth.", 60-timeSince) Authenticate() } // Sleep for 15 seconds for the next check