diff --git a/agent/src/Handler/Types/V0/Base.hs b/agent/src/Handler/Types/V0/Base.hs index 811c2648e..0066d0e8f 100644 --- a/agent/src/Handler/Types/V0/Base.hs +++ b/agent/src/Handler/Types/V0/Base.hs @@ -31,15 +31,13 @@ data ServerRes = ServerRes , serverStatus :: Maybe AppStatus , serverStatusAt :: UTCTime , serverVersionInstalled :: Version - , serverVersionLatest :: Maybe Version - , serverNotifications :: [Entity Notification] + , serverNotifications :: [ Entity Notification ] , serverWifi :: WifiList - , serverSsh :: [SshKeyFingerprint] + , serverSsh :: [ SshKeyFingerprint ] , serverAlternativeRegistryUrl :: Maybe Text , serverSpecs :: SpecsRes , serverWelcomeAck :: Bool - } - deriving (Eq, Show) + } deriving (Eq, Show) type JsonEncoding a = Encoding jsonEncode :: (Monad m, ToJSON a) => a -> m (JsonEncoding a) @@ -53,7 +51,6 @@ instance ToJSON ServerRes where Nothing -> String "UPDATING" Just stat -> toJSON stat , "versionInstalled" .= serverVersionInstalled - , "versionLatest" .= serverVersionLatest , "notifications" .= serverNotifications , "wifi" .= serverWifi , "ssh" .= serverSsh diff --git a/agent/src/Handler/V0.hs b/agent/src/Handler/V0.hs index 6678604f2..d309a6c31 100644 --- a/agent/src/Handler/V0.hs +++ b/agent/src/Handler/V0.hs @@ -4,7 +4,6 @@ module Handler.V0 where import Startlude hiding ( runReader ) -import Control.Carrier.Error.Either import Control.Carrier.Lift ( runM ) import Data.Aeson import Data.IORef @@ -21,10 +20,8 @@ import Handler.Types.V0.Specs import Handler.Types.V0.Ssh import Handler.Types.V0.Base import Handler.Types.V0.Wifi -import Lib.Algebra.State.RegistryUrl import Lib.Error import Lib.External.Metrics.Df -import qualified Lib.External.Registry as Reg import Lib.External.Specs.CPU import Lib.External.Specs.Memory import qualified Lib.External.WpaSupplicant as WpaSupplicant @@ -61,9 +58,6 @@ getServerR = handleS9ErrT $ do wifi <- WpaSupplicant.runWlan0 $ liftA2 WifiList WpaSupplicant.getCurrentNetwork WpaSupplicant.listNetworks specs <- getSpecs settings welcomeAck <- fmap isJust . lift . runDB . Persist.get $ WelcomeAckKey agentVersion - versionLatest <- liftIO $ (try @SomeException $ getOsVersionLatest agentCtx) >>= \case - Left e -> (putStrLn @Text $ "Error fetching latest OS Version: " <> show e) $> Nothing - Right a -> pure a let sid = T.drop 7 $ specsNetworkId specs @@ -78,7 +72,6 @@ getServerR = handleS9ErrT $ do , serverAlternativeRegistryUrl = alternativeRegistryUrl , serverSpecs = specs , serverWelcomeAck = welcomeAck - , serverVersionLatest = versionLatest } where parseSshKeys :: Text -> S9ErrT Handler [SshKeyFingerprint] @@ -146,35 +139,3 @@ patchNullableFile path = do runM $ injectFilesystemBaseFromContext settings $ case mVal of Just val -> writeSystemPath path $ T.strip val Nothing -> deleteSystemPath path - -expirationOsVersionLatest :: Num a => a -expirationOsVersionLatest = 60 - -getOsVersionLatest :: MonadIO m => AgentCtx -> m (Maybe Version) -getOsVersionLatest ctx = do - now <- liftIO getCurrentTime - let osVersionCache = appOsVersionLatest ctx - mCache <- liftIO . readIORef $ osVersionCache - - case mCache of - Nothing -> repopulateCache ctx - Just cache -> if diffUTCTime now (lastChecked cache) >= expirationOsVersionLatest - then repopulateCache ctx - else pure . Just $ osVersion cache - -repopulateCache :: MonadIO m => AgentCtx -> m (Maybe Version) -repopulateCache ctx = do - let osVersionCache = appOsVersionLatest ctx - let s = appSettings ctx - eitherV <- interp s $ Reg.getLatestAgentVersion - - case eitherV of - Left error -> do - putStrLn $ "Repopulate OS Version Cache exception: " <> (show error :: Text) - fmap (fmap osVersion) . liftIO . readIORef $ osVersionCache - Right v -> do - res <- OsVersionCache v <$> liftIO getCurrentTime - liftIO $ writeIORef osVersionCache (Just res) - pure . Just $ osVersion res - where interp s = liftIO . runError @S9Error . injectFilesystemBaseFromContext s . runRegistryUrlIOC -