From 54ae7f82d69f247cdd1e003b0da648016627e1c2 Mon Sep 17 00:00:00 2001 From: Keagan McClelland Date: Fri, 19 Feb 2021 14:04:22 -0700 Subject: [PATCH] adds action listings to AIS response --- agent/src/Handler/Apps.hs | 14 +++++++------ agent/src/Handler/Types/Apps.hs | 3 +++ agent/src/Lib/Algebra/Domain/AppMgr.hs | 7 ++++--- agent/src/Lib/External/AppManifest.hs | 28 ++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/agent/src/Handler/Apps.hs b/agent/src/Handler/Apps.hs index f8ce08e5b..4ddf9ea39 100644 --- a/agent/src/Handler/Apps.hs +++ b/agent/src/Handler/Apps.hs @@ -303,6 +303,7 @@ getInstalledAppByIdLogic appId = do , appInstalledFullConfiguredRequirements = [] , appInstalledFullUninstallAlert = Nothing , appInstalledFullRestoreAlert = Nothing + , appInstalledFullActions = [] } serverApps <- AppMgr2.list [AppMgr2.flags|-s -d|] let remapped = remapAppMgrInfo jobCache serverApps @@ -339,15 +340,16 @@ getInstalledAppByIdLogic appId = do then LanAddress . (".onion" `Text.replace` ".local") . unTorAddress <$> infoResTorAddress else Nothing pure AppInstalledFull { appInstalledFullBase = AppBase appId infoResTitle (iconUrl appId version) - , appInstalledFullStatus = status - , appInstalledFullVersionInstalled = version - , appInstalledFullInstructions = instructions - , appInstalledFullLastBackup = backupTime - , appInstalledFullTorAddress = infoResTorAddress - , appInstalledFullLanAddress = lanAddress + , appInstalledFullStatus = status + , appInstalledFullVersionInstalled = version + , appInstalledFullInstructions = instructions + , appInstalledFullLastBackup = backupTime + , appInstalledFullTorAddress = infoResTorAddress + , appInstalledFullLanAddress = lanAddress , appInstalledFullConfiguredRequirements = HM.elems requirements , appInstalledFullUninstallAlert = manifest >>= AppManifest.appManifestUninstallAlert , appInstalledFullRestoreAlert = manifest >>= AppManifest.appManifestRestoreAlert + , appInstalledFullActions = fromMaybe [] $ AppManifest.appManifestActions <$> manifest } runMaybeT (installing <|> installed) `orThrowM` NotFoundE "appId" (show appId) diff --git a/agent/src/Handler/Types/Apps.hs b/agent/src/Handler/Types/Apps.hs index 7ed0b95b5..da9d5a3e8 100644 --- a/agent/src/Handler/Types/Apps.hs +++ b/agent/src/Handler/Types/Apps.hs @@ -14,6 +14,7 @@ import Lib.Types.Core import Lib.Types.Emver import Lib.Types.Emver.Orphans ( ) import Lib.Types.NetAddress +import qualified Lib.External.AppManifest as Manifest data AppBase = AppBase { appBaseId :: AppId , appBaseTitle :: Text @@ -137,6 +138,7 @@ data AppInstalledFull = AppInstalledFull , appInstalledFullConfiguredRequirements :: [Stripped AppDependencyRequirement] , appInstalledFullUninstallAlert :: Maybe Text , appInstalledFullRestoreAlert :: Maybe Text + , appInstalledFullActions :: [Manifest.Action] } instance ToJSON AppInstalledFull where toJSON AppInstalledFull {..} = object @@ -152,6 +154,7 @@ instance ToJSON AppInstalledFull where , "status" .= appInstalledFullStatus , "uninstallAlert" .= appInstalledFullUninstallAlert , "restoreAlert" .= appInstalledFullRestoreAlert + , "actions" .= appInstalledFullActions ] data AppVersionInfo = AppVersionInfo diff --git a/agent/src/Lib/Algebra/Domain/AppMgr.hs b/agent/src/Lib/Algebra/Domain/AppMgr.hs index 17423e227..07ea3ca86 100644 --- a/agent/src/Lib/Algebra/Domain/AppMgr.hs +++ b/agent/src/Lib/Algebra/Domain/AppMgr.hs @@ -29,7 +29,7 @@ import qualified Data.String as String import Lib.Algebra.Domain.AppMgr.Types import Lib.Algebra.Domain.AppMgr.TH import Lib.Error -import Lib.External.AppManifest +import qualified Lib.External.AppManifest as Manifest import Lib.TyFam.ConditionalData import Lib.Types.Core ( AppId(..) , AppContainerStatus(..) @@ -65,8 +65,9 @@ data InfoRes a = InfoRes :: Include (Either_ (DefaultEqSym1 'OnlyDependencies) (ElemSym1 'IncludeDependencies) a) (HM.HashMap AppId DependencyInfo) - , infoResManifest :: Include (Either_ (DefaultEqSym1 'OnlyManifest) (ElemSym1 'IncludeManifest) a) AppManifest - , infoResStatus :: Include (Either_ (DefaultEqSym1 'OnlyStatus) (ElemSym1 'IncludeStatus) a) AppContainerStatus + , infoResManifest + :: Include (Either_ (DefaultEqSym1 'OnlyManifest) (ElemSym1 'IncludeManifest) a) Manifest.AppManifest + , infoResStatus :: Include (Either_ (DefaultEqSym1 'OnlyStatus) (ElemSym1 'IncludeStatus) a) AppContainerStatus } instance SingI (a :: Either OnlyInfoFlag [IncludeInfoFlag]) => FromJSON (InfoRes a) where parseJSON = withObject "AppMgr Info/List Response" $ \o -> do diff --git a/agent/src/Lib/External/AppManifest.hs b/agent/src/Lib/External/AppManifest.hs index 4d85c2c77..fd6eb4144 100644 --- a/agent/src/Lib/External/AppManifest.hs +++ b/agent/src/Lib/External/AppManifest.hs @@ -47,6 +47,32 @@ instance FromJSON AssetMapping where assetMappingOverwrite <- o .: "overwrite" pure $ AssetMapping { .. } +data Action = Action + { actionId :: Text + , actionName :: Text + , actionDescription :: Text + , actionWarning :: Maybe Text + , actionAllowedStatuses :: [AppContainerStatus] + } +instance FromJSON Action where + parseJSON = withObject "AppAction" $ \o -> do + actionId <- o .: "id" + actionName <- o .: "name" + actionDescription <- o .: "description" + actionWarning <- o .:? "warning" + actionAllowedStatuses <- o .: "allowed-statuses" + pure Action { .. } +instance ToJSON Action where + toJSON Action {..} = + object + $ [ "id" .= actionId + , "name" .= actionName + , "description" .= actionDescription + , "allowedStatuses" .= actionAllowedStatuses + ] + <> maybeToList (("warning" .=) <$> actionWarning) + + data AppManifest where AppManifest ::{ appManifestId :: AppId , appManifestVersion :: Version @@ -62,6 +88,7 @@ data AppManifest where , appManifestDependencies :: HM.HashMap AppId VersionRange , appManifestUninstallAlert :: Maybe Text , appManifestRestoreAlert :: Maybe Text + , appManifestActions :: [Action] } -> AppManifest uiAvailable :: AppManifest -> Bool @@ -83,6 +110,7 @@ instance FromJSON AppManifest where appManifestDependencies <- o .:? "dependencies" .!= HM.empty >>= traverse parseDepInfo appManifestUninstallAlert <- o .:? "uninstall-alert" appManifestRestoreAlert <- o .:? "restore-alert" + appManifestActions <- o .: "actions" pure $ AppManifest { .. } where parsePortMapping = withObject "Port Mapping" $ \o -> liftA2 (,) (o .: "tor") (o .: "internal")