rename appmgr calls to be more descriptive of the API

This commit is contained in:
Keagan McClelland
2021-09-27 10:58:48 -06:00
parent e94d7440c2
commit 97e779941c
4 changed files with 56 additions and 55 deletions

View File

@@ -33,7 +33,6 @@ import Yesod.Persist.Core
import Database.Queries
import Foundation
import Lib.Error
import Lib.External.AppMgr
import Lib.Registry
import Lib.Types.AppIndex
@@ -79,10 +78,10 @@ getAppManifestR appId = do
Just v -> pure v
let appDir = (<> "/") . (</> show av) . (</> show appId) $ appsDir
addPackageHeader appMgrDir appDir appExt
getManifest appMgrDir
appDir
appExt
(\bsSource -> respondSource "application/json" (bsSource .| awaitForever sendChunkBS))
sourceManifest appMgrDir
appDir
appExt
(\bsSource -> respondSource "application/json" (bsSource .| awaitForever sendChunkBS))
where appExt = Extension (show appId) :: Extension "s9pk"
getAppConfigR :: AppIdentifier -> Handler TypedContent
@@ -95,7 +94,10 @@ getAppConfigR appId = do
Just v -> pure v
let appDir = (<> "/") . (</> show av) . (</> show appId) $ appsDir
addPackageHeader appMgrDir appDir appExt
config <- getConfig appMgrDir appDir appExt (\bsSource -> _)
config <- sourceConfig appMgrDir
appDir
appExt
(\bsSource -> respondSource "application/json" (bsSource .| awaitForever sendChunkBS))
pure $ TypedContent "application/json" (toContent config)
where appExt = Extension (show appId) :: Extension "s9pk"

View File

@@ -19,7 +19,6 @@ import Data.Conduit ( (.|)
)
import qualified Data.Conduit.List as CL
import Foundation
import Lib.Error
import Lib.External.AppMgr
import Lib.Registry
import Lib.Types.AppIndex
@@ -45,7 +44,7 @@ getIconsR appId = do
Nothing -> sendResponseStatus status404 ("Specified App Version Not Found" :: Text)
Just v -> pure v
let appDir = (<> "/") . (</> show spec) . (</> show appId) $ appsDir
manifest' <- getManifest appMgrDir appDir ext (\bsSource -> runConduit $ bsSource .| CL.foldMap BS.fromStrict)
manifest' <- sourceManifest appMgrDir appDir ext (\bsSource -> runConduit $ bsSource .| CL.foldMap BS.fromStrict)
manifest <- case eitherDecode manifest' of
Left e -> do
$logError "could not parse service manifest!"
@@ -66,10 +65,10 @@ getIconsR appId = do
SVG -> pure typeSvg
JPG -> pure typeJpeg
JPEG -> pure typeJpeg
getIcon appMgrDir
(appDir </> show ext)
ext
(\bsSource -> respondSource mimeType (bsSource .| awaitForever sendChunkBS))
sourceIcon appMgrDir
(appDir </> show ext)
ext
(\bsSource -> respondSource mimeType (bsSource .| awaitForever sendChunkBS))
where ext = Extension (show appId) :: Extension "s9pk"
getLicenseR :: AppIdentifier -> Handler TypedContent
@@ -82,7 +81,7 @@ getLicenseR appId = do
case servicePath of
Nothing -> notFound
Just p ->
getLicense appMgrDir p ext (\bsSource -> respondSource typePlain (bsSource .| awaitForever sendChunkBS))
sourceLicense appMgrDir p ext (\bsSource -> respondSource typePlain (bsSource .| awaitForever sendChunkBS))
where ext = Extension (show appId) :: Extension "s9pk"
getInstructionsR :: AppIdentifier -> Handler TypedContent
@@ -94,8 +93,8 @@ getInstructionsR appId = do
servicePath <- liftIO $ getVersionedFileFromDir appsDir ext spec
case servicePath of
Nothing -> notFound
Just p -> getInstructions appMgrDir
p
ext
(\bsSource -> respondSource typePlain (bsSource .| awaitForever sendChunkBS))
Just p -> sourceInstructions appMgrDir
p
ext
(\bsSource -> respondSource typePlain (bsSource .| awaitForever sendChunkBS))
where ext = Extension (show appId) :: Extension "s9pk"

View File

@@ -414,7 +414,7 @@ getServiceDetails settings metadata maybeVersion appId = do
Just v -> pure v
let appDir = (<> "/") . (</> show version) . (</> show appId) $ appsDir
let appExt = Extension (show appId) :: Extension "s9pk"
manifest' <- getManifest appMgrDir appDir appExt (\bs -> sinkMem (bs .| mapC BS.fromStrict))
manifest' <- sourceManifest appMgrDir appDir appExt (\bs -> sinkMem (bs .| mapC BS.fromStrict))
case eitherDecode $ manifest' of
Left e -> pure $ Left $ "Could not parse service manifest for " <> show appId <> ": " <> show e
Right m -> do
@@ -467,7 +467,7 @@ decodeInstructions :: (MonadUnliftIO m, MonadHandler m, KnownSymbol a, MonadThro
-> Extension a
-> m Text
decodeInstructions appmgrPath depPath package = do
getInstructions appmgrPath depPath package (\bs -> sinkMem (bs .| CT.decode CT.utf8))
sourceInstructions appmgrPath depPath package (\bs -> sinkMem (bs .| CT.decode CT.utf8))
decodeLicense :: (MonadUnliftIO m, MonadThrow m, MonadHandler m, KnownSymbol a)
=> FilePath
@@ -475,7 +475,7 @@ decodeLicense :: (MonadUnliftIO m, MonadThrow m, MonadHandler m, KnownSymbol a)
-> Extension a
-> m Text
decodeLicense appmgrPath depPath package =
getLicense appmgrPath depPath package (\bs -> sinkMem (bs .| CT.decode CT.utf8))
sourceLicense appmgrPath depPath package (\bs -> sinkMem (bs .| CT.decode CT.utf8))
fetchAllAppVersions :: Key SApp -> HandlerFor RegistryCtx ([VersionInfo], ReleaseNotes)
fetchAllAppVersions appId = do

View File

@@ -57,36 +57,36 @@ readProcessInheritStderr a b c sink = do
$ System.Process.Typed.proc a b
withProcessTerm_ pc $ \p -> sink (getStdout p)
getConfig :: (MonadUnliftIO m, MonadThrow m, KnownSymbol a)
=> FilePath
-> FilePath
-> Extension a
-> (ConduitT () ByteString m () -> m r)
-> m r
getConfig appmgrPath appPath e@(Extension appId) sink = do
sourceConfig :: (MonadUnliftIO m, MonadThrow m, KnownSymbol a)
=> FilePath
-> FilePath
-> Extension a
-> (ConduitT () ByteString m () -> m r)
-> m r
sourceConfig appmgrPath appPath e@(Extension appId) sink = do
let
appmgr = readProcessInheritStderr (appmgrPath <> "embassy-sdk")
["inspect", "config", appPath </> show e, "--json"]
""
appmgr sink `catch` \ece -> throwIO (AppMgrE [i|inspect config #{appId} \--json|] (eceExitCode ece))
getManifest :: (MonadUnliftIO m, KnownSymbol a)
=> FilePath
-> FilePath
-> Extension a
-> (ConduitT () ByteString m () -> m r)
-> m r
getManifest appmgrPath appPath e@(Extension appId) sink = do
sourceManifest :: (MonadUnliftIO m, KnownSymbol a)
=> FilePath
-> FilePath
-> Extension a
-> (ConduitT () ByteString m () -> m r)
-> m r
sourceManifest appmgrPath appPath e@(Extension appId) sink = do
let appmgr = readProcessInheritStderr (appmgrPath <> "embassy-sdk") ["inspect", "manifest", appPath </> show e] ""
appmgr sink `catch` \ece -> throwIO (AppMgrE [i|embassy-sdk inspect manifest #{appId}|] (eceExitCode ece))
getIcon :: (MonadUnliftIO m, KnownSymbol a)
=> FilePath
-> FilePath
-> Extension a
-> (ConduitT () ByteString m () -> m r)
-> m r
getIcon appmgrPath appPath (Extension icon) sink = do
sourceIcon :: (MonadUnliftIO m, KnownSymbol a)
=> FilePath
-> FilePath
-> Extension a
-> (ConduitT () ByteString m () -> m r)
-> m r
sourceIcon appmgrPath appPath (Extension icon) sink = do
let appmgr = readProcessInheritStderr (appmgrPath <> "embassy-sdk") ["inspect", "icon", appPath] ""
appmgr sink `catch` \ece -> throwIO $ AppMgrE [i|embassy-sdk inspect icon #{icon}|] (eceExitCode ece)
@@ -96,23 +96,23 @@ getPackageHash appmgrPath appPath e@(Extension appId) = do
appmgr (\bsSource -> runConduit $ bsSource .| CL.foldMap id)
`catch` \ece -> throwIO $ AppMgrE [i|embassy-sdk inspect hash #{appId}|] (eceExitCode ece)
getInstructions :: (MonadUnliftIO m, KnownSymbol a)
=> FilePath
-> FilePath
-> Extension a
-> (ConduitT () ByteString m () -> m r)
-> m r
getInstructions appmgrPath appPath (Extension appId) sink = do
sourceInstructions :: (MonadUnliftIO m, KnownSymbol a)
=> FilePath
-> FilePath
-> Extension a
-> (ConduitT () ByteString m () -> m r)
-> m r
sourceInstructions appmgrPath appPath (Extension appId) sink = do
let appmgr = readProcessInheritStderr (appmgrPath <> "embassy-sdk") ["inspect", "instructions", appPath] ""
appmgr sink `catch` \ece -> throwIO $ AppMgrE [i|embassy-sdk inspect instructions #{appId}|] (eceExitCode ece)
getLicense :: (MonadUnliftIO m, KnownSymbol a)
=> FilePath
-> FilePath
-> Extension a
-> (ConduitT () ByteString m () -> m r)
-> m r
getLicense appmgrPath appPath (Extension appId) sink = do
sourceLicense :: (MonadUnliftIO m, KnownSymbol a)
=> FilePath
-> FilePath
-> Extension a
-> (ConduitT () ByteString m () -> m r)
-> m r
sourceLicense appmgrPath appPath (Extension appId) sink = do
let appmgr = readProcessInheritStderr (appmgrPath <> "embassy-sdk") ["inspect", "license", appPath] ""
appmgr sink `catch` \ece -> throwIO $ AppMgrE [i|embassy-sdk inspect license #{appId}|] (eceExitCode ece)