external: SETCREDS include creds in externalConfigChanges

This makes the creds get saved, since only things recorded there will be
saved.

IIRC, unparsedRemoteConfig was not originally available when I
implemented this; now that it is things get a bit simpler.

More could probably be simplified, is externalConfigChanges needed at
all?

This does not entirely fix the bugs though, because creds are only
embedded when embedcreds=yes, but not when encryption=pubkey is used
without embedcreds=yes.
This commit is contained in:
Joey Hess 2020-06-16 17:24:24 -04:00
parent 9fb549b3f1
commit a1d4c8e4ec
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 40 additions and 19 deletions

View file

@ -57,20 +57,25 @@ data CredPairStorage = CredPairStorage
- if that's going to be done, so that the creds can be encrypted using the
- cipher. The EncryptionIsSetup is witness to that being the case.
-}
setRemoteCredPair :: EncryptionIsSetup -> ParsedRemoteConfig -> RemoteGitConfig -> CredPairStorage -> Maybe CredPair -> Annex RemoteConfig
setRemoteCredPair encsetup pc = setRemoteCredPair' id (const pc) encsetup (unparsedRemoteConfig pc)
setRemoteCredPair'
:: (ProposedAccepted String -> a)
-> (M.Map RemoteConfigField a -> ParsedRemoteConfig)
-> EncryptionIsSetup
-> M.Map RemoteConfigField a
setRemoteCredPair
:: EncryptionIsSetup
-> ParsedRemoteConfig
-> RemoteGitConfig
-> CredPairStorage
-> Maybe CredPair
-> Annex (M.Map RemoteConfigField a)
setRemoteCredPair' mkval parseconfig encsetup c gc storage mcreds = case mcreds of
Nothing -> maybe (return c) (setRemoteCredPair' mkval parseconfig encsetup c gc storage . Just)
-> Annex RemoteConfig
setRemoteCredPair encsetup pc gc storage mcreds = unparsedRemoteConfig <$>
setRemoteCredPair' pc encsetup gc storage mcreds
setRemoteCredPair'
:: ParsedRemoteConfig
-> EncryptionIsSetup
-> RemoteGitConfig
-> CredPairStorage
-> Maybe CredPair
-> Annex ParsedRemoteConfig
setRemoteCredPair' pc encsetup gc storage mcreds = case mcreds of
Nothing -> maybe (return pc) (setRemoteCredPair' pc encsetup gc storage . Just)
=<< getRemoteCredPair pc gc storage
Just creds
| embedCreds pc -> do
@ -79,7 +84,7 @@ setRemoteCredPair' mkval parseconfig encsetup c gc storage mcreds = case mcreds
storeconfig creds key =<< remoteCipher pc gc
| otherwise -> do
localcache creds
return c
return pc
where
localcache creds = writeCacheCredPair creds storage
@ -88,11 +93,14 @@ setRemoteCredPair' mkval parseconfig encsetup c gc storage mcreds = case mcreds
s <- liftIO $ encrypt cmd (pc, gc) cipher
(feedBytes $ L.pack $ encodeCredPair creds)
(readBytesStrictly $ return . S.unpack)
return $ M.insert key (mkval (Accepted (toB64 s))) c
storeconfig' key (Accepted (toB64 s))
storeconfig creds key Nothing =
return $ M.insert key (mkval (Accepted (toB64 $ encodeCredPair creds))) c
storeconfig' key (Accepted (toB64 $ encodeCredPair creds))
pc = parseconfig c
storeconfig' key val = return $ pc
{ parsedRemoteConfigMap = M.insert key (RemoteConfigValue val) (parsedRemoteConfigMap pc)
, unparsedRemoteConfig = M.insert key val (unparsedRemoteConfig pc)
}
{- Gets a remote's credpair, from the environment if set, otherwise
- from the cache in gitAnnexCredsDir, or failing that, from the