webapp: Now automatically fills in any creds used by an existing remote when creating a new remote of the same type. Done for Internet Archive, S3, Glacier, and Box.com remotes.

This commit is contained in:
Joey Hess 2013-04-27 15:16:06 -04:00
parent 8626e67e97
commit c3498042fd
6 changed files with 122 additions and 50 deletions

View file

@ -7,7 +7,7 @@
{-# LANGUAGE ScopedTypeVariables, CPP #-}
module Remote.WebDAV (remote, davCreds, setCredsEnv) where
module Remote.WebDAV (remote, davCreds, setCredsEnv, configUrl) where
import Network.Protocol.HTTP.DAV
import qualified Data.Map as M
@ -203,11 +203,14 @@ withStoredFiles r k baseurl user pass onerr a
davAction :: Remote -> a -> ((DavUrl, DavUser, DavPass) -> Annex a) -> Annex a
davAction r unconfigured action = do
mcreds <- getCreds (config r) (uuid r)
case (mcreds, M.lookup "url" $ config r) of
case (mcreds, configUrl r) of
(Just (user, pass), Just url) ->
action (url, toDavUser user, toDavPass pass)
_ -> return unconfigured
configUrl :: Remote -> Maybe DavUrl
configUrl r = M.lookup "url" $ config r
toDavUser :: String -> DavUser
toDavUser = B8.fromString