mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 04:51:35 +03:00
63 lines
1.8 KiB
Haskell
63 lines
1.8 KiB
Haskell
module Hasura.Server.Auth.JWT.Logging
|
|
( JwkRefreshLog (..)
|
|
, JwkRefreshHttpError (..)
|
|
, JwkLogNotice (..)
|
|
)
|
|
where
|
|
|
|
import Data.Aeson
|
|
|
|
import Hasura.HTTP
|
|
import Hasura.Logging (EngineLogType (..), Hasura, InternalLogTypes (..),
|
|
LogLevel (..), ToEngineLog (..))
|
|
import Hasura.Prelude
|
|
import Hasura.Server.Logging ()
|
|
import Hasura.Server.Utils (httpExceptToJSON)
|
|
|
|
import qualified Data.Text as T
|
|
import qualified Network.HTTP.Types as HTTP
|
|
|
|
|
|
data JwkLogNotice
|
|
= JLNInfo !Text
|
|
| JLNError !Text
|
|
deriving (Show)
|
|
|
|
data JwkRefreshLog
|
|
= JwkRefreshLog
|
|
{ jrlLogLevel :: !LogLevel
|
|
, jrlNotice :: !JwkLogNotice
|
|
, jrlHttpError :: !(Maybe JwkRefreshHttpError)
|
|
} deriving (Show)
|
|
|
|
data JwkRefreshHttpError
|
|
= JwkRefreshHttpError
|
|
{ jrheStatus :: !(Maybe HTTP.Status)
|
|
, jrheUrl :: !T.Text
|
|
, jrheHttpException :: !(Maybe HttpException)
|
|
, 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" .= (httpExceptToJSON . unHttpException <$> jrheHttpException jhe)
|
|
]
|
|
|
|
instance ToJSON JwkRefreshLog where
|
|
toJSON jrl = case jrlNotice jrl of
|
|
JLNInfo info ->
|
|
object [ "message" .= info
|
|
, "http_error" .= (toJSON <$> jrlHttpError jrl)
|
|
]
|
|
JLNError err ->
|
|
object [ "error" .= err
|
|
, "http_error" .= (toJSON <$> jrlHttpError jrl)
|
|
]
|
|
|
|
instance ToEngineLog JwkRefreshLog Hasura where
|
|
toEngineLog jwkRefreshLog =
|
|
(jrlLogLevel jwkRefreshLog, ELTInternal ILTJwkRefreshLog, toJSON jwkRefreshLog)
|