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
# If the first user database in the list is unreachable, the application will perform a failover to the next list entry, etc.
user-database:
mode: simple
mode: single-source
protocol: oauth2
config:
protocol: "oauth2"
config:
client-id: "_env:OAUTH2CLIENTID:"
client-secret: "_env:OAUTH2CLIENTSECRET:"
tenant-id: "_env:OAUTH2TENANTID:"
client-id: "_env:OAUTH2CLIENTID:"
client-secret: "_env:OAUTH2CLIENTSECRET:"
tenant-id: "_env:OAUTH2TENANTID:"
# protocol: "ldap"
# config:
# host: "_env:LDAPHOST:"

View File

@ -146,16 +146,16 @@ data UserDbConf' = UserDbLdap LdapConf | UserDbOAuth2 OAuth2Conf
deriving (Show)
data UserDbConf =
UserDbSimple -- ^ use only one specific source
{ userdbSource :: UserDbConf'
UserDbSingleSource -- ^ use only one specific source
{ userdbSingleSource :: UserDbConf'
}
-- 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
-- { userdbFailoverSources :: PointedList UserDbConf
-- , userDbFailoverRetest :: NominalDiffTime
-- }
-- | UserDbMerge -- ^ Multiple coequal user sources
-- { userdbMergeSources :: Set UserDbConf
-- | UserDbMultiSource -- ^ Multiple coequal user sources
-- { userdbMultiSources :: Set UserDbConf
-- }
deriving (Show)
@ -318,14 +318,12 @@ deriveFromJSON defaultOptions
, sumEncoding = TaggedObject "protocol" "config"
} ''UserDbConf'
instance FromJSON UserDbConf where
parseJSON = withObject "UserDbConf" $ \o -> do
mode <- o .: "mode"
case mode of
"simple" -> do
userdbSource <- o .: "config"
return UserDbSimple{..}
other -> error $ "Unsupported user database mode: " <> other
deriveFromJSON defaultOptions
{ constructorTagModifier = camelToPathPiece' 1
, fieldLabelModifier = camelToPathPiece' 1
, sumEncoding = TaggedObject "mode" "config"
, unwrapUnaryRecords = True
} ''UserDbConf
instance FromJSON HaskellNet.PortNumber where
parseJSON = withScientific "PortNumber" $ \sciNum -> case Scientific.toBoundedInteger sciNum of