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.App
PostgREST.AppState PostgREST.AppState
PostgREST.Auth PostgREST.Auth
PostgREST.Auth.Types
PostgREST.CLI PostgREST.CLI
PostgREST.Config PostgREST.Config
PostgREST.Config.Database PostgREST.Config.Database
+1 -1
View File
@@ -42,7 +42,7 @@ import qualified PostgREST.Unix as Unix (installSignalHandlers)
import PostgREST.ApiRequest (ApiRequest (..)) import PostgREST.ApiRequest (ApiRequest (..))
import PostgREST.AppState (AppState) import PostgREST.AppState (AppState)
import PostgREST.Auth (AuthResult (..)) import PostgREST.Auth.Types (AuthResult (..))
import PostgREST.Config (AppConfig (..), LogLevel (..)) import PostgREST.Config (AppConfig (..), LogLevel (..))
import PostgREST.Config.PgVersion (PgVersion (..)) import PostgREST.Config.PgVersion (PgVersion (..))
import PostgREST.Error (Error) import PostgREST.Error (Error)
+1 -8
View File
@@ -4,7 +4,6 @@
module PostgREST.AppState module PostgREST.AppState
( AppState ( AppState
, AuthResult(..)
, destroy , destroy
, getConfig , getConfig
, getSchemaCache , getSchemaCache
@@ -31,8 +30,6 @@ module PostgREST.AppState
, isPending , isPending
) where ) where
import qualified Data.Aeson as JSON
import qualified Data.Aeson.KeyMap as KM
import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Char8 as BS
import qualified Data.Cache as C import qualified Data.Cache as C
import Data.Either.Combinators (whenLeft) import Data.Either.Combinators (whenLeft)
@@ -60,6 +57,7 @@ import Data.IORef (IORef, atomicWriteIORef, newIORef,
readIORef) readIORef)
import Data.Time.Clock (UTCTime, getCurrentTime) import Data.Time.Clock (UTCTime, getCurrentTime)
import PostgREST.Auth.Types (AuthResult)
import PostgREST.Config (AppConfig (..), import PostgREST.Config (AppConfig (..),
addFallbackAppName, addFallbackAppName,
readAppConfig) readAppConfig)
@@ -78,11 +76,6 @@ import Data.Streaming.Network (bindPortTCP, bindRandomPortTCP)
import Data.String (IsString (..)) import Data.String (IsString (..))
import Protolude import Protolude
data AuthResult = AuthResult
{ authClaims :: KM.KeyMap JSON.Value
, authRole :: BS.ByteString
}
data AppState = AppState data AppState = AppState
-- | Database connection pool -- | Database connection pool
{ statePool :: SQL.Pool { statePool :: SQL.Pool
+7 -7
View File
@@ -12,8 +12,7 @@ very simple authentication system inside the PostgreSQL database.
-} -}
{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE RecordWildCards #-}
module PostgREST.Auth module PostgREST.Auth
( AuthResult (..) ( getResult
, getResult
, getJwtDur , getJwtDur
, getRole , getRole
, middleware , middleware
@@ -45,11 +44,12 @@ import System.Clock (TimeSpec (..))
import System.IO.Unsafe (unsafePerformIO) import System.IO.Unsafe (unsafePerformIO)
import System.TimeIt (timeItT) import System.TimeIt (timeItT)
import PostgREST.AppState (AppState, AuthResult (..), getConfig, import PostgREST.AppState (AppState, getConfig, getJwtCache,
getJwtCache, getTime) getTime)
import PostgREST.Config (AppConfig (..), FilterExp (..), JSPath, import PostgREST.Auth.Types (AuthResult (..))
JSPathExp (..)) import PostgREST.Config (AppConfig (..), FilterExp (..), JSPath,
import PostgREST.Error (Error (..)) JSPathExp (..))
import PostgREST.Error (Error (..))
import Protolude 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 (..), PreferTransaction (..),
Preferences (..), Preferences (..),
shouldCount) shouldCount)
import PostgREST.Auth (AuthResult (..)) import PostgREST.Auth.Types (AuthResult (..))
import PostgREST.Config (AppConfig (..), import PostgREST.Config (AppConfig (..),
OpenAPIMode (..)) OpenAPIMode (..))
import PostgREST.Config.PgVersion (PgVersion (..)) import PostgREST.Config.PgVersion (PgVersion (..))