Skip to content

Commit a30745f

Browse files
committed
Remove partial application chains
1 parent 08303c5 commit a30745f

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,16 @@ getToken auth@(OIDCAuth{..}) = do
7272
case maybeIdToken of
7373
Nothing -> fetchToken auth
7474
Just idToken -> do
75-
let maybeExp = decodeClaims (Text.encodeUtf8 idToken)
76-
& rightToMaybe
77-
& fmap snd
78-
& (>>= jwtExp)
79-
case maybeExp of
75+
let maybeExpiry = do
76+
(_, claims) <- decodeClaims (Text.encodeUtf8 idToken)
77+
& rightToMaybe
78+
jwtExp claims
79+
case maybeExpiry of
8080
Nothing -> fetchToken auth
81-
Just (IntDate expiryDate) -> if now < expiryDate
82-
then pure idToken
83-
else fetchToken auth
81+
Just (IntDate expiryDate) ->
82+
if now < expiryDate
83+
then pure idToken
84+
else fetchToken auth
8485

8586
fetchToken :: OIDCAuth -> IO Text
8687
fetchToken auth@(OIDCAuth{..}) = do
@@ -178,7 +179,6 @@ parseCAData :: TLS.ClientParams -> Map Text Text -> Maybe (IO (Either ParseCertE
178179
parseCAData tlsParams authInfo = do
179180
caBase64 <- Map.lookup "idp-certificate-authority-data" authInfo
180181
Just $ pure $ do
181-
caText <- Text.encodeUtf8 caBase64
182-
& B64.decode
182+
caText <- B64.decode (Text.encodeUtf8 caBase64)
183183
& mapLeft Base64ParsingFailed
184184
updateClientParams tlsParams caText

kubernetes-client/src/Kubernetes/Client/Config.hs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,13 @@ mkKubeClientConfig
6868
-> KubeConfigSource
6969
-> IO (NH.Manager, K.KubernetesClientConfig)
7070
mkKubeClientConfig oidcCache (KubeConfigFile f) = do
71-
kubeConfigFile <- decodeFileThrow f
72-
masterURI <- getCluster kubeConfigFile
73-
& fmap server
74-
& either (const $ pure "localhost:8080") return
75-
tlsParams <- defaultTLSClientParams
76-
& fmap (tlsValidation kubeConfigFile)
77-
& (>>= (addCACertData kubeConfigFile))
78-
& (>>= addCACertFile kubeConfigFile (takeDirectory f))
71+
kubeConfig <- decodeFileThrow f
72+
masterURI <- server <$> getCluster kubeConfig
73+
& either (const $ pure "localhost:8080") return
74+
tlsParams <- configureTLSParams kubeConfig (takeDirectory f)
7975
clientConfig <- K.newConfig & fmap (setMasterURI masterURI)
8076
(tlsParamsWithAuth, clientConfigWithAuth) <-
81-
case getAuthInfo kubeConfigFile of
77+
case getAuthInfo kubeConfig of
8278
Left _ -> return (tlsParams,clientConfig)
8379
Right (_, auth) -> applyAuthSettings oidcCache auth (tlsParams, clientConfig)
8480
mgr <- newManager tlsParamsWithAuth
@@ -112,6 +108,13 @@ newManager cp = NH.newManager (mkManagerSettings (TLSSettings cp) Nothing)
112108
serviceAccountDir :: FilePath
113109
serviceAccountDir = "/var/run/secrets/kubernetes.io/serviceaccount"
114110

111+
configureTLSParams :: Config -> FilePath -> IO TLS.ClientParams
112+
configureTLSParams cfg dir = do
113+
defaultTLS <- defaultTLSClientParams
114+
withCACertData <- addCACertData cfg defaultTLS
115+
withCACertFile <- addCACertFile cfg dir withCACertData
116+
return $ tlsValidation cfg withCACertFile
117+
115118
tlsValidation :: Config -> TLS.ClientParams -> TLS.ClientParams
116119
tlsValidation cfg tlsParams =
117120
case getCluster cfg of

0 commit comments

Comments
 (0)