Bound authentication probe startup synchronization

This commit is contained in:
ms2k 2026-07-20 05:22:08 +09:00
commit b196f9e17b

View file

@ -1,14 +1,16 @@
module Main (main) where
import Control.Concurrent (threadDelay)
import Control.Exception (throwIO, try)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Base16 as B16
import qualified Data.ByteString.Char8 as B8
import Data.List (find)
import System.Entropy (getEntropy)
import Nuthatch.Probe.Assert
import Nuthatch.Probe.Curl
import Nuthatch.Probe.Oidc
import Nuthatch.Probe.ProductClient
import System.Entropy (getEntropy)
import System.IO.Temp (withSystemTempDirectory)
main :: IO ()
@ -17,6 +19,7 @@ main =
context <- newProbeContext directory
runId <- B8.unpack . B16.encode <$> getEntropy 8
verifyCredentialScope
waitForApplication context
verifyPublicBoundary context
userA <- requireEnv "NUTHATCH_OIDC_USER_A"
sessionA <- login context True userA "a"
@ -28,6 +31,25 @@ main =
verifyLogout context sessionA
putStrLn "OIDC application boundary passed"
waitForApplication :: ProbeContext -> IO ()
waitForApplication context = go 30
where
go :: Int -> IO ()
go remaining = do
result <-
try (curl
[ "--connect-timeout", "1"
, "--max-time", "2"
, probeBase context <> "/readyz"
])
:: IO (Either CurlTransportFailure CurlResponse)
case result of
Right _ -> pure ()
Left failure
| curlTransportExitCode failure == 7 && remaining > 1 ->
threadDelay 1000000 >> go (remaining - 1)
| otherwise -> throwIO failure
verifyCredentialScope :: IO ()
verifyCredentialScope = do
endpoint <- requireEnv "NUTHATCH_S3_ENDPOINT"