From 6c12d63eda66895cfbe98ca8c6707a795bfc4f06 Mon Sep 17 00:00:00 2001 From: Lucy Cifferello <12953208+elvece@users.noreply.github.com> Date: Thu, 1 Jul 2021 18:39:15 -0400 Subject: [PATCH] merge add package header --- config/routes | 4 ++-- src/Handler/Apps.hs | 2 ++ src/Handler/Marketplace.hs | 2 ++ src/Lib/External/AppMgr.hs | 9 ++++++++- src/Util/Shared.hs | 10 +++++++++- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/config/routes b/config/routes index 93473b5..2bd895e 100644 --- a/config/routes +++ b/config/routes @@ -1,8 +1,8 @@ /apps AppsManifestR GET -- get current apps listing -/package/manifest/#AppIdentifier AppManifestR GET -- get app manifest from appmgr -- ?spec={semver-spec} -/package/config/#AppIdentifier AppConfigR GET -- get app config from appmgr -- ?spec={semver-spec} +/package/manifest/#AppIdentifier AppManifestR GET -- get app manifest from appmgr -- ?spec={semver-spec} +/package/config/#AppIdentifier AppConfigR GET -- get app config from appmgr -- ?spec={semver-spec} /version VersionR GET diff --git a/src/Handler/Apps.hs b/src/Handler/Apps.hs index 7e85cb7..5274c43 100644 --- a/src/Handler/Apps.hs +++ b/src/Handler/Apps.hs @@ -111,6 +111,7 @@ getAppManifestR appId = do Just v -> pure v let appDir = (<> "/") . ( show av) . ( toS appId) $ appsDir manifest <- handleS9ErrT $ getManifest appMgrDir appDir appExt + addPackageHeader appMgrDir appDir appExt pure $ TypedContent "application/json" (toContent manifest) where appExt = Extension (toS appId) :: Extension "s9pk" @@ -124,6 +125,7 @@ getAppConfigR appId = do Just v -> pure v let appDir = (<> "/") . ( show av) . ( toS appId) $ appsDir config <- handleS9ErrT $ getConfig appMgrDir appDir appExt + addPackageHeader appMgrDir appDir appExt pure $ TypedContent "application/json" (toContent config) where appExt = Extension (toS appId) :: Extension "s9pk" diff --git a/src/Handler/Marketplace.hs b/src/Handler/Marketplace.hs index cee6d52..e54be51 100644 --- a/src/Handler/Marketplace.hs +++ b/src/Handler/Marketplace.hs @@ -36,6 +36,7 @@ import Data.Aeson import qualified Data.ByteString.Lazy as BS import qualified Data.Text as T import Data.String.Interpolate.IsString +import Util.Shared newtype CategoryRes = CategoryRes { @@ -206,6 +207,7 @@ getServiceR = do -- let deps = HM.toList (versionInfoDependencies $ Data.List.head versionInfo) d <- traverse (mapDependencyMetadata appsDir appMgrDir) (HM.toList $ serviceManifestDependencies manifest) icon <- decodeIcon appMgrDir appsDir appExt + addPackageHeader appMgrDir appDir appExt pure $ ServiceRes { serviceResIcon = icon , serviceResManifest = manifest -- TypedContent "application/json" (toContent manifest) diff --git a/src/Lib/External/AppMgr.hs b/src/Lib/External/AppMgr.hs index efe589b..2e67d15 100644 --- a/src/Lib/External/AppMgr.hs +++ b/src/Lib/External/AppMgr.hs @@ -61,4 +61,11 @@ getIcon appmgrPath appPath e@(Extension icon) = do (ec, bs) <- readProcessInheritStderr (appmgrPath <> "embassy-sdk") ["inspect", "icon", appPath <> show e] "" case ec of ExitSuccess -> pure bs - ExitFailure n -> throwE $ AppMgrE [i|icon #{icon} \--json|] n \ No newline at end of file + ExitFailure n -> throwE $ AppMgrE [i|icon #{icon} \--json|] n + +getPackageHash :: (MonadIO m, KnownSymbol a) => FilePath -> FilePath -> Extension a -> S9ErrT m ByteString +getPackageHash appmgrPath appPath e@(Extension appId) = do + (ec, bs) <- readProcessInheritStderr (appmgrPath <> "embassy-sdk") ["inspect", "hash", appPath <> show e] "" + case ec of + ExitSuccess -> pure bs + ExitFailure n -> throwE $ AppMgrE [i|hash #{appId} \--json|] n \ No newline at end of file diff --git a/src/Util/Shared.hs b/src/Util/Shared.hs index 50eaaee..6878b78 100644 --- a/src/Util/Shared.hs +++ b/src/Util/Shared.hs @@ -3,6 +3,7 @@ module Util.Shared where import Startlude hiding (Handler) import qualified Data.Text as T +import Data.Text.Encoding import Network.HTTP.Types import Yesod.Core @@ -10,6 +11,8 @@ import Foundation import Lib.Registry import Lib.Types.Emver import Data.Semigroup +import Lib.External.AppMgr +import Lib.Error getVersionFromQuery :: KnownSymbol a => FilePath -> Extension a -> Handler (Maybe Version) getVersionFromQuery rootDir ext = do @@ -24,4 +27,9 @@ getBestVersion rootDir ext spec = do appVersions <- liftIO $ getAvailableAppVersions rootDir ext let satisfactory = filter ((<|| spec) . fst . unRegisteredAppVersion) appVersions let best = getMax <$> foldMap (Just . Max . fst . unRegisteredAppVersion) satisfactory - pure best \ No newline at end of file + pure best + +addPackageHeader :: (MonadHandler m, KnownSymbol a) => FilePath -> FilePath -> Extension a -> m () +addPackageHeader appMgrDir appDir appExt = do + packageHash <- handleS9ErrT $ getPackageHash appMgrDir appDir appExt + addHeader "X-S9PK-HASH" $ decodeUtf8 packageHash \ No newline at end of file