graphql-engine/server/src-lib/Hasura/Server/Auth/JWT/Logging.hs
Vamshi Surabhi ec8b2c80b5
refactor to remove warnings especially with orphan instances (#1163)
* remove phase one/two distinction and hdbquery typeclass

* move extensions to default-extensions

* switch to LazyTx which only acquires a connection if needed

* move defns from TH module into Ops module

* remove tojson orphan instance for http exception

* remove orphan instance for dmlp1

* getTopLevelNodes will not throw any exceptions
2018-12-13 12:56:15 +05:30

54 lines
1.5 KiB
Haskell

module Hasura.Server.Auth.JWT.Logging
( JwkRefreshLog (..)
, JwkRefreshHttpError (..)
, mkJwkRefreshLog
)
where
import Data.Aeson
import Hasura.HTTP
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
, 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" .= (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")