@@ -5,6 +5,7 @@ module Kubernetes.Client.Auth.GCP
5
5
where
6
6
7
7
import Control.Concurrent.STM
8
+ import Control.Exception.Safe (Exception , throwM )
8
9
import Data.Attoparsec.Text
9
10
import Data.Either.Combinators
10
11
import Data.Function ((&) )
@@ -36,7 +37,8 @@ data GCPAuth = GCPAuth { gcpAccessToken :: TVar(Maybe Text)
36
37
37
38
instance AuthMethod GCPAuth where
38
39
applyAuthMethod _ gcp req = do
39
- token <- getToken gcp >>= exceptEither
40
+ token <- getToken gcp
41
+ >>= either (throwM . GCPGetTokenException ) pure
40
42
pure
41
43
$ setHeader req [(" Authorization" , " Bearer " <> (Text. encodeUtf8 token))]
42
44
& L. set rAuthTypesL []
@@ -45,15 +47,19 @@ instance AuthMethod GCPAuth where
45
47
gcpAuth :: DetectAuth
46
48
gcpAuth AuthInfo {authProvider = Just (AuthProviderConfig " gcp" (Just cfg))} (tls, kubecfg)
47
49
= 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
51
53
Right gcp -> pure (tls, addAuthMethod kubecfg gcp)
52
54
gcpAuth _ _ = Nothing
53
55
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
57
63
58
64
getToken :: GCPAuth -> IO (Either String Text )
59
65
getToken g@ (GCPAuth {.. }) = getCurrentToken g
0 commit comments