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]
, serverAlternativeRegistryUrl :: Maybe Text
, serverSpecs :: SpecsRes
, serverWelcomeAck :: Bool
}
deriving (Eq, Show)
@@ -57,6 +58,7 @@ instance ToJSON ServerRes where
, "ssh" .= serverSsh
, "alternativeRegistryUrl" .= serverAlternativeRegistryUrl
, "specs" .= serverSpecs
, "welcomeAck" .= serverWelcomeAck
]
instance ToTypedContent ServerRes where
toTypedContent = toTypedContent . toJSON

View File

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