From 18f18e3b95bd36589f99f65df79cacece8c96892 Mon Sep 17 00:00:00 2001 From: Aaron Greenspan Date: Tue, 19 Jan 2021 17:40:16 -0700 Subject: [PATCH] agent: adds autoCheckUpdates to v0 --- agent/src/Handler/Types/V0/Base.hs | 2 ++ agent/src/Handler/V0.hs | 2 ++ agent/src/Lib/SystemPaths.hs | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/agent/src/Handler/Types/V0/Base.hs b/agent/src/Handler/Types/V0/Base.hs index 0066d0e8f..ead34abfd 100644 --- a/agent/src/Handler/Types/V0/Base.hs +++ b/agent/src/Handler/Types/V0/Base.hs @@ -37,6 +37,7 @@ data ServerRes = ServerRes , serverAlternativeRegistryUrl :: Maybe Text , serverSpecs :: SpecsRes , serverWelcomeAck :: Bool + , serverAutoCheckUpdates :: Bool } deriving (Eq, Show) type JsonEncoding a = Encoding @@ -57,6 +58,7 @@ instance ToJSON ServerRes where , "alternativeRegistryUrl" .= serverAlternativeRegistryUrl , "specs" .= serverSpecs , "welcomeAck" .= serverWelcomeAck + , "autoCheckUpdates" .= serverAutoCheckUpdates ] instance ToTypedContent ServerRes where toTypedContent = toTypedContent . toJSON diff --git a/agent/src/Handler/V0.hs b/agent/src/Handler/V0.hs index d309a6c31..012cf5eff 100644 --- a/agent/src/Handler/V0.hs +++ b/agent/src/Handler/V0.hs @@ -58,6 +58,7 @@ getServerR = handleS9ErrT $ do wifi <- WpaSupplicant.runWlan0 $ liftA2 WifiList WpaSupplicant.getCurrentNetwork WpaSupplicant.listNetworks specs <- getSpecs settings welcomeAck <- fmap isJust . lift . runDB . Persist.get $ WelcomeAckKey agentVersion + autoCheckUpdates <- runM $ injectFilesystemBaseFromContext settings $ existsSystemPath autoCheckUpdatesPath let sid = T.drop 7 $ specsNetworkId specs @@ -72,6 +73,7 @@ getServerR = handleS9ErrT $ do , serverAlternativeRegistryUrl = alternativeRegistryUrl , serverSpecs = specs , serverWelcomeAck = welcomeAck + , serverAutoCheckUpdates = autoCheckUpdates } where parseSshKeys :: Text -> S9ErrT Handler [SshKeyFingerprint] diff --git a/agent/src/Lib/SystemPaths.hs b/agent/src/Lib/SystemPaths.hs index 7bee6f18c..e178102b3 100644 --- a/agent/src/Lib/SystemPaths.hs +++ b/agent/src/Lib/SystemPaths.hs @@ -80,6 +80,11 @@ readSystemPath path = do $ (Just <$> readFile (toS loadPath)) `catch` (\(e :: IOException) -> if isDoesNotExistError e then pure Nothing else throwIO e) +existsSystemPath :: (HasFilesystemBase sig m, MonadIO m) => SystemPath -> m Bool +existsSystemPath path = do + checkPath <- getAbsoluteLocationFor path + liftIO . doesPathExist $ toS checkPath + -- like the above, but throws IO error if file not found readSystemPath' :: (HasFilesystemBase sig m, MonadIO m) => SystemPath -> m Text readSystemPath' path = do