diff --git a/obelisk/config/common/servers.yaml b/obelisk/config/common/servers.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5f56fd1fd535e20df99cce4452c3cf20b5c56128 --- /dev/null +++ b/obelisk/config/common/servers.yaml @@ -0,0 +1,8 @@ +# 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 diff --git a/obelisk/frontend/src/App.hs b/obelisk/frontend/src/App.hs index 7a4a8cacf008854e853c13623c0126604767c99c..e195a2126cb2c2829eca250f2637d82711cb8f09 100644 --- a/obelisk/frontend/src/App.hs +++ b/obelisk/frontend/src/App.hs @@ -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. diff --git a/obelisk/frontend/src/MagicFolder.hs b/obelisk/frontend/src/MagicFolder.hs index 4c03696014958b2c42da375d8459f311a1f3f71f..89be393d23edeb817ed72f1963a1a2dd17ac36df 100644 --- a/obelisk/frontend/src/MagicFolder.hs +++ b/obelisk/frontend/src/MagicFolder.hs @@ -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 - 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 - |] + Nothing -> pure . Left $ "Could not load grid configuration" + Just bytes -> + pure . first renderError $ decodeEither' bytes + where + renderError = T.concat . ("Could not parse grid configuration: ":) . (:[]) . T.pack . show -- | Load the configured magic-folder collective capabilities. --