mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-26 02:11:53 +00:00
fix max eos version available logic; toggle migrations
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -39,3 +39,4 @@ start9-registry.ps
|
||||
shell.nix
|
||||
testdata/
|
||||
lbuild.sh
|
||||
icon
|
||||
@@ -37,6 +37,8 @@ static-bin-dir: "_env:STATIC_BIN:/usr/local/bin/"
|
||||
error-log-root: "_env:ERROR_LOG_ROOT:/var/log/registry/"
|
||||
marketplace-name: "_env:MARKETPLACE_NAME:CHANGE ME"
|
||||
icon-path: "_env:ICON_PATH:/var/www/html/resources"
|
||||
max-eos-version: "_env:MAX_VERSION:0.3.3.0"
|
||||
run-migration: "_env:RUN_MIGRATION:false"
|
||||
|
||||
database:
|
||||
database: "_env:PG_DATABASE:start9_registry"
|
||||
|
||||
@@ -254,11 +254,14 @@ makeFoundation appSettings = do
|
||||
flip runLoggingT logFunc $
|
||||
createPostgresqlPool (pgConnStr $ appDatabaseConf appSettings) (pgPoolSize . appDatabaseConf $ appSettings)
|
||||
|
||||
runSqlPool
|
||||
(Database.Persist.Migration.Postgres.runMigration Database.Persist.Migration.defaultSettings manualMigration)
|
||||
pool
|
||||
-- Preform database migration using application logging settings
|
||||
runLoggingT (runSqlPool (runMigration migrateAll) pool) logFunc
|
||||
if (needsMigration appSettings)
|
||||
then
|
||||
runSqlPool
|
||||
(Database.Persist.Migration.Postgres.runMigration Database.Persist.Migration.defaultSettings manualMigration)
|
||||
pool
|
||||
else
|
||||
-- Preform database migration using application logging settings
|
||||
runLoggingT (runSqlPool (runMigration migrateAll) pool) logFunc
|
||||
|
||||
-- Return the foundation
|
||||
return $ mkFoundation pool
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{-# LANGUAGE RecordWildCards #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
|
||||
module Handler.Eos.V0.Latest where
|
||||
|
||||
@@ -13,15 +14,18 @@ import Database.Esqueleto.Experimental (
|
||||
table,
|
||||
(^.),
|
||||
)
|
||||
import Foundation (Handler)
|
||||
import Foundation (Handler, RegistryCtx (appSettings))
|
||||
import Handler.Package.V0.ReleaseNotes (ReleaseNotes (..))
|
||||
import Handler.Util (queryParamAs, tickleMAU)
|
||||
import Lib.Types.Emver (Version, parseVersion)
|
||||
import Model (EntityField (..), OsVersion (..))
|
||||
import Orphans.Emver ()
|
||||
import Startlude (Bool (..), Down (..), Eq, Generic, Maybe, Ord ((<)), Show, Text, const, filter, fst, head, maybe, pure, sortOn, ($), (&&&), (.), (<$>), (<&>))
|
||||
import Yesod (ToContent (toContent), ToTypedContent (..), YesodPersist (runDB))
|
||||
import Startlude (Bool (..), Down (..), Eq, Generic, Maybe (..), Ord ((<)), Show, Text, const, filter, fst, head, maybe, pure, sortOn, ($), (&&&), (.), (<$>), (<&>), (<=))
|
||||
import Yesod (ToContent (toContent), ToTypedContent (..), YesodPersist (runDB), getsYesod, sendResponseStatus)
|
||||
import Yesod.Core.Types (JSONResponse (..))
|
||||
import Settings (AppSettings(maxEosVersion))
|
||||
import Network.HTTP.Types (status400)
|
||||
import Lib.Error (S9Error(InvalidParamsE))
|
||||
|
||||
|
||||
data EosRes = EosRes
|
||||
@@ -41,26 +45,36 @@ instance ToTypedContent EosRes where
|
||||
|
||||
getEosVersionR :: Handler (JSONResponse (Maybe EosRes))
|
||||
getEosVersionR = do
|
||||
eosVersion <- queryParamAs "eos-version" parseVersion
|
||||
allEosVersions <- runDB $
|
||||
select $ do
|
||||
vers <- from $ table @OsVersion
|
||||
orderBy [desc (vers ^. OsVersionCreatedAt)]
|
||||
pure vers
|
||||
let osV = entityVal <$> allEosVersions
|
||||
let mLatest = head osV
|
||||
let mappedVersions =
|
||||
ReleaseNotes $
|
||||
HM.fromList $
|
||||
sortOn (Down . fst) $
|
||||
filter (maybe (const True) (<) eosVersion . fst) $
|
||||
((osVersionNumber &&& osVersionReleaseNotes))
|
||||
<$> osV
|
||||
tickleMAU
|
||||
pure . JSONResponse $
|
||||
mLatest <&> \latest ->
|
||||
EosRes
|
||||
{ eosResVersion = osVersionNumber latest
|
||||
, eosResHeadline = osVersionHeadline latest
|
||||
, eosResReleaseNotes = mappedVersions
|
||||
}
|
||||
currentEosVersion <- queryParamAs "eos-version" parseVersion
|
||||
case currentEosVersion of
|
||||
Nothing -> sendResponseStatus status400 (InvalidParamsE "Param is required" "eos-version")
|
||||
Just currentEosVersion' -> do
|
||||
maxVersion <- getsYesod $ maxEosVersion . appSettings
|
||||
allEosVersions <- runDB $
|
||||
select $ do
|
||||
vers <- from $ table @OsVersion
|
||||
orderBy [desc (vers ^. OsVersionNumber)]
|
||||
pure vers
|
||||
let osV = determineMaxEosVersionAvailable maxVersion currentEosVersion' $ entityVal <$> allEosVersions
|
||||
let mLatest = head osV
|
||||
let mappedVersions =
|
||||
ReleaseNotes $
|
||||
HM.fromList $
|
||||
sortOn (Down . fst) $
|
||||
filter (maybe (const True) (<) currentEosVersion . fst) $
|
||||
((osVersionNumber &&& osVersionReleaseNotes))
|
||||
<$> osV
|
||||
tickleMAU
|
||||
pure . JSONResponse $
|
||||
mLatest <&> \latest ->
|
||||
EosRes
|
||||
{ eosResVersion = osVersionNumber latest
|
||||
, eosResHeadline = osVersionHeadline latest
|
||||
, eosResReleaseNotes = mappedVersions
|
||||
}
|
||||
|
||||
determineMaxEosVersionAvailable :: Version -> Version -> [OsVersion] -> [OsVersion]
|
||||
determineMaxEosVersionAvailable maxEosVersion currentEosVersion versions = do
|
||||
if (currentEosVersion < maxEosVersion)
|
||||
then sortOn (Down . osVersionNumber) $ filter (\v -> osVersionNumber v <= maxEosVersion) $ versions
|
||||
else versions
|
||||
@@ -76,9 +76,11 @@ data AppSettings = AppSettings
|
||||
, iconPath :: !FilePath
|
||||
, errorLogRoot :: !FilePath
|
||||
, marketplaceName :: !Text
|
||||
, maxEosVersion :: !Version
|
||||
, registryHostname :: !Text
|
||||
, registryVersion :: !Version
|
||||
, resourcesDir :: !FilePath
|
||||
, needsMigration :: !Bool
|
||||
, sslAuto :: !Bool
|
||||
, sslCertLocation :: !FilePath
|
||||
, sslCsrLocation :: !FilePath
|
||||
@@ -110,8 +112,10 @@ instance FromJSON AppSettings where
|
||||
errorLogRoot <- o .: "error-log-root"
|
||||
iconPath <- o .: "icon-path"
|
||||
marketplaceName <- o .: "marketplace-name"
|
||||
maxEosVersion <- o .: "max-eos-version"
|
||||
registryHostname <- o .: "registry-hostname"
|
||||
resourcesDir <- o .: "resources-path"
|
||||
needsMigration <- o .: "run-migration"
|
||||
sslAuto <- o .: "ssl-auto"
|
||||
sslPath <- o .: "ssl-path"
|
||||
staticBinDir <- o .: "static-bin-dir"
|
||||
|
||||
Reference in New Issue
Block a user