From 091bc05a303ae4e0222007d4fc30bf0d8df16780 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Wed, 19 Feb 2025 19:16:16 +0200 Subject: [PATCH] credservice: allow rotation to be disabled --- credservice.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/credservice.go b/credservice.go index 3a95fb2..b4fc6ed 100644 --- a/credservice.go +++ b/credservice.go @@ -20,10 +20,9 @@ func CredService(interval, timeout time.Duration, var mux sync.Mutex var auth_header, user_uuid string auth = func() (res string) { - (&mux).Lock() - res = auth_header - (&mux).Unlock() - return + mux.Lock() + defer mux.Unlock() + return auth_header } tx_res, tx_err := EnsureTransaction(context.Background(), timeout, func(ctx context.Context, client *http.Client) bool { @@ -45,6 +44,9 @@ func CredService(interval, timeout time.Duration, return } auth_header = basic_auth_header(TemplateLogin(user_uuid), tunnels.AgentKey) + if interval <= 0 { + return + } go func() { var ( err error @@ -74,9 +76,9 @@ func CredService(interval, timeout time.Duration, logger.Critical("All rotation attempts failed.") continue } - (&mux).Lock() + mux.Lock() auth_header = basic_auth_header(TemplateLogin(user_uuid), tuns.AgentKey) - (&mux).Unlock() + mux.Unlock() logger.Info("Credentials rotated successfully.") } }()