Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a bit more logging at info level #130

Merged
merged 1 commit into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Control.Applicative ((<|>))
import Control.Concurrent.QSem (newQSem, waitQSem, signalQSem)
import Control.Exception (Handler (..), bracket_, catch, catches)
import Control.Monad (forM)
import Control.Monad (forM, when)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Aeson (FromJSON, (.:))
import Data.Aeson.Types (parseMaybe)
Expand Down Expand Up @@ -352,8 +352,10 @@ vaultEnv originalContext =
handleVaultAuthResponse context f =
catch f httpErrorHandler >>= \case
Left vaultError -> pure $ Left vaultError
Right (ClientToken token) -> pure $
Right context
Right (ClientToken token) -> do
when (getOptionsValue oLogLevel (cCliOptions context) <= Info) $
putStrLn "[INFO] Authentication successful, we have a VAULT_TOKEN now."
pure $ Right context
{ cCliOptions = (cCliOptions context)
{ oAuthMethod = AuthVaultToken token
}
Expand Down Expand Up @@ -464,6 +466,8 @@ requestGitHubVaultToken context ghtoken = let
-- | Authenticate using Kubernetes auth, see https://www.vaultproject.io/docs/auth/kubernetes.
requestKubernetesVaultToken :: Context -> Text -> IO (Either VaultError ClientToken)
requestKubernetesVaultToken context role = do
when (getOptionsValue oLogLevel (cCliOptions context) <= Info) $
putStrLn "[INFO] Authenticating with Kubernetes ..."
jwtResult <- readKubernetesJwt
case jwtResult of
Left err -> pure $ Left err
Expand Down Expand Up @@ -517,7 +521,9 @@ requestSecret context secretPath =
getSecret :: Retry.RetryStatus -> IO (Either VaultError VaultData)
getSecret _retryStatus = catch (doRequest secretPath request) httpErrorHandler

in
in do
when (getOptionsValue oLogLevel (cCliOptions context) <= Info) $
putStrLn $ "[INFO] Getting " <> secretPath <> " ..."
doWithRetries retryPolicy getSecret

-- | Request all the supplied secrets from the vault, but just once, even if
Expand Down