avoid accepting externaltype= and readonly= parameters for rclone

I think readonly= doesn't make sense here? externaltype= certianly
doesn't.
This commit is contained in:
Joey Hess 2024-04-17 15:41:55 -04:00
parent d55e3f5fe2
commit d2709c6862
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -172,7 +172,7 @@ gen rt externalprogram r u rc gc rs
externalSetup :: Maybe ExternalProgram -> Maybe (String, String) -> SetupStage -> Maybe UUID -> Maybe CredPair -> RemoteConfig -> RemoteGitConfig -> Annex (RemoteConfig, UUID) externalSetup :: Maybe ExternalProgram -> Maybe (String, String) -> SetupStage -> Maybe UUID -> Maybe CredPair -> RemoteConfig -> RemoteGitConfig -> Annex (RemoteConfig, UUID)
externalSetup externalprogram setgitconfig _ mu _ c gc = do externalSetup externalprogram setgitconfig _ mu _ c gc = do
u <- maybe (liftIO genUUID) return mu u <- maybe (liftIO genUUID) return mu
pc <- either giveup return $ parseRemoteConfig c lenientRemoteConfigParser pc <- either giveup return $ parseRemoteConfig c (lenientRemoteConfigParser externalprogram)
let readonlyconfig = getRemoteConfigValue readonlyField pc == Just True let readonlyconfig = getRemoteConfigValue readonlyField pc == Just True
let externaltype = if readonlyconfig let externaltype = if readonlyconfig
then "readonly" then "readonly"
@ -189,7 +189,7 @@ externalSetup externalprogram setgitconfig _ mu _ c gc = do
setConfig (remoteAnnexConfig (fromJust (lookupName c)) "readonly") (boolConfig True) setConfig (remoteAnnexConfig (fromJust (lookupName c)) "readonly") (boolConfig True)
return c' return c'
else do else do
pc' <- either giveup return $ parseRemoteConfig c' lenientRemoteConfigParser pc' <- either giveup return $ parseRemoteConfig c' (lenientRemoteConfigParser externalprogram)
let p = fromMaybe (ExternalType externaltype) externalprogram let p = fromMaybe (ExternalType externaltype) externalprogram
external <- newExternal p (Just u) pc' (Just gc) Nothing Nothing external <- newExternal p (Just u) pc' (Just gc) Nothing Nothing
-- Now that we have an external, ask it to LISTCONFIGS, -- Now that we have an external, ask it to LISTCONFIGS,
@ -862,13 +862,15 @@ getInfoM external = (++)
{- All unknown configs are passed through in case the external program {- All unknown configs are passed through in case the external program
- uses them. -} - uses them. -}
lenientRemoteConfigParser :: RemoteConfigParser lenientRemoteConfigParser :: Maybe ExternalProgram -> RemoteConfigParser
lenientRemoteConfigParser = lenientRemoteConfigParser externalprogram =
addRemoteConfigParser specialRemoteConfigParsers baseRemoteConfigParser addRemoteConfigParser specialRemoteConfigParsers (baseRemoteConfigParser externalprogram)
baseRemoteConfigParser :: RemoteConfigParser baseRemoteConfigParser :: Maybe ExternalProgram -> RemoteConfigParser
baseRemoteConfigParser = RemoteConfigParser baseRemoteConfigParser externalprogram = RemoteConfigParser
{ remoteConfigFieldParsers = { remoteConfigFieldParsers = if isJust extcommand
then []
else
[ optionalStringParser externaltypeField [ optionalStringParser externaltypeField
(FieldDesc "type of external special remote to use") (FieldDesc "type of external special remote to use")
, trueFalseParser readonlyField (Just False) , trueFalseParser readonlyField (Just False)
@ -876,20 +878,25 @@ baseRemoteConfigParser = RemoteConfigParser
] ]
, remoteConfigRestPassthrough = Just , remoteConfigRestPassthrough = Just
( const True ( const True
, [("*", FieldDesc "all other parameters are passed to external special remote program")] , [("*", FieldDesc $ "all other parameters are passed to " ++ fromMaybe "external special remote program" extcommand)]
) )
} }
where
extcommand = case externalprogram of
Just (ExternalCommand c _) -> Just c
_ -> Nothing
{- When the remote supports LISTCONFIGS, only accept the ones it listed. {- When the remote supports LISTCONFIGS, only accept the ones it listed.
- When it does not, accept all configs. -} - When it does not, accept all configs. -}
strictRemoteConfigParser :: External -> Annex RemoteConfigParser strictRemoteConfigParser :: External -> Annex RemoteConfigParser
strictRemoteConfigParser external = listConfigs external >>= \case strictRemoteConfigParser external = listConfigs external >>= \case
Nothing -> return lenientRemoteConfigParser Nothing -> return lcp
Just l -> do Just l -> do
let s = S.fromList (map fst l) let s = S.fromList (map fst l)
let listed f = S.member (fromProposedAccepted f) s let listed f = S.member (fromProposedAccepted f) s
return $ lenientRemoteConfigParser return $ lcp { remoteConfigRestPassthrough = Just (listed, l) }
{ remoteConfigRestPassthrough = Just (listed, l) } where
lcp = lenientRemoteConfigParser (Just (externalProgram external))
listConfigs :: External -> Annex (Maybe [(Setting, FieldDesc)]) listConfigs :: External -> Annex (Maybe [(Setting, FieldDesc)])
listConfigs external = handleRequest external LISTCONFIGS Nothing (collect []) listConfigs external = handleRequest external LISTCONFIGS Nothing (collect [])
@ -907,12 +914,12 @@ remoteConfigParser externalprogram c
-- or when everything in the config was already accepted; in those -- or when everything in the config was already accepted; in those
-- cases the lenient parser will do the same thing as the strict -- cases the lenient parser will do the same thing as the strict
-- parser. -- parser.
| M.null (M.filter isproposed c) = return lenientRemoteConfigParser | M.null (M.filter isproposed c) = return (lenientRemoteConfigParser externalprogram)
| otherwise = case parseRemoteConfig c baseRemoteConfigParser of | otherwise = case parseRemoteConfig c (baseRemoteConfigParser externalprogram) of
Left _ -> return lenientRemoteConfigParser Left _ -> return (lenientRemoteConfigParser externalprogram)
Right pc -> case (getRemoteConfigValue externaltypeField pc, getRemoteConfigValue readonlyField pc) of Right pc -> case (getRemoteConfigValue externaltypeField pc, getRemoteConfigValue readonlyField pc) of
(Nothing, _) -> return lenientRemoteConfigParser (Nothing, _) -> return (lenientRemoteConfigParser externalprogram)
(_, Just True) -> return lenientRemoteConfigParser (_, Just True) -> return (lenientRemoteConfigParser externalprogram)
(Just externaltype, _) -> do (Just externaltype, _) -> do
let p = fromMaybe (ExternalType externaltype) externalprogram let p = fromMaybe (ExternalType externaltype) externalprogram
external <- newExternal p Nothing pc Nothing Nothing Nothing external <- newExternal p Nothing pc Nothing Nothing Nothing