2018-09-27 14:22:49 +03:00
|
|
|
module Hasura.Server.Auth.JWT.Logging
|
|
|
|
( JwkRefreshLog (..)
|
|
|
|
, JwkRefreshHttpError (..)
|
2019-08-01 13:51:59 +03:00
|
|
|
, JwkLogNotice (..)
|
2018-09-27 14:22:49 +03:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Data.Aeson
|
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
import Hasura.HTTP
|
2019-12-13 00:46:33 +03:00
|
|
|
import Hasura.Logging (EngineLogType (..), Hasura, InternalLogTypes (..),
|
|
|
|
LogLevel (..), ToEngineLog (..))
|
2018-09-27 14:22:49 +03:00
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.Server.Logging ()
|
2019-08-01 13:51:59 +03:00
|
|
|
import Hasura.Server.Utils (httpExceptToJSON)
|
2018-09-27 14:22:49 +03:00
|
|
|
|
|
|
|
import qualified Data.Text as T
|
|
|
|
import qualified Network.HTTP.Types as HTTP
|
|
|
|
|
|
|
|
|
2019-08-01 13:51:59 +03:00
|
|
|
data JwkLogNotice
|
|
|
|
= JLNInfo !Text
|
|
|
|
| JLNError !Text
|
|
|
|
deriving (Show)
|
|
|
|
|
2018-09-27 14:22:49 +03:00
|
|
|
data JwkRefreshLog
|
|
|
|
= JwkRefreshLog
|
|
|
|
{ jrlLogLevel :: !LogLevel
|
2019-08-01 13:51:59 +03:00
|
|
|
, jrlNotice :: !JwkLogNotice
|
2018-09-27 14:22:49 +03:00
|
|
|
, 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
|
2019-08-01 13:51:59 +03:00
|
|
|
, "http_exception" .= (httpExceptToJSON . unHttpException <$> jrheHttpException jhe)
|
2018-09-27 14:22:49 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
instance ToJSON JwkRefreshLog where
|
2019-08-01 13:51:59 +03:00
|
|
|
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)
|
|
|
|
]
|
2018-09-27 14:22:49 +03:00
|
|
|
|
2019-11-26 15:14:21 +03:00
|
|
|
instance ToEngineLog JwkRefreshLog Hasura where
|
2018-09-27 14:22:49 +03:00
|
|
|
toEngineLog jwkRefreshLog =
|
2019-11-26 15:14:21 +03:00
|
|
|
(jrlLogLevel jwkRefreshLog, ELTInternal ILTJwkRefreshLog, toJSON jwkRefreshLog)
|