Skip to content

Commit ea041b3

Browse files
committed
Use TVars more efficiently in OIDC Auth
Also rename variables wrongly named as MVar as they are really TVars
1 parent b2dedbd commit ea041b3

File tree

1 file changed

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

1 file changed

+8
-8
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ data OIDCAuth = OIDCAuth { issuerURL :: Text
3636
, clientID :: Text
3737
, clientSecret :: Text
3838
, tlsParams :: TLS.ClientParams
39-
, idTokenMVar :: TVar(Maybe Text)
40-
, refreshTokenMVar :: TVar(Maybe Text)
39+
, idTokenTVar :: TVar(Maybe Text)
40+
, refreshTokenTVar :: TVar(Maybe Text)
4141
}
4242

4343
-- | Cache OIDCAuth based on issuerURL and clientID.
@@ -55,7 +55,7 @@ getToken :: OIDCAuth -> IO Text
5555
getToken o@(OIDCAuth{..}) = do
5656
now <- getPOSIXTime
5757
mgr <- newManager tlsManagerSettings
58-
idToken <- atomically $ readTVar idTokenMVar
58+
idToken <- readTVarIO idTokenTVar
5959
let maybeExp = idToken
6060
& (>>= decode)
6161
& (fmap claims)
@@ -68,7 +68,7 @@ getToken o@(OIDCAuth{..}) = do
6868

6969
fetchToken :: Manager -> OIDCAuth -> IO Text
7070
fetchToken mgr o@(OIDCAuth{..}) = do
71-
maybeToken <- atomically $ readTVar refreshTokenMVar
71+
maybeToken <- readTVarIO refreshTokenTVar
7272
case maybeToken of
7373
Nothing -> error "cannot refresh id-token without a refresh token"
7474
Just token -> do
@@ -85,7 +85,7 @@ fetchToken mgr o@(OIDCAuth{..}) = do
8585
case OAuth.idToken oauthToken of
8686
Nothing -> error "token response did not contain an id_token, either the scope \"openid\" wasn't requested upon login, or the provider doesn't support id_tokens as part of the refresh response."
8787
Just (IdToken t) -> do
88-
_ <- atomically $ writeTVar idTokenMVar (Just t)
88+
_ <- atomically $ writeTVar idTokenTVar (Just t)
8989
return t
9090

9191
fetchTokenEndpoint :: Manager -> OIDCAuth -> IO Text
@@ -116,7 +116,7 @@ oidcAuth _ _ = Nothing
116116
-}
117117
cachedOIDCAuth :: OIDCCache -> DetectAuth
118118
cachedOIDCAuth cache AuthInfo{authProvider = Just(AuthProviderConfig "oidc" (Just cfg))} (tls, kubecfg) = Just $ do
119-
m <- atomically $ readTVar cache
119+
m <- readTVarIO cache
120120
o <- case findInCache m cfg of
121121
Left e -> error e
122122
Right (Just o) -> return o
@@ -137,8 +137,8 @@ findInCache cache cfg = do
137137
parseOIDCAuthInfo :: Map Text Text -> IO (Either String OIDCAuth)
138138
parseOIDCAuthInfo m = do
139139
eitherTLSParams <- parseCA m
140-
idTokenMVar <- atomically $ newTVar $ Map.lookup "id-token" m
141-
refreshTokenMVar <- atomically $ newTVar $ Map.lookup "refresh-token" m
140+
idTokenTVar <- atomically $ newTVar $ Map.lookup "id-token" m
141+
refreshTokenTVar <- atomically $ newTVar $ Map.lookup "refresh-token" m
142142
return $ do
143143
tlsParams <- eitherTLSParams
144144
issuerURL <- lookupEither m "idp-issuer-url"

0 commit comments

Comments
 (0)