avoid getting creds from environment during autoenable

When autoenabling special remotes of type S3, weddav, or glacier, do not
take login credentials from environment variables, as the user may not be
expecting the autoenable to happen, and may have those set for other
purposes.
This commit is contained in:
Joey Hess 2021-03-17 09:41:12 -04:00
parent 02e74c010b
commit 0e44c252c8
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
14 changed files with 72 additions and 37 deletions

View file

@ -273,7 +273,7 @@ s3Setup' ss u mcreds c gc
(c', encsetup) <- encryptionSetup (c `M.union` defaults) gc
pc <- either giveup return . parseRemoteConfig c'
=<< configParser remote c'
c'' <- setRemoteCredPair encsetup pc gc (AWS.creds u) mcreds
c'' <- setRemoteCredPair ss encsetup pc gc (AWS.creds u) mcreds
pc' <- either giveup return . parseRemoteConfig c''
=<< configParser remote c''
info <- extractS3Info pc'
@ -287,14 +287,14 @@ s3Setup' ss u mcreds c gc
showNote "Internet Archive mode"
pc <- either giveup return . parseRemoteConfig c
=<< configParser remote c
c' <- setRemoteCredPair noEncryptionUsed pc gc (AWS.creds u) mcreds
c' <- setRemoteCredPair ss noEncryptionUsed pc gc (AWS.creds u) mcreds
-- Ensure user enters a valid bucket name, since
-- this determines the name of the archive.org item.
let validbucket = replace " " "-" $ map toLower $
maybe (giveup "specify bucket=") fromProposedAccepted
(M.lookup bucketField c')
let archiveconfig =
-- IA acdepts x-amz-* as an alias for x-archive-*
-- IA accepts x-amz-* as an alias for x-archive-*
M.mapKeys (Proposed . replace "x-archive-" "x-amz-" . fromProposedAccepted) $
-- encryption does not make sense here
M.insert encryptionField (Proposed "none") $
@ -1273,11 +1273,8 @@ enableBucketVersioning ss info _ _ _ = do
case ss of
Init -> when (versioning info) $
enableversioning (bucket info)
Enable oldc -> do
oldpc <- parsedRemoteConfig remote oldc
oldinfo <- extractS3Info oldpc
when (versioning info /= versioning oldinfo) $
giveup "Cannot change versioning= of existing S3 remote."
Enable oldc -> checkunchanged oldc
AutoEnable oldc -> checkunchanged oldc
where
enableversioning b = do
#if MIN_VERSION_aws(0,21,1)
@ -1296,6 +1293,12 @@ enableBucketVersioning ss info _ _ _ = do
]
#endif
checkunchanged oldc = do
oldpc <- parsedRemoteConfig remote oldc
oldinfo <- extractS3Info oldpc
when (versioning info /= versioning oldinfo) $
giveup "Cannot change versioning= of existing S3 remote."
-- If the remote has versioning enabled, but the version ID is for some
-- reason not being recorded, it's not safe to perform an action that
-- will remove the unversioned file. The file may be the only copy of an