From 9dc6ec461c3a3ef307d72284ed4050c50c577828 Mon Sep 17 00:00:00 2001 From: Sarah Vaupel Date: Tue, 23 Jan 2024 02:59:25 +0100 Subject: [PATCH] chore(settings): simplify/flatten userdb config settings --- config/settings.yml | 11 +++++------ src/Settings.hs | 22 ++++++++++------------ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/config/settings.yml b/config/settings.yml index 0e45357f0..979297cd7 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -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:" diff --git a/src/Settings.hs b/src/Settings.hs index 177ae6611..133613cdd 100644 --- a/src/Settings.hs +++ b/src/Settings.hs @@ -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