chore(settings): refactor userdb config structure

This commit is contained in:
Sarah Vaupel 2024-01-26 23:24:40 +01:00
parent 71af64dc28
commit 4051d1e11b
4 changed files with 35 additions and 36 deletions

View File

@ -128,15 +128,15 @@ database:
auto-db-migrate: '_env:AUTO_DB_MIGRATE:true' auto-db-migrate: '_env:AUTO_DB_MIGRATE:true'
# External databases used for authentication and user data lookup # External databases used for authentication and userdata lookups
# If the first user database in the list is unreachable, the application will perform a failover to the next list entry, etc.
user-database: user-database:
mode: single-source mode: single-source
protocol: oauth2 protocol: azureadv2
config: config:
client-id: "_env:OAUTH2CLIENTID:" client-id: "_env:AZURECLIENTID:00000000-0000-0000-0000-000000000000"
client-secret: "_env:OAUTH2CLIENTSECRET:" client-secret: "_env:AZURECLIENTSECRET:verysecret"
tenant-id: "_env:OAUTH2TENANTID:" tenant-id: "_env:AZURETENANTID:00000000-0000-0000-0000-000000000000"
scopes: "_env:AZURESCOPES:[]"
# protocol: "ldap" # protocol: "ldap"
# config: # config:
# host: "_env:LDAPHOST:" # host: "_env:LDAPHOST:"
@ -148,12 +148,13 @@ user-database:
# scope: "_env:LDAPSCOPE:WholeSubtree" # scope: "_env:LDAPSCOPE:WholeSubtree"
# timeout: "_env:LDAPTIMEOUT:5" # timeout: "_env:LDAPTIMEOUT:5"
# search-timeout: "_env:LDAPSEARCHTIME:5" # search-timeout: "_env:LDAPSEARCHTIME:5"
# pool:
# stripes: "_env:LDAPSTRIPES:1"
# timeout: "_env:LDAPTIMEOUT:20"
# limit: "_env:LDAPLIMIT:10"
userdb-retest-failover: 60 ldap-pool:
stripes: "_env:LDAPSTRIPES:1"
timeout: "_env:LDAPTIMEOUT:20"
limit: "_env:LDAPLIMIT:10"
# userdb-retest-failover: 60
userdb-sync-within: "_env:USERDB_SYNC_WITHIN:1209600" # 14 Tage in Sekunden userdb-sync-within: "_env:USERDB_SYNC_WITHIN:1209600" # 14 Tage in Sekunden
userdb-sync-interval: "_env:USERDB_SYNC_INTERVAL:3600" # jede Stunde userdb-sync-interval: "_env:USERDB_SYNC_INTERVAL:3600" # jede Stunde

View File

@ -142,7 +142,7 @@ instance FromJSON PWHashConf where
return PWHashConf{..} return PWHashConf{..}
data UserDbConf' = UserDbLdap LdapConf | UserDbOAuth2 OAuth2Conf data UserDbConf' = UserDbLdap LdapConf | UserDbAzureAdV2 AzureConf
deriving (Show) deriving (Show)
data UserDbConf = data UserDbConf =
@ -517,10 +517,12 @@ data AppSettings = AppSettings
, appHealthCheckHTTPReachableTimeout :: NominalDiffTime , appHealthCheckHTTPReachableTimeout :: NominalDiffTime
, appHealthCheckMatchingClusterConfigTimeout :: NominalDiffTime , appHealthCheckMatchingClusterConfigTimeout :: NominalDiffTime
, appUserdbRetestFailover :: DiffTime -- , appUserdbRetestFailover :: DiffTime
, appUserdbSyncWithin :: Maybe NominalDiffTime , appUserdbSyncWithin :: Maybe NominalDiffTime
, appUserdbSyncInterval :: NominalDiffTime , appUserdbSyncInterval :: NominalDiffTime
, appLdapPoolConf :: Maybe ResourcePoolConf
, appSynchroniseAvsUsersWithin :: Maybe NominalDiffTime , appSynchroniseAvsUsersWithin :: Maybe NominalDiffTime
, appSynchroniseAvsUsersInterval :: NominalDiffTime , appSynchroniseAvsUsersInterval :: NominalDiffTime
@ -628,6 +630,7 @@ instance FromJSON AppSettings where
-- nonEmptyHost (UserDbOAuth2 OAuth2Conf{..}) = not $ or [ null oauth2TenantId, null oauth2ClientId, null oauth2ClientSecret ] -- nonEmptyHost (UserDbOAuth2 OAuth2Conf{..}) = not $ or [ null oauth2TenantId, null oauth2ClientId, null oauth2ClientSecret ]
appUserDbConf <- o .: "user-database" appUserDbConf <- o .: "user-database"
-- P.fromList . mapMaybe (assertM nonEmptyHost) <$> o .:? "user-database" .!= [] -- P.fromList . mapMaybe (assertM nonEmptyHost) <$> o .:? "user-database" .!= []
appLdapPoolConf <- o .:? "ldap-pool"
appLmsConf <- o .: "lms-direct" appLmsConf <- o .: "lms-direct"
appAvsConf <- assertM (not . null . avsPass) <$> o .:? "avs" appAvsConf <- assertM (not . null . avsPass) <$> o .:? "avs"
appLprConf <- o .: "lpr" appLprConf <- o .: "lpr"
@ -692,7 +695,7 @@ instance FromJSON AppSettings where
appSessionTimeout <- o .: "session-timeout" appSessionTimeout <- o .: "session-timeout"
appUserdbRetestFailover <- o .: "userdb-retest-failover" -- appUserdbRetestFailover <- o .: "userdb-retest-failover"
appUserdbSyncWithin <- o .:? "userdb-sync-within" appUserdbSyncWithin <- o .:? "userdb-sync-within"
appUserdbSyncInterval <- o .: "userdb-sync-interval" appUserdbSyncInterval <- o .: "userdb-sync-interval"

View File

@ -6,12 +6,11 @@
module Settings.Ldap module Settings.Ldap
( LdapConf(..) ( LdapConf(..)
, _ldapHost, _ldapDn, _ldapBase, _ldapScope, _ldapTimeout, _ldapSearchTimeout, _ldapPool , _ldapHost, _ldapDn, _ldapBase, _ldapScope, _ldapTimeout, _ldapSearchTimeout
) where ) where
import ClassyPrelude import ClassyPrelude
import Settings.ResourcePool
import Utils.Lens.TH import Utils.Lens.TH
import Control.Monad.Fail (fail) import Control.Monad.Fail (fail)
@ -33,7 +32,6 @@ data LdapConf = LdapConf
, ldapScope :: Ldap.Scope , ldapScope :: Ldap.Scope
, ldapTimeout :: NominalDiffTime , ldapTimeout :: NominalDiffTime
, ldapSearchTimeout :: Int32 , ldapSearchTimeout :: Int32
, ldapPool :: ResourcePoolConf
} deriving (Show) } deriving (Show)
makeLenses_ ''LdapConf makeLenses_ ''LdapConf
@ -60,5 +58,4 @@ instance FromJSON LdapConf where
ldapScope <- o .: "scope" ldapScope <- o .: "scope"
ldapTimeout <- o .: "timeout" ldapTimeout <- o .: "timeout"
ldapSearchTimeout <- o .: "search-timeout" ldapSearchTimeout <- o .: "search-timeout"
ldapPool <- o .: "pool"
return LdapConf{..} return LdapConf{..}

View File

@ -3,32 +3,30 @@
-- SPDX-License-Identifier: AGPL-3.0-or-later -- SPDX-License-Identifier: AGPL-3.0-or-later
module Settings.OAuth2 module Settings.OAuth2
( OAuth2Conf(..) ( AzureConf(..)
, _oauth2ClientId, _oauth2ClientSecret, _oauth2TenantId, _oauth2Scopes , _azureClientId, _azureClientSecret, _azureTenantId, _azureScopes
) where ) where
import ClassyPrelude import ClassyPrelude
import Utils.Lens.TH
import Data.Aeson import Data.Aeson
import qualified Data.Set as Set import Data.Aeson.TH
import Data.UUID
import Utils.Lens.TH
import Utils.PathPiece (camelToPathPiece')
-- TODO: use better types -- TODO: use better types
data OAuth2Conf = OAuth2Conf data AzureConf = AzureConf
{ oauth2ClientId :: Text { azureClientId :: UUID
, oauth2ClientSecret :: Text , azureClientSecret :: Text
, oauth2TenantId :: Text , azureTenantId :: UUID
, oauth2Scopes :: Set Text , azureScopes :: Set Text -- TODO: use better type
} deriving (Show) } deriving (Show)
makeLenses_ ''OAuth2Conf makeLenses_ ''AzureConf
instance FromJSON OAuth2Conf where deriveFromJSON defaultOptions
parseJSON = withObject "OAuth2Conf" $ \o -> do { fieldLabelModifier = camelToPathPiece' 1
oauth2ClientId <- o .:? "client-id" .!= "" } ''AzureConf
oauth2ClientSecret <- o .:? "client-secret" .!= ""
oauth2TenantId <- o .:? "tenant-id" .!= ""
oauth2Scopes <- o .:? "scopes" .!= Set.empty
return OAuth2Conf{..}