summaryrefslogtreecommitdiff
path: root/Creds.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-12-27 16:01:43 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-12-27 16:01:43 -0400
commitc1cc4d23de10e5669a42164b9145acea732be60d (patch)
treeda75e73f9a0523428233d0e5f644826bae07c379 /Creds.hs
parentc1d48d64b4d93c0a684ef68262b9e14b1b63005d (diff)
add credential storage support for external special remotes & update example
Diffstat (limited to 'Creds.hs')
-rw-r--r--Creds.hs24
1 files changed, 13 insertions, 11 deletions
diff --git a/Creds.hs b/Creds.hs
index c79c16cce..7c300dd07 100644
--- a/Creds.hs
+++ b/Creds.hs
@@ -35,25 +35,27 @@ data CredPairStorage = CredPairStorage
{- Stores creds in a remote's configuration, if the remote allows
- that. Otherwise, caches them locally. -}
setRemoteCredPair :: RemoteConfig -> CredPairStorage -> Annex RemoteConfig
-setRemoteCredPair c storage = go =<< getRemoteCredPair c storage
+setRemoteCredPair c storage =
+ maybe (return c) (setRemoteCredPair' c storage)
+ =<< getRemoteCredPair c storage
+
+setRemoteCredPair' :: RemoteConfig -> CredPairStorage -> CredPair -> Annex RemoteConfig
+setRemoteCredPair' c storage creds
+ | embedCreds c = case credPairRemoteKey storage of
+ Nothing -> localcache
+ Just key -> storeconfig key =<< remoteCipher c
+ | otherwise = localcache
where
- go (Just creds)
- | embedCreds c = case credPairRemoteKey storage of
- Nothing -> localcache creds
- Just key -> storeconfig creds key =<< remoteCipher c
- | otherwise = localcache creds
- go Nothing = return c
-
- localcache creds = do
+ localcache = do
writeCacheCredPair creds storage
return c
- storeconfig creds key (Just cipher) = do
+ storeconfig key (Just cipher) = do
s <- liftIO $ encrypt [] cipher
(feedBytes $ L.pack $ encodeCredPair creds)
(readBytes $ return . L.unpack)
return $ M.insert key (toB64 s) c
- storeconfig creds key Nothing =
+ storeconfig key Nothing =
return $ M.insert key (toB64 $ encodeCredPair creds) c
{- Gets a remote's credpair, from the environment if set, otherwise