mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 20:41:49 +03:00
24592a516b
* Pass environment variables around as a data structure, via @sordina * Resolving build error * Adding Environment passing note to changelog * Removing references to ILTPollerLog as this seems to have been reintroduced from a bad merge * removing commented-out imports * Language pragmas already set by project * Linking async thread * Apply suggestions from code review Use `runQueryTx` instead of `runLazyTx` for queries. * remove the non-user facing entry in the changelog Co-authored-by: Phil Freeman <paf31@cantab.net> Co-authored-by: Phil Freeman <phil@hasura.io> Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
65 lines
2.0 KiB
Haskell
65 lines
2.0 KiB
Haskell
module Hasura.Server.Auth.JWT.Logging
|
|
( JwkRefreshLog (..)
|
|
, JwkFetchError (..)
|
|
)
|
|
where
|
|
|
|
import Data.Aeson
|
|
import Hasura.HTTP
|
|
import Hasura.Logging (EngineLogType (..), Hasura, InternalLogTypes (..),
|
|
LogLevel (..), ToEngineLog (..))
|
|
import Hasura.Prelude
|
|
import Hasura.Server.Logging ()
|
|
import Network.URI (URI)
|
|
|
|
import qualified Data.ByteString.Lazy as BL
|
|
import qualified Data.Text as T
|
|
import qualified Network.HTTP.Types as HTTP
|
|
|
|
-- | Possible errors during fetching and parsing JWK
|
|
-- (the 'Text' type at the end is a friendly error message)
|
|
data JwkFetchError
|
|
= JFEHttpException !HttpException !Text
|
|
-- ^ Exception while making the HTTP request
|
|
| JFEHttpError !URI !HTTP.Status !BL.ByteString !Text
|
|
-- ^ Non-2xx HTTP errors from the upstream server
|
|
| JFEJwkParseError !Text !Text
|
|
-- ^ Error parsing the JWK response itself
|
|
| JFEExpiryParseError !(Maybe Text) Text
|
|
-- ^ Error parsing the expiry of the JWK
|
|
deriving (Show)
|
|
|
|
instance ToJSON JwkFetchError where
|
|
toJSON = \case
|
|
JFEHttpException e _ ->
|
|
object [ "http_exception" .= e ]
|
|
|
|
JFEHttpError url status body _ ->
|
|
object [ "status_code" .= HTTP.statusCode status
|
|
, "url" .= T.pack (show url)
|
|
, "response" .= bsToTxt (BL.toStrict body)
|
|
]
|
|
|
|
JFEJwkParseError e msg ->
|
|
object [ "error" .= e, "message" .= msg ]
|
|
|
|
JFEExpiryParseError e msg ->
|
|
object [ "error" .= e, "message" .= msg ]
|
|
|
|
data JwkRefreshLog
|
|
= JwkRefreshLog
|
|
{ jrlLogLevel :: !LogLevel
|
|
, jrlMessage :: !(Maybe Text)
|
|
, jrlError :: !(Maybe JwkFetchError)
|
|
} deriving (Show)
|
|
|
|
instance ToJSON JwkRefreshLog where
|
|
toJSON (JwkRefreshLog _ msg err) =
|
|
object [ "message" .= msg
|
|
, "error" .= err
|
|
]
|
|
|
|
instance ToEngineLog JwkRefreshLog Hasura where
|
|
toEngineLog jwkRefreshLog =
|
|
(jrlLogLevel jwkRefreshLog, ELTInternal ILTJwkRefreshLog, toJSON jwkRefreshLog)
|