be stricter about rejecting invalid configurations for remotes
This is a first step toward that goal, using the ProposedAccepted type in RemoteConfig lets initremote/enableremote reject bad parameters that were passed in a remote's configuration, while avoiding enableremote rejecting bad parameters that have already been stored in remote.log This does not eliminate every place where a remote config is parsed and a default value is used if the parse false. But, I did fix several things that expected foo=yes/no and so confusingly accepted foo=true but treated it like foo=no. There are still some fields that are parsed with yesNo but not not checked when initializing a remote, and there are other fields that are parsed in other ways and not checked when initializing a remote. This also lays groundwork for rejecting unknown/typoed config keys.
This commit is contained in:
parent
ea3f206fd1
commit
71ecfbfccf
45 changed files with 395 additions and 224 deletions
|
@ -24,6 +24,7 @@ import Annex.UUID
|
|||
import Config
|
||||
import Config.DynamicConfig
|
||||
import Types.GitConfig
|
||||
import Types.ProposedAccepted
|
||||
|
||||
import qualified Data.Map as M
|
||||
|
||||
|
@ -41,7 +42,7 @@ start [] = unknownNameError "Specify the remote to enable."
|
|||
start (name:rest) = go =<< filter matchingname <$> Annex.getGitRemotes
|
||||
where
|
||||
matchingname r = Git.remoteName r == Just name
|
||||
go [] = startSpecialRemote name (Logs.Remote.keyValToConfig rest)
|
||||
go [] = startSpecialRemote name (Logs.Remote.keyValToConfig Proposed rest)
|
||||
=<< SpecialRemote.findExisting name
|
||||
go (r:_) = do
|
||||
-- This could be either a normal git remote or a special
|
||||
|
|
|
@ -20,6 +20,7 @@ import Annex.UUID
|
|||
import Logs.UUID
|
||||
import Logs.Remote
|
||||
import Types.GitConfig
|
||||
import Types.ProposedAccepted
|
||||
import Config
|
||||
|
||||
cmd :: Command
|
||||
|
@ -63,7 +64,7 @@ start o (name:ws) = ifM (isJust <$> findExisting name)
|
|||
(Just . Sameas <$$> getParsed)
|
||||
(sameas o)
|
||||
c <- newConfig name sameasuuid
|
||||
(Logs.Remote.keyValToConfig ws)
|
||||
(Logs.Remote.keyValToConfig Proposed ws)
|
||||
<$> readRemoteLog
|
||||
t <- either giveup return (findType c)
|
||||
starting "initremote" (ActionItemOther (Just name)) $
|
||||
|
@ -77,12 +78,12 @@ perform t name c o = do
|
|||
(c', u) <- R.setup t R.Init (sameasu <|> uuidfromuser) Nothing c dummycfg
|
||||
next $ cleanup u name c' o
|
||||
where
|
||||
uuidfromuser = case M.lookup "uuid" c of
|
||||
uuidfromuser = case fromProposedAccepted <$> M.lookup (Accepted "uuid") c of
|
||||
Just s
|
||||
| isUUID s -> Just (toUUID s)
|
||||
| otherwise -> giveup "invalid uuid"
|
||||
Nothing -> Nothing
|
||||
sameasu = toUUID <$> M.lookup sameasUUIDField c
|
||||
sameasu = toUUID . fromProposedAccepted <$> M.lookup sameasUUIDField c
|
||||
|
||||
cleanup :: UUID -> String -> R.RemoteConfig -> InitRemoteOptions -> CommandCleanup
|
||||
cleanup u name c o = do
|
||||
|
|
|
@ -13,6 +13,7 @@ import Annex.SpecialRemote.Config (nameField, sameasNameField)
|
|||
import qualified Logs.Remote
|
||||
import qualified Types.Remote as R
|
||||
import qualified Remote
|
||||
import Types.ProposedAccepted
|
||||
|
||||
import qualified Data.Map as M
|
||||
|
||||
|
@ -50,6 +51,6 @@ perform u cfg mcu newname = do
|
|||
let (namefield, cu) = case mcu of
|
||||
Nothing -> (nameField, u)
|
||||
Just (Annex.SpecialRemote.ConfigFrom u') -> (sameasNameField, u')
|
||||
Logs.Remote.configSet cu (M.insert namefield newname cfg)
|
||||
Logs.Remote.configSet cu (M.insert namefield (Proposed newname) cfg)
|
||||
|
||||
next $ return True
|
||||
|
|
|
@ -24,6 +24,7 @@ import Utility.DataUnits
|
|||
import Utility.CopyFile
|
||||
import Types.Messages
|
||||
import Types.Export
|
||||
import Types.ProposedAccepted
|
||||
import Remote.Helper.ExportImport
|
||||
import Remote.Helper.Chunked
|
||||
import Git.Types
|
||||
|
@ -109,7 +110,7 @@ perform rs unavailrs exportr ks = do
|
|||
desc r' k = intercalate "; " $ map unwords
|
||||
[ [ "key size", show (fromKey keySize k) ]
|
||||
, [ show (getChunkConfig (Remote.config r')) ]
|
||||
, ["encryption", fromMaybe "none" (M.lookup "encryption" (Remote.config r'))]
|
||||
, ["encryption", maybe "none" fromProposedAccepted (M.lookup (Accepted "encryption") (Remote.config r'))]
|
||||
]
|
||||
descexport k1 k2 = intercalate "; " $ map unwords
|
||||
[ [ "exporttree=yes" ]
|
||||
|
@ -119,28 +120,29 @@ perform rs unavailrs exportr ks = do
|
|||
|
||||
adjustChunkSize :: Remote -> Int -> Annex (Maybe Remote)
|
||||
adjustChunkSize r chunksize = adjustRemoteConfig r
|
||||
(M.insert "chunk" (show chunksize))
|
||||
(M.insert (Proposed "chunk") (Proposed (show chunksize)))
|
||||
|
||||
-- Variants of a remote with no encryption, and with simple shared
|
||||
-- encryption. Gpg key based encryption is not tested.
|
||||
encryptionVariants :: Remote -> Annex [Remote]
|
||||
encryptionVariants r = do
|
||||
noenc <- adjustRemoteConfig r (M.insert "encryption" "none")
|
||||
noenc <- adjustRemoteConfig r (M.insert (Proposed "encryption") (Proposed "none"))
|
||||
sharedenc <- adjustRemoteConfig r $
|
||||
M.insert "encryption" "shared" .
|
||||
M.insert "highRandomQuality" "false"
|
||||
M.insert (Proposed "encryption") (Proposed "shared") .
|
||||
M.insert (Proposed "highRandomQuality") (Proposed "false")
|
||||
return $ catMaybes [noenc, sharedenc]
|
||||
|
||||
-- Variant of a remote with exporttree disabled.
|
||||
disableExportTree :: Remote -> Annex Remote
|
||||
disableExportTree r = maybe (error "failed disabling exportree") return
|
||||
=<< adjustRemoteConfig r (M.delete "exporttree")
|
||||
=<< adjustRemoteConfig r (M.delete (Accepted "exporttree"))
|
||||
|
||||
-- Variant of a remote with exporttree enabled.
|
||||
exportTreeVariant :: Remote -> Annex (Maybe Remote)
|
||||
exportTreeVariant r = ifM (Remote.isExportSupported r)
|
||||
( adjustRemoteConfig r $
|
||||
M.insert "encryption" "none" . M.insert "exporttree" "yes"
|
||||
M.insert (Proposed "encryption") (Proposed "none") .
|
||||
M.insert (Proposed "exporttree") (Proposed "yes")
|
||||
, return Nothing
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue