refactor: move AuthResult to Auth/Types.hs module

The `AuthResult` type does not belong to AppState
module. This commit refactor this by moving it to
a new module `Auth/Types.hs`.
This commit is contained in:
M. Taimoor Zaeem
2025-02-04 11:56:42 -05:00
committed by Steve Chavez
parent db85e64971
commit 3f78615dff
6 changed files with 24 additions and 17 deletions
+1
View File
@@ -49,6 +49,7 @@ library
PostgREST.App
PostgREST.AppState
PostgREST.Auth
PostgREST.Auth.Types
PostgREST.CLI
PostgREST.Config
PostgREST.Config.Database
+1 -1
View File
@@ -42,7 +42,7 @@ import qualified PostgREST.Unix as Unix (installSignalHandlers)
import PostgREST.ApiRequest (ApiRequest (..))
import PostgREST.AppState (AppState)
import PostgREST.Auth (AuthResult (..))
import PostgREST.Auth.Types (AuthResult (..))
import PostgREST.Config (AppConfig (..), LogLevel (..))
import PostgREST.Config.PgVersion (PgVersion (..))
import PostgREST.Error (Error)
+1 -8
View File
@@ -4,7 +4,6 @@
module PostgREST.AppState
( AppState
, AuthResult(..)
, destroy
, getConfig
, getSchemaCache
@@ -31,8 +30,6 @@ module PostgREST.AppState
, isPending
) where
import qualified Data.Aeson as JSON
import qualified Data.Aeson.KeyMap as KM
import qualified Data.ByteString.Char8 as BS
import qualified Data.Cache as C
import Data.Either.Combinators (whenLeft)
@@ -60,6 +57,7 @@ import Data.IORef (IORef, atomicWriteIORef, newIORef,
readIORef)
import Data.Time.Clock (UTCTime, getCurrentTime)
import PostgREST.Auth.Types (AuthResult)
import PostgREST.Config (AppConfig (..),
addFallbackAppName,
readAppConfig)
@@ -78,11 +76,6 @@ import Data.Streaming.Network (bindPortTCP, bindRandomPortTCP)
import Data.String (IsString (..))
import Protolude
data AuthResult = AuthResult
{ authClaims :: KM.KeyMap JSON.Value
, authRole :: BS.ByteString
}
data AppState = AppState
-- | Database connection pool
{ statePool :: SQL.Pool
+7 -7
View File
@@ -12,8 +12,7 @@ very simple authentication system inside the PostgreSQL database.
-}
{-# LANGUAGE RecordWildCards #-}
module PostgREST.Auth
( AuthResult (..)
, getResult
( getResult
, getJwtDur
, getRole
, middleware
@@ -45,11 +44,12 @@ import System.Clock (TimeSpec (..))
import System.IO.Unsafe (unsafePerformIO)
import System.TimeIt (timeItT)
import PostgREST.AppState (AppState, AuthResult (..), getConfig,
getJwtCache, getTime)
import PostgREST.Config (AppConfig (..), FilterExp (..), JSPath,
JSPathExp (..))
import PostgREST.Error (Error (..))
import PostgREST.AppState (AppState, getConfig, getJwtCache,
getTime)
import PostgREST.Auth.Types (AuthResult (..))
import PostgREST.Config (AppConfig (..), FilterExp (..), JSPath,
JSPathExp (..))
import PostgREST.Error (Error (..))
import Protolude
+13
View File
@@ -0,0 +1,13 @@
module PostgREST.Auth.Types
( AuthResult (..) )
where
import qualified Data.Aeson as JSON
import qualified Data.Aeson.KeyMap as KM
import qualified Data.ByteString as BS
-- | Parse result for JWT Claims
data AuthResult = AuthResult
{ authClaims :: KM.KeyMap JSON.Value
, authRole :: BS.ByteString
}
+1 -1
View File
@@ -37,7 +37,7 @@ import PostgREST.ApiRequest.Preferences (PreferCount (..),
PreferTransaction (..),
Preferences (..),
shouldCount)
import PostgREST.Auth (AuthResult (..))
import PostgREST.Auth.Types (AuthResult (..))
import PostgREST.Config (AppConfig (..),
OpenAPIMode (..))
import PostgREST.Config.PgVersion (PgVersion (..))