chore(settings): simplify/flatten userdb config settings

This commit is contained in:
Sarah Vaupel 2024-01-23 02:59:25 +01:00
parent 1f31fe8cf2
commit 9dc6ec461c
2 changed files with 15 additions and 18 deletions

View File

@ -131,13 +131,12 @@ auto-db-migrate: '_env:AUTO_DB_MIGRATE:true'
# External databases used for authentication and user data lookup # External databases used for authentication and user data lookup
# If the first user database in the list is unreachable, the application will perform a failover to the next list entry, etc. # 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: simple mode: single-source
protocol: oauth2
config: config:
protocol: "oauth2" client-id: "_env:OAUTH2CLIENTID:"
config: client-secret: "_env:OAUTH2CLIENTSECRET:"
client-id: "_env:OAUTH2CLIENTID:" tenant-id: "_env:OAUTH2TENANTID:"
client-secret: "_env:OAUTH2CLIENTSECRET:"
tenant-id: "_env:OAUTH2TENANTID:"
# protocol: "ldap" # protocol: "ldap"
# config: # config:
# host: "_env:LDAPHOST:" # host: "_env:LDAPHOST:"

View File

@ -146,16 +146,16 @@ data UserDbConf' = UserDbLdap LdapConf | UserDbOAuth2 OAuth2Conf
deriving (Show) deriving (Show)
data UserDbConf = data UserDbConf =
UserDbSimple -- ^ use only one specific source UserDbSingleSource -- ^ use only one specific source
{ userdbSource :: UserDbConf' { userdbSingleSource :: UserDbConf'
} }
-- TODO: other modes yet to be implemented -- TODO: other modes yet to be implemented
-- | UserDbFailover -- ^ use only one user source at a time, but failover to the next-best database if the current source is unavailable -- | UserDbFailover -- ^ use only one user source at a time, but failover to the next-best database if the current source is unavailable
-- { userdbFailoverSources :: PointedList UserDbConf -- { userdbFailoverSources :: PointedList UserDbConf
-- , userDbFailoverRetest :: NominalDiffTime -- , userDbFailoverRetest :: NominalDiffTime
-- } -- }
-- | UserDbMerge -- ^ Multiple coequal user sources -- | UserDbMultiSource -- ^ Multiple coequal user sources
-- { userdbMergeSources :: Set UserDbConf -- { userdbMultiSources :: Set UserDbConf
-- } -- }
deriving (Show) deriving (Show)
@ -318,14 +318,12 @@ deriveFromJSON defaultOptions
, sumEncoding = TaggedObject "protocol" "config" , sumEncoding = TaggedObject "protocol" "config"
} ''UserDbConf' } ''UserDbConf'
instance FromJSON UserDbConf where deriveFromJSON defaultOptions
parseJSON = withObject "UserDbConf" $ \o -> do { constructorTagModifier = camelToPathPiece' 1
mode <- o .: "mode" , fieldLabelModifier = camelToPathPiece' 1
case mode of , sumEncoding = TaggedObject "mode" "config"
"simple" -> do , unwrapUnaryRecords = True
userdbSource <- o .: "config" } ''UserDbConf
return UserDbSimple{..}
other -> error $ "Unsupported user database mode: " <> other
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