From fcb807eb4217dc696a52ceaf3dbd3731a90a8c4f Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Sat, 16 Jan 2021 17:01:18 -0700 Subject: [PATCH] agent: .autoCheckUpdates --- agent/config/routes | 1 + agent/src/Handler/V0.hs | 15 +++++++++++++++ agent/src/Lib/SystemPaths.hs | 3 +++ 3 files changed, 19 insertions(+) diff --git a/agent/config/routes b/agent/config/routes index 389d99a14..f598519c2 100644 --- a/agent/config/routes +++ b/agent/config/routes @@ -7,6 +7,7 @@ /v0 ServerR GET PATCH /v0/name NameR PATCH +/v0/autoCheckUpdates AutoCheckUpdatesR PATCH /v0/welcome/#Version WelcomeR POST /v0/specs SpecsR GET diff --git a/agent/src/Handler/V0.hs b/agent/src/Handler/V0.hs index 3f5757e49..9a70954de 100644 --- a/agent/src/Handler/V0.hs +++ b/agent/src/Handler/V0.hs @@ -109,9 +109,24 @@ newtype NullablePatchReq = NullablePatchReq { mpatchValue :: Maybe Text } derivi instance FromJSON NullablePatchReq where parseJSON = withObject "Nullable Patch Request" $ \o -> NullablePatchReq <$> o .:? "value" +newtype BoolPatchReq = BoolPatchReq { bpatchValue :: Bool } deriving (Eq, Show) + +instance FromJSON BoolPatchReq where + parseJSON = withObject "Patch Request" $ \o -> BoolPatchReq <$> o .: "value" + patchNameR :: Handler () patchNameR = patchFile serverNamePath +patchAutoCheckUpdatesR :: Handler () +patchAutoCheckUpdatesR = do + settings <- getsYesod appSettings + BoolPatchReq val <- requireCheckJsonBody + runM $ + injectFilesystemBaseFromContext settings $ + if val + then writeSystemPath autoCheckUpdatesPath "" + else deleteSystemPath autoCheckUpdatesPath + patchFile :: SystemPath -> Handler () patchFile path = do settings <- getsYesod appSettings diff --git a/agent/src/Lib/SystemPaths.hs b/agent/src/Lib/SystemPaths.hs index bbb4abb71..7bee6f18c 100644 --- a/agent/src/Lib/SystemPaths.hs +++ b/agent/src/Lib/SystemPaths.hs @@ -188,6 +188,9 @@ agentTorHiddenServicePrivateKeyPath = agentTorHiddenServiceDirectory <> "/hs_ed2 serverNamePath :: SystemPath serverNamePath = "/root/agent/name.txt" +autoCheckUpdatesPath :: SystemPath +autoCheckUpdatesPath = "/root/agent/.autoCheckUpdates" + altRegistryUrlPath :: SystemPath altRegistryUrlPath = "/root/agent/alt_registry_url.txt"