Skip to content

Commit 3f78615

Browse files
taimoorzaeemsteve-chavez
authored andcommitted
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`.
1 parent db85e64 commit 3f78615

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

postgrest.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ library
4949
PostgREST.App
5050
PostgREST.AppState
5151
PostgREST.Auth
52+
PostgREST.Auth.Types
5253
PostgREST.CLI
5354
PostgREST.Config
5455
PostgREST.Config.Database

src/PostgREST/App.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import qualified PostgREST.Unix as Unix (installSignalHandlers)
4242

4343
import PostgREST.ApiRequest (ApiRequest (..))
4444
import PostgREST.AppState (AppState)
45-
import PostgREST.Auth (AuthResult (..))
45+
import PostgREST.Auth.Types (AuthResult (..))
4646
import PostgREST.Config (AppConfig (..), LogLevel (..))
4747
import PostgREST.Config.PgVersion (PgVersion (..))
4848
import PostgREST.Error (Error)

src/PostgREST/AppState.hs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
module PostgREST.AppState
66
( AppState
7-
, AuthResult(..)
87
, destroy
98
, getConfig
109
, getSchemaCache
@@ -31,8 +30,6 @@ module PostgREST.AppState
3130
, isPending
3231
) where
3332

34-
import qualified Data.Aeson as JSON
35-
import qualified Data.Aeson.KeyMap as KM
3633
import qualified Data.ByteString.Char8 as BS
3734
import qualified Data.Cache as C
3835
import Data.Either.Combinators (whenLeft)
@@ -60,6 +57,7 @@ import Data.IORef (IORef, atomicWriteIORef, newIORef,
6057
readIORef)
6158
import Data.Time.Clock (UTCTime, getCurrentTime)
6259

60+
import PostgREST.Auth.Types (AuthResult)
6361
import PostgREST.Config (AppConfig (..),
6462
addFallbackAppName,
6563
readAppConfig)
@@ -78,11 +76,6 @@ import Data.Streaming.Network (bindPortTCP, bindRandomPortTCP)
7876
import Data.String (IsString (..))
7977
import Protolude
8078

81-
data AuthResult = AuthResult
82-
{ authClaims :: KM.KeyMap JSON.Value
83-
, authRole :: BS.ByteString
84-
}
85-
8679
data AppState = AppState
8780
-- | Database connection pool
8881
{ statePool :: SQL.Pool

src/PostgREST/Auth.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ very simple authentication system inside the PostgreSQL database.
1212
-}
1313
{-# LANGUAGE RecordWildCards #-}
1414
module PostgREST.Auth
15-
( AuthResult (..)
16-
, getResult
15+
( getResult
1716
, getJwtDur
1817
, getRole
1918
, middleware
@@ -45,11 +44,12 @@ import System.Clock (TimeSpec (..))
4544
import System.IO.Unsafe (unsafePerformIO)
4645
import System.TimeIt (timeItT)
4746

48-
import PostgREST.AppState (AppState, AuthResult (..), getConfig,
49-
getJwtCache, getTime)
50-
import PostgREST.Config (AppConfig (..), FilterExp (..), JSPath,
51-
JSPathExp (..))
52-
import PostgREST.Error (Error (..))
47+
import PostgREST.AppState (AppState, getConfig, getJwtCache,
48+
getTime)
49+
import PostgREST.Auth.Types (AuthResult (..))
50+
import PostgREST.Config (AppConfig (..), FilterExp (..), JSPath,
51+
JSPathExp (..))
52+
import PostgREST.Error (Error (..))
5353

5454
import Protolude
5555

src/PostgREST/Auth/Types.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module PostgREST.Auth.Types
2+
( AuthResult (..) )
3+
where
4+
5+
import qualified Data.Aeson as JSON
6+
import qualified Data.Aeson.KeyMap as KM
7+
import qualified Data.ByteString as BS
8+
9+
-- | Parse result for JWT Claims
10+
data AuthResult = AuthResult
11+
{ authClaims :: KM.KeyMap JSON.Value
12+
, authRole :: BS.ByteString
13+
}

src/PostgREST/Query.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import PostgREST.ApiRequest.Preferences (PreferCount (..),
3737
PreferTransaction (..),
3838
Preferences (..),
3939
shouldCount)
40-
import PostgREST.Auth (AuthResult (..))
40+
import PostgREST.Auth.Types (AuthResult (..))
4141
import PostgREST.Config (AppConfig (..),
4242
OpenAPIMode (..))
4343
import PostgREST.Config.PgVersion (PgVersion (..))

0 commit comments

Comments
 (0)