summaryrefslogtreecommitdiff
path: root/Logs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2020-01-10 14:10:20 -0400
committerJoey Hess <joeyh@joeyh.name>2020-01-10 14:52:48 -0400
commit71ecfbfccf1f1d1dd3d83d79f80b694398e1092b (patch)
tree02dc973fcf4bf989138cea1bd70569c7e1431343 /Logs
parentea3f206fd110e4063e8f1cbe3b330085ab631ce2 (diff)
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.
Diffstat (limited to 'Logs')
-rw-r--r--Logs/Remote/Pure.hs19
1 files changed, 10 insertions, 9 deletions
diff --git a/Logs/Remote/Pure.hs b/Logs/Remote/Pure.hs
index e855d87200..7d05269be6 100644
--- a/Logs/Remote/Pure.hs
+++ b/Logs/Remote/Pure.hs
@@ -19,6 +19,7 @@ module Logs.Remote.Pure (
import Annex.Common
import Types.Remote
+import Types.ProposedAccepted
import Logs.UUIDBased
import Annex.SpecialRemote.Config
@@ -40,24 +41,24 @@ buildRemoteConfigLog :: Log RemoteConfig -> Builder
buildRemoteConfigLog = buildLogOld (byteString . encodeBS . showConfig)
remoteConfigParser :: A.Parser RemoteConfig
-remoteConfigParser = keyValToConfig . words . decodeBS <$> A.takeByteString
+remoteConfigParser = keyValToConfig Accepted . words . decodeBS <$> A.takeByteString
showConfig :: RemoteConfig -> String
showConfig = unwords . configToKeyVal
{- Given Strings like "key=value", generates a RemoteConfig. -}
-keyValToConfig :: [String] -> RemoteConfig
-keyValToConfig ws = M.fromList $ map (/=/) ws
+keyValToConfig :: (String -> ProposedAccepted String) -> [String] -> RemoteConfig
+keyValToConfig mk ws = M.fromList $ map (/=/) ws
where
- (/=/) s = (k, v)
+ (/=/) s = (mk k, mk v)
where
k = takeWhile (/= '=') s
v = configUnEscape $ drop (1 + length k) s
-configToKeyVal :: M.Map String String -> [String]
+configToKeyVal :: RemoteConfig -> [String]
configToKeyVal m = map toword $ sort $ M.toList m
where
- toword (k, v) = k ++ "=" ++ configEscape v
+ toword (k, v) = fromProposedAccepted k ++ "=" ++ configEscape (fromProposedAccepted v)
configEscape :: String -> String
configEscape = concatMap escape
@@ -90,9 +91,9 @@ prop_isomorphic_configEscape s = s == (configUnEscape . configEscape) s
prop_parse_show_Config :: RemoteConfig -> Bool
prop_parse_show_Config c
-- whitespace and '=' are not supported in config keys
- | any (\k -> any isSpace k || elem '=' k) (M.keys c) = True
- | any (any excluded) (M.keys c) = True
- | any (any excluded) (M.elems c) = True
+ | any (\k -> any isSpace k || elem '=' k) (map fromProposedAccepted $ M.keys c) = True
+ | any (any excluded) (map fromProposedAccepted $ M.keys c) = True
+ | any (any excluded) (map fromProposedAccepted $ M.elems c) = True
| otherwise = A.parseOnly remoteConfigParser (encodeBS $ showConfig c) ~~ Right c
where
normalize v = sort . M.toList <$> v