fix whitelist logic and default it to empty

This commit is contained in:
Lucy Cifferello
2023-04-12 17:01:19 -06:00
parent cf8b386c53
commit fa40f6f7a2
2 changed files with 7 additions and 5 deletions

View File

@@ -39,7 +39,7 @@ marketplace-name: "_env:MARKETPLACE_NAME:CHANGE ME"
max-eos-version: "_env:MAX_VERSION:0.3.4.0" max-eos-version: "_env:MAX_VERSION:0.3.4.0"
min-eos-version: "_env:MIN_VERSION:0.3.4.0" min-eos-version: "_env:MIN_VERSION:0.3.4.0"
run-migration: "_env:RUN_MIGRATION:false" run-migration: "_env:RUN_MIGRATION:false"
whitelist: "_env:WHITELIST:ADD ME" whitelist: "_env:WHITELIST:"
database: database:
database: "_env:PG_DATABASE:start9_registry" database: "_env:PG_DATABASE:start9_registry"

View File

@@ -117,7 +117,9 @@ import Startlude (
(<<$>>), (<<$>>),
(<>), (<>),
(>), (>),
(&&) (&&),
(||),
(<=)
) )
import System.FilePath ( import System.FilePath (
(<.>), (<.>),
@@ -165,9 +167,8 @@ postPkgUploadR = do
PackageManifest{..} <- do PackageManifest{..} <- do
liftIO (decodeFileStrict (dir </> "manifest.json")) liftIO (decodeFileStrict (dir </> "manifest.json"))
`orThrow` sendResponseText status500 "Failed to parse manifest.json" `orThrow` sendResponseText status500 "Failed to parse manifest.json"
if (not $ elem packageManifestId whitelist && (length whitelist > 0)) if ((length whitelist > 0 && (packageManifestId `elem` whitelist)) || length whitelist <= 0)
then sendResponseText status500 "Package does not belong on this registry." then do
else do
renameFile path (dir </> (toS . unPkgId) packageManifestId <.> "s9pk") renameFile path (dir </> (toS . unPkgId) packageManifestId <.> "s9pk")
let targetPath = pkgRepoFileRoot </> show packageManifestId </> show packageManifestVersion let targetPath = pkgRepoFileRoot </> show packageManifestId </> show packageManifestVersion
removePathForcibly targetPath removePathForcibly targetPath
@@ -181,6 +182,7 @@ postPkgUploadR = do
Just name -> do Just name -> do
now <- liftIO getCurrentTime now <- liftIO getCurrentTime
runDB $ insert_ (Upload (AdminKey name) (PkgRecordKey packageManifestId) packageManifestVersion now) runDB $ insert_ (Upload (AdminKey name) (PkgRecordKey packageManifestId) packageManifestVersion now)
else sendResponseText status500 "Package does not belong on this registry."
where where
retry m = runMaybeT . asum $ replicate 3 (MaybeT $ hush <$> try @_ @SomeException m) retry m = runMaybeT . asum $ replicate 3 (MaybeT $ hush <$> try @_ @SomeException m)