2018-09-27 14:22:49 +03:00
|
|
|
module Hasura.Server.Auth.JWT.Logging
|
|
|
|
( JwkRefreshLog (..)
|
|
|
|
, JwkRefreshHttpError (..)
|
|
|
|
, mkJwkRefreshLog
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Data.Aeson
|
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
import Hasura.HTTP
|
2018-09-27 14:22:49 +03:00
|
|
|
import Hasura.Logging (LogLevel (..), ToEngineLog (..))
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.Server.Logging ()
|
|
|
|
|
|
|
|
import qualified Data.Text as T
|
|
|
|
import qualified Network.HTTP.Types as HTTP
|
|
|
|
|
|
|
|
|
|
|
|
data JwkRefreshLog
|
|
|
|
= JwkRefreshLog
|
|
|
|
{ jrlLogLevel :: !LogLevel
|
|
|
|
, jrlError :: !T.Text
|
|
|
|
, jrlHttpError :: !(Maybe JwkRefreshHttpError)
|
|
|
|
} deriving (Show)
|
|
|
|
|
|
|
|
data JwkRefreshHttpError
|
|
|
|
= JwkRefreshHttpError
|
|
|
|
{ jrheStatus :: !(Maybe HTTP.Status)
|
|
|
|
, jrheUrl :: !T.Text
|
2018-12-13 10:26:15 +03:00
|
|
|
, jrheHttpException :: !(Maybe HttpException)
|
2018-09-27 14:22:49 +03:00
|
|
|
, jrheResponse :: !(Maybe T.Text)
|
|
|
|
} deriving (Show)
|
|
|
|
|
|
|
|
instance ToJSON JwkRefreshHttpError where
|
|
|
|
toJSON jhe =
|
|
|
|
object [ "status_code" .= (HTTP.statusCode <$> jrheStatus jhe)
|
|
|
|
, "url" .= jrheUrl jhe
|
|
|
|
, "response" .= jrheResponse jhe
|
|
|
|
, "http_exception" .= (toJSON <$> jrheHttpException jhe)
|
|
|
|
]
|
|
|
|
|
|
|
|
instance ToJSON JwkRefreshLog where
|
|
|
|
toJSON jrl =
|
|
|
|
object [ "error" .= jrlError jrl
|
|
|
|
, "http_error" .= (toJSON <$> jrlHttpError jrl)
|
|
|
|
]
|
|
|
|
|
|
|
|
instance ToEngineLog JwkRefreshLog where
|
|
|
|
toEngineLog jwkRefreshLog =
|
|
|
|
(jrlLogLevel jwkRefreshLog, "jwk-refresh-log", toJSON jwkRefreshLog)
|
|
|
|
|
|
|
|
mkJwkRefreshLog :: T.Text -> Maybe JwkRefreshHttpError -> JwkRefreshLog
|
|
|
|
mkJwkRefreshLog = JwkRefreshLog (LevelOther "critical")
|