@@ -198,22 +198,22 @@ data Credentials
198198--
199199-- Throws 'AuthError' when environment variables or service account information
200200-- cannot be read, and credentials files are invalid or cannot be found.
201−getAuth :: (MonadIO m, MonadCatch m) => Manager -> Credentials -> m Auth
202−getAuth m = \case
201+getAuth :: (MonadIO m, MonadCatch m) => Credentials -> Manager -> m Auth
202+getAuth c m = case c of
203203 FromToken t -> pure (AuthToken t)
204− FromFile f -> fromFilePath m f
205− FromAccount s -> fromMetadata m s
204+ FromFile f -> fromFilePath f m
205+ FromAccount s -> fromMetadata s m
206206 Discover ->
207207 catching _MissingFileError (fromFile m) $ \f -> do
208208 p <- isGCE m
209209 unless p $
210210 throwingM _MissingFileError f
211− fromMetadata m "default"
211+ fromMetadata "default" m
212212
213213-- | Refresh a token from the local GCE metadata endpoint for the specified
214214-- 'ServiceId'.
215−fromMetadata :: (MonadIO m, MonadCatch m) => Manager -> ServiceId -> m Auth
216−fromMetadata m = refresh m >=> fmap AuthMeta . liftIO . newMVar
215+fromMetadata :: (MonadIO m, MonadCatch m) => ServiceId -> Manager -> m Auth
216+fromMetadata s = refresh s >=> fmap AuthMeta . liftIO . newMVar
217217
218218-- | Attempt to load either a @service_account@ or @authorized_user@ formatted
219219-- file to obtain the credentials neccessary to perform a token refresh.
@@ -221,22 +221,24 @@ fromFile :: (MonadIO m, MonadCatch m) => Manager -> m Auth
221221fromFile m = do
222222 f <- defaultCredentialsPath
223223 case f of
224− Just x -> fromFilePath m x
225− Nothing -> cloudSDKConfigPath >>= fromFilePath m
224+ Just x -> fromFilePath x m
225+ Nothing -> do
226+ x <- cloudSDKConfigPath
227+ fromFilePath x m
226228
227229-- | Attempt to load either a @service_account@ or @authorized_user@ formatted
228230-- file to obtain the credentials neccessary to perform a token refresh from
229231-- the specified file.
230−fromFilePath :: (MonadIO m, MonadCatch m) => Manager -> FilePath -> m Auth
231−fromFilePath m f = do
232+fromFilePath :: (MonadIO m, MonadCatch m) => FilePath -> Manager -> m Auth
233+fromFilePath f m = do
232234 p <- liftIO (doesFileExist f)
233235 unless p $
234236 throwM (MissingFileError f)
235237 e <- liftIO (LBS.readFile f) >>=
236238 either (throwM . InvalidFileError f) pure . parseLBS
237239 case e of
238− Left a -> refresh m a >>= fmap AuthSign . liftIO . newMVar
239− Right u -> refresh m u >>= fmap AuthUser . liftIO . newMVar
240+ Left a -> refresh a m >>= fmap AuthSign . liftIO . newMVar
241+ Right u -> refresh u m >>= fmap AuthUser . liftIO . newMVar
240242
241243-- | Lookup the @GOOGLE_APPLICATION_CREDENTIALS@ environment variable for the
242244-- default application credentials filepath.
@@ -324,7 +326,7 @@ refreshToken m r = do
324326 if yv
325327 then pure (y, _token y)
326328 else do
327− z <- refresh m (_details y)
329+ z <- refresh (_details y) m
328330 pure (z, _token z)
329331
330332-- {
@@ -398,17 +400,18 @@ instance FromJSON AuthorisedUser where
398400 <*> o .: "refresh_token"
399401
400402class Refresh a where
401− refresh :: (MonadIO m, MonadCatch m) => Manager -> a -> m (Expires a)
403+ refresh :: (MonadIO m, MonadCatch m) => a -> Manager -> m (Expires a)
402404
403405instance Refresh ServiceAccount where
404− refresh m s = do
406+ refresh s m = do
405407 b <- jwtEncode s
406− refreshRequest m s $ accountsRequest
407− { Client.requestBody = RequestBodyBS $
408− "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer"
409− <> "&assertion="
410− <> b
411− }
408+ let rq = accountsRequest
409+ { Client.requestBody = RequestBodyBS $
410+ "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer"
411+ <> "&assertion="
412+ <> b
413+ }
414+ refreshRequest s rq m
412415
413416jwtEncode :: (MonadIO m, MonadThrow m) => ServiceAccount -> m ByteString
414417jwtEncode s = liftIO $ do
@@ -443,7 +446,7 @@ jwtEncode s = liftIO $ do
443446 ]
444447
445448instance Refresh AuthorisedUser where
446− refresh m u@AuthorisedUser{..} = refreshRequest m u $
449+ refresh u@AuthorisedUser{..} = refreshRequest u $
447450 accountsRequest
448451 { Client.requestBody = RequestBodyBS . Text.encodeUtf8 $
449452 "grant_type=refresh_token"
@@ -453,7 +456,7 @@ instance Refresh AuthorisedUser where
453456 }
454457
455458instance Refresh ServiceId where
456− refresh m sid = refreshRequest m sid $
459+ refresh sid = refreshRequest sid $
457460 metadataRequest
458461 { Client.path = "instance/service-accounts/"
459462 <> Text.encodeUtf8 (serviceIdToText sid)
@@ -472,11 +475,11 @@ accountsRequest = def
472475 }
473476
474477refreshRequest :: (MonadIO m, MonadCatch m)
475− => Manager
476− -> a
478+ => a
477479 -> Client.Request
480+ -> Manager
478481 -> m (Expires a)
479−refreshRequest m r rq = do
482+refreshRequest r rq m = do
480483 rs <- liftIO (httpLbs rq m) `catch` (throwM . RetrievalError)
481484 let bs = responseBody rs
482485 s = responseStatus rs