refactor(settings): use better settings type names for user-auth

This commit is contained in:
Sarah Vaupel 2024-02-14 02:02:42 +01:00
parent 9597663881
commit 0c5f4cb430
3 changed files with 28 additions and 27 deletions

View File

@ -128,8 +128,8 @@ database:
auto-db-migrate: '_env:AUTO_DB_MIGRATE:true' auto-db-migrate: '_env:AUTO_DB_MIGRATE:true'
# External sources used for authentication and userdata lookups # External sources used for user authentication and userdata lookups
user-source: user-auth:
# mode: single-source # mode: single-source
protocol: azureadv2 protocol: azureadv2
config: config:
@ -155,6 +155,7 @@ ldap-pool:
timeout: "_env:LDAPTIMEOUT:20" timeout: "_env:LDAPTIMEOUT:20"
limit: "_env:LDAPLIMIT:10" limit: "_env:LDAPLIMIT:10"
# TODO: might move later
# user-retest-failover: 60 # user-retest-failover: 60
user-sync-within: "_env:USER_SYNC_WITHIN:1209600" # 14 Tage in Sekunden user-sync-within: "_env:USER_SYNC_WITHIN:1209600" # 14 Tage in Sekunden
user-sync-interval: "_env:USER_SYNC_INTERVAL:3600" # jede Stunde user-sync-interval: "_env:USER_SYNC_INTERVAL:3600" # jede Stunde

View File

@ -141,21 +141,22 @@ instance FromJSON PWHashConf where
return PWHashConf{..} return PWHashConf{..}
data UserSource = UserSourceLdap LdapConf | UserSourceAzureAdV2 AzureConf data AuthSourceConf = AuthSourceConfLdap LdapConf | AuthSourceConfAzureAdV2 AzureConf
deriving (Show) deriving (Show)
data UserSourceConf = data UserAuthConf =
UserSourceConfSingleSource -- ^ use only one specific source UserAuthConfSingleSource -- ^ use only one specific source
{ usersrcSingleSource :: UserSource { userAuthConfSingleSource :: AuthSourceConf
} }
-- TODO: other modes yet to be implemented -- TODO: other modes yet to be implemented
-- | UserFailover -- ^ use only one user source at a time, but failover to the next-best database if the current source is unavailable -- | UserAuthConfFailover -- ^ use only one user source at a time, but failover to the next-best database if the current source is unavailable
-- { usersrcFailoverSources :: PointedList UserSource -- { userAuthConfFailoverSources :: PointedList UserSource
-- , usersrcFailoverRetest :: NominalDiffTime -- , userAuthConfFailoverRetest :: NominalDiffTime
-- } -- }
-- | UserMultiSource -- ^ Multiple coequal user sources -- | UserAuthConfMultiSource -- ^ Multiple coequal user sources
-- { usersrcMultiSources :: Set UserSource -- { userAuthConfMultiSources :: Set UserSource
-- } -- }
-- | UserAuthConfNoSource -- ^ allow no external sources at all -- TODO: either this, or make user-auth in settings.yml optional
deriving (Show) deriving (Show)
data LmsConf = LmsConf data LmsConf = LmsConf
@ -308,21 +309,21 @@ pathPieceJSONKey ''SettingBotMitigation
makePrisms ''JobMode makePrisms ''JobMode
makeLenses_ ''JobMode makeLenses_ ''JobMode
makePrisms ''UserSource makePrisms ''AuthSourceConf
makeLenses_ ''UserSourceConf makeLenses_ ''UserAuthConf
makePrisms ''UserSourceConf makePrisms ''UserAuthConf
deriveFromJSON defaultOptions deriveFromJSON defaultOptions
{ constructorTagModifier = toLower . dropPrefix "UserSource" { constructorTagModifier = toLower . dropPrefix "AuthSourceConf"
, sumEncoding = TaggedObject "protocol" "config" , sumEncoding = TaggedObject "protocol" "config"
} ''UserSource } ''AuthSourceConf
deriveFromJSON defaultOptions deriveFromJSON defaultOptions
{ constructorTagModifier = camelToPathPiece' 3 { constructorTagModifier = camelToPathPiece' 3
, fieldLabelModifier = camelToPathPiece' 1 , fieldLabelModifier = camelToPathPiece' 3
, sumEncoding = UntaggedValue -- TaggedObject "mode" "config" , sumEncoding = UntaggedValue -- TaggedObject "mode" "config"
, unwrapUnaryRecords = True , unwrapUnaryRecords = True
} ''UserSourceConf } ''UserAuthConf
instance FromJSON HaskellNet.PortNumber where instance FromJSON HaskellNet.PortNumber where
parseJSON = withScientific "PortNumber" $ \sciNum -> case Scientific.toBoundedInteger sciNum of parseJSON = withScientific "PortNumber" $ \sciNum -> case Scientific.toBoundedInteger sciNum of
@ -450,7 +451,7 @@ data AppSettings = AppSettings
, appDatabaseConf :: PostgresConf , appDatabaseConf :: PostgresConf
-- ^ Configuration settings for accessing the database. -- ^ Configuration settings for accessing the database.
, appAutoDbMigrate :: Bool , appAutoDbMigrate :: Bool
, appUserSourceConf :: UserSourceConf , appUserAuthConf :: UserAuthConf
-- ^ Configuration settings for CSV export/import to LMS (= Learn Management System) -- ^ Configuration settings for CSV export/import to LMS (= Learn Management System)
, appLmsConf :: LmsConf , appLmsConf :: LmsConf
-- ^ Configuration settings for accessing the LDAP-directory -- ^ Configuration settings for accessing the LDAP-directory
@ -627,7 +628,7 @@ instance FromJSON AppSettings where
-- Ldap.Tls host _ -> not $ null host -- Ldap.Tls host _ -> not $ null host
-- Ldap.Plain host -> not $ null host -- Ldap.Plain host -> not $ null host
-- nonEmptyHost (UserDbOAuth2 OAuth2Conf{..}) = not $ or [ null oauth2TenantId, null oauth2ClientId, null oauth2ClientSecret ] -- nonEmptyHost (UserDbOAuth2 OAuth2Conf{..}) = not $ or [ null oauth2TenantId, null oauth2ClientId, null oauth2ClientSecret ]
appUserSourceConf <- o .: "user-source" appUserAuthConf <- o .: "user-auth"
-- P.fromList . mapMaybe (assertM nonEmptyHost) <$> o .:? "user-database" .!= [] -- P.fromList . mapMaybe (assertM nonEmptyHost) <$> o .:? "user-database" .!= []
appLdapPoolConf <- o .:? "ldap-pool" appLdapPoolConf <- o .:? "ldap-pool"
appLmsConf <- o .: "lms-direct" appLmsConf <- o .: "lms-direct"

View File

@ -4,7 +4,7 @@
module Settings.OAuth2 module Settings.OAuth2
( AzureConf(..) ( AzureConf(..)
, _azureClientId, _azureClientSecret, _azureTenantId, _azureScopes , _azureConfClientId, _azureConfClientSecret, _azureConfTenantId, _azureConfScopes
) where ) where
import ClassyPrelude import ClassyPrelude
@ -17,16 +17,15 @@ import Utils.Lens.TH
import Utils.PathPiece (camelToPathPiece') import Utils.PathPiece (camelToPathPiece')
-- TODO: use better types
data AzureConf = AzureConf data AzureConf = AzureConf
{ azureClientId :: UUID { azureConfClientId :: UUID
, azureClientSecret :: Text , azureConfClientSecret :: Text
, azureTenantId :: UUID , azureConfTenantId :: UUID
, azureScopes :: Set Text -- TODO: use better type , azureConfScopes :: Set Text -- TODO: use AzureScopes type?
} deriving (Show) } deriving (Show)
makeLenses_ ''AzureConf makeLenses_ ''AzureConf
deriveFromJSON defaultOptions deriveFromJSON defaultOptions
{ fieldLabelModifier = camelToPathPiece' 1 { fieldLabelModifier = camelToPathPiece' 2
} ''AzureConf } ''AzureConf