Skip to content
Snippets Groups Projects
Commit cca6808e authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

Merge branch 'grid-as-configuration' into 'main'

Read grid configuration using the Obelisk "Config" system

Closes #59

See merge request !55
parents f9d9fc9c 7ac19755
Branches
Tags
1 merge request!55Read grid configuration using the Obelisk "Config" system
Pipeline #4894 passed
# The Private Storage staging grid configuration.
storage:
v0-roiqkiw76qcj7gcilbbut52rsxofubqugqtgnap3rgncutdueoda:
ann:
anonymous-storage-FURL: pb://oykwjvglr5h7elum5zlfll7vgiayd2ey@tcp:storage001.privatestorage-staging.com:8899/u2urs2aqarw2euuxddby7dvxkdd2rsuc
nickname: storage001
anonymous-storage-NURLs:
- pb://oykwjvglr5h7elum5zlfll7vgiayd2ey@tcp:storage001.privatestorage-staging.com:8899/u2urs2aqarw2euuxddby7dvxkdd2rsuc
......@@ -26,7 +26,7 @@ import Reflex
, foldDyn
, fmapMaybe
)
import Obelisk.Configs (HasConfigs)
import Tahoe.Announcement (Announcements)
import MagicFolder (MagicFolder, loadGrid, loadMagicFolders, readMagicFolder)
......@@ -50,6 +50,7 @@ initialApp
, PerformEvent t m
, TriggerEvent t m
, MonadIO (Performable m)
, HasConfigs (Performable m)
)
=> Event t () -- ^ An event to trigger loading the state.
-> m (App t) -- ^ The loaded application state.
......
......@@ -4,6 +4,7 @@
module MagicFolder where
import Data.Bifunctor (first)
import Text.Megaparsec (parse)
import qualified Data.Map.Strict as Map
import qualified Tahoe.Directory as Directory
......@@ -12,9 +13,10 @@ import Text.RawString.QQ (r)
import qualified Data.Text as T
import Data.Yaml (decodeEither')
import Tahoe.Announcement (Announcements(..))
import Control.Monad.IO.Class (MonadIO(liftIO))
import Control.Monad.IO.Class (MonadIO)
import Control.Exception (SomeException)
import qualified Tahoe.MagicFoldr as MF
import Obelisk.Configs (HasConfigs(getConfig))
data MagicFolder =
MagicFolder
......@@ -29,27 +31,15 @@ newtype EntryName = EntryName { unEntryName :: T.Text } deriving (Eq, Ord, Show)
-- | Load the announcements for the grid to use for downloads.
--
-- This reads "servers.yaml" from the application-private files directory.
loadGrid :: MonadIO m => m (Either T.Text Announcements)
loadGrid = liftIO $ do
loadGrid :: HasConfigs m => m (Either T.Text Announcements)
loadGrid = do
announcementsBytes <- getConfig "common/servers.yaml"
case announcementsBytes of
Left err -> pure $ Left $ T.concat ["Could not read grid configuration: ", T.pack $ show (err :: SomeException)]
Right bytes ->
case decodeEither' bytes of
Left err -> pure $ Left $ T.concat ["Could not parse grid configuration: ", T.pack $ show err]
Right ann -> pure $ Right ann
Nothing -> pure . Left $ "Could not load grid configuration"
Just bytes ->
pure . first renderError $ decodeEither' bytes
where
-- TODO: Figure out how we can distribute this yaml in a separate file and
-- still be able to get at its contents, even on Android.
announcementsBytes =
Right [r|
storage:
v0-roiqkiw76qcj7gcilbbut52rsxofubqugqtgnap3rgncutdueoda:
ann:
anonymous-storage-FURL: pb://gnuer2axzoq3ggnn7gjoybmfqsjvaow3@tcp:magnon:46185/sxytycucj5eeunlx6modfazq5byp2hpb
nickname: storage001
anonymous-storage-NURLs:
- pb://4cD3anuFqhz81xiI2dtRj7eDJLsCFNXrHZZExUXotfE@magnon:46185/sxytycucj5eeunlx6modfazq5byp2hpb#v=1
|]
renderError = T.concat . ("Could not parse grid configuration: ":) . (:[]) . T.pack . show
-- | Load the configured magic-folder collective capabilities.
--
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment