agent: fetches server ack for v0 response

This commit is contained in:
Aaron Greenspan
2021-01-14 17:23:00 -07:00
committed by Aiden McClelland
parent ad92660c76
commit b908967ac4
2 changed files with 6 additions and 1 deletions

View File

@@ -36,6 +36,7 @@ data ServerRes = ServerRes
, serverSsh :: [SshKeyFingerprint] , serverSsh :: [SshKeyFingerprint]
, serverAlternativeRegistryUrl :: Maybe Text , serverAlternativeRegistryUrl :: Maybe Text
, serverSpecs :: SpecsRes , serverSpecs :: SpecsRes
, serverWelcomeAck :: Bool
} }
deriving (Eq, Show) deriving (Eq, Show)
@@ -57,6 +58,7 @@ instance ToJSON ServerRes where
, "ssh" .= serverSsh , "ssh" .= serverSsh
, "alternativeRegistryUrl" .= serverAlternativeRegistryUrl , "alternativeRegistryUrl" .= serverAlternativeRegistryUrl
, "specs" .= serverSpecs , "specs" .= serverSpecs
, "welcomeAck" .= serverWelcomeAck
] ]
instance ToTypedContent ServerRes where instance ToTypedContent ServerRes where
toTypedContent = toTypedContent . toJSON toTypedContent = toTypedContent . toJSON

View File

@@ -8,7 +8,7 @@ import Control.Carrier.Lift ( runM )
import Data.Aeson import Data.Aeson
import Data.IORef import Data.IORef
import qualified Data.Text as T import qualified Data.Text as T
import Database.Persist import Database.Persist as Persist
import Yesod.Core.Handler import Yesod.Core.Handler
import Yesod.Persist.Core import Yesod.Persist.Core
import Yesod.Core.Json import Yesod.Core.Json
@@ -56,6 +56,8 @@ getServerR = handleS9ErrT $ do
ssh <- readFromPath settings sshKeysFilePath >>= parseSshKeys ssh <- readFromPath settings sshKeysFilePath >>= parseSshKeys
wifi <- WpaSupplicant.runWlan0 $ liftA2 WifiList WpaSupplicant.getCurrentNetwork WpaSupplicant.listNetworks wifi <- WpaSupplicant.runWlan0 $ liftA2 WifiList WpaSupplicant.getCurrentNetwork WpaSupplicant.listNetworks
specs <- getSpecs settings specs <- getSpecs settings
welcomeAck <- fmap isJust . lift . runDB . Persist.get $ WelcomeAckKey agentVersion
let sid = T.drop 7 $ specsNetworkId specs let sid = T.drop 7 $ specsNetworkId specs
jsonEncode ServerRes { serverId = specsNetworkId specs jsonEncode ServerRes { serverId = specsNetworkId specs
@@ -68,6 +70,7 @@ getServerR = handleS9ErrT $ do
, serverSsh = ssh , serverSsh = ssh
, serverAlternativeRegistryUrl = alternativeRegistryUrl , serverAlternativeRegistryUrl = alternativeRegistryUrl
, serverSpecs = specs , serverSpecs = specs
, serverWelcomeAck = welcomeAck
} }
where where
parseSshKeys :: Text -> S9ErrT Handler [SshKeyFingerprint] parseSshKeys :: Text -> S9ErrT Handler [SshKeyFingerprint]