Skip to content

Commit b2dedbd

Browse files
committed
Use TVars more efficiently in GCP Auth
1 parent d695148 commit b2dedbd

File tree

1 file changed

+5
-4
lines changed
  • kubernetes-client/src/Kubernetes/Client/Auth

1 file changed

+5
-4
lines changed

kubernetes-client/src/Kubernetes/Client/Auth/GCP.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ getToken g@(GCPAuth{..}) = getCurrentToken g
6262
getCurrentToken :: GCPAuth -> IO (Maybe Text)
6363
getCurrentToken (GCPAuth{..}) = do
6464
now <- getCurrentTime
65-
maybeExpiry <- atomically $ readTVar gcpTokenExpiry
66-
maybeToken <- atomically $ readTVar gcpAccessToken
65+
maybeExpiry <- readTVarIO gcpTokenExpiry
66+
maybeToken <- readTVarIO gcpAccessToken
6767
return $ do
6868
expiry <- maybeExpiry
6969
if expiry > now
@@ -80,8 +80,9 @@ fetchToken GCPAuth{..} = do
8080
expText = runJSONPath gcpExpiryKey =<< credsJSON
8181
expiry :: Either Text (Maybe UTCTime)
8282
expiry = Just <$> (parseExpiryTime =<< expText)
83-
atomically $ writeTVar gcpAccessToken (rightToMaybe token)
84-
atomically $ writeTVar gcpTokenExpiry (either (const Nothing) id expiry)
83+
atomically $ do
84+
writeTVar gcpAccessToken (rightToMaybe token)
85+
writeTVar gcpTokenExpiry (either (const Nothing) id expiry)
8586
return token
8687

8788
parseGCPAuthInfo :: Map Text Text -> IO (Either Text GCPAuth)

0 commit comments

Comments
 (0)