Skip to content

Commit 547b5af

Browse files
committed
Remove error calls from GCP Auth
1 parent df543b9 commit 547b5af

File tree

1 file changed

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

1 file changed

+13
-7
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Kubernetes.Client.Auth.GCP
55
where
66

77
import Control.Concurrent.STM
8+
import Control.Exception.Safe (Exception, throwM)
89
import Data.Attoparsec.Text
910
import Data.Either.Combinators
1011
import Data.Function ((&))
@@ -36,7 +37,8 @@ data GCPAuth = GCPAuth { gcpAccessToken :: TVar(Maybe Text)
3637

3738
instance AuthMethod GCPAuth where
3839
applyAuthMethod _ gcp req = do
39-
token <- getToken gcp >>= exceptEither
40+
token <- getToken gcp
41+
>>= either (throwM . GCPGetTokenException) pure
4042
pure
4143
$ setHeader req [("Authorization", "Bearer " <> (Text.encodeUtf8 token))]
4244
& L.set rAuthTypesL []
@@ -45,15 +47,19 @@ instance AuthMethod GCPAuth where
4547
gcpAuth :: DetectAuth
4648
gcpAuth AuthInfo{authProvider = Just(AuthProviderConfig "gcp" (Just cfg))} (tls, kubecfg)
4749
= Just $ do
48-
configOfErr <- parseGCPAuthInfo cfg
49-
case configOfErr of
50-
Left e -> error e
50+
configOrErr <- parseGCPAuthInfo cfg
51+
case configOrErr of
52+
Left e -> throwM $ GCPAuthParsingException e
5153
Right gcp -> pure (tls, addAuthMethod kubecfg gcp)
5254
gcpAuth _ _ = Nothing
5355

54-
exceptEither :: Either String a -> IO a
55-
exceptEither (Right a) = pure a
56-
exceptEither (Left t) = error (show t)
56+
data GCPAuthParsingException = GCPAuthParsingException String
57+
deriving Show
58+
instance Exception GCPAuthParsingException
59+
60+
data GCPGetTokenException = GCPGetTokenException String
61+
deriving Show
62+
instance Exception GCPGetTokenException
5763

5864
getToken :: GCPAuth -> IO (Either String Text)
5965
getToken g@(GCPAuth{..}) = getCurrentToken g

0 commit comments

Comments
 (0)