include passthrough params in --describe-other-params

This commit is contained in:
Joey Hess 2020-01-20 16:23:35 -04:00
parent aa949bbb7d
commit 2be4122bfc
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
8 changed files with 46 additions and 27 deletions

View file

@ -189,7 +189,7 @@ parseRemoteConfig c rpc =
where where
go l c' [] = go l c' [] =
let (passover, leftovers) = partition let (passover, leftovers) = partition
(remoteConfigRestPassthrough rpc . fst) (maybe (const False) fst (remoteConfigRestPassthrough rpc) . fst)
(M.toList c') (M.toList c')
leftovers' = filter (notaccepted . fst) leftovers leftovers' = filter (notaccepted . fst) leftovers
in if not (null leftovers') in if not (null leftovers')

View file

@ -114,22 +114,22 @@ cleanup u name c o = do
describeOtherParamsFor :: RemoteConfig -> RemoteType -> CommandPerform describeOtherParamsFor :: RemoteConfig -> RemoteType -> CommandPerform
describeOtherParamsFor c t = do describeOtherParamsFor c t = do
cp <- R.configParser t c cp <- R.configParser t c
let l = mapMaybe mk $ filter notinconfig $ remoteConfigFieldParsers cp let l = map mk (filter notinconfig $ remoteConfigFieldParsers cp)
liftIO $ forM_ l $ \(p, pd, vd) -> do ++ map mk' (maybe [] snd (remoteConfigRestPassthrough cp))
putStrLn p liftIO $ forM_ l $ \(p, fd, vd) -> case fd of
putStrLn ("\t" ++ pd) HiddenField -> return ()
case vd of FieldDesc d -> do
Nothing -> return () putStrLn p
Just vd' -> putStrLn $ "\t(" ++ vd' ++ ")" putStrLn ("\t" ++ d)
case vd of
Nothing -> return ()
Just (ValueDesc d') ->
putStrLn $ "\t(" ++ d' ++ ")"
next $ return True next $ return True
where where
notinconfig fp = not (M.member (parserForField fp) c) notinconfig fp = not (M.member (parserForField fp) c)
mk fp = case fieldDesc fp of mk fp = ( fromProposedAccepted (parserForField fp)
HiddenField -> Nothing , fieldDesc fp
FieldDesc d -> Just , valueDesc fp
( fromProposedAccepted (parserForField fp) )
, d mk' (k, v) = (k, v, Nothing)
, case valueDesc fp of
Nothing -> Nothing
Just (ValueDesc vd) -> Just vd
)

View file

@ -792,7 +792,10 @@ lenientRemoteConfigParser = addRemoteConfigParser specialRemoteConfigParsers $
, trueFalseParser readonlyField False , trueFalseParser readonlyField False
(FieldDesc "enable readonly mode") (FieldDesc "enable readonly mode")
] ]
, remoteConfigRestPassthrough = const True , remoteConfigRestPassthrough = Just
( const True
, [("*", FieldDesc "all other parameters are passed to external special remote program")]
)
} }
{- When the remote supports LISTCONFIGS, only accept the ones it listed. {- When the remote supports LISTCONFIGS, only accept the ones it listed.
@ -804,14 +807,14 @@ strictRemoteConfigParser external = listConfigs external >>= \case
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 $ lenientRemoteConfigParser
{ remoteConfigRestPassthrough = listed } { remoteConfigRestPassthrough = Just (listed, l) }
listConfigs :: External -> Annex (Maybe [(Setting, Description)]) listConfigs :: External -> Annex (Maybe [(Setting, FieldDesc)])
listConfigs external = handleRequest external LISTCONFIGS Nothing (collect []) listConfigs external = handleRequest external LISTCONFIGS Nothing (collect [])
where where
collect l req = case req of collect l req = case req of
CONFIG s d -> Just $ return $ CONFIG s d -> Just $ return $
GetNextMessage $ collect ((s, d) : l) GetNextMessage $ collect ((s, FieldDesc d) : l)
CONFIGEND -> result (Just (reverse l)) CONFIGEND -> result (Just (reverse l))
UNSUPPORTED_REQUEST -> result Nothing UNSUPPORTED_REQUEST -> result Nothing
_ -> Nothing _ -> Nothing

View file

@ -78,7 +78,7 @@ encryptionConfigs = S.fromList (map parserForField encryptionConfigParsers)
parseEncryptionConfig :: RemoteConfig -> Either String ParsedRemoteConfig parseEncryptionConfig :: RemoteConfig -> Either String ParsedRemoteConfig
parseEncryptionConfig c = parseRemoteConfig parseEncryptionConfig c = parseRemoteConfig
(M.restrictKeys c encryptionConfigs) (M.restrictKeys c encryptionConfigs)
(RemoteConfigParser encryptionConfigParsers (const False)) (RemoteConfigParser encryptionConfigParsers Nothing)
encryptionFieldParser :: RemoteConfigFieldParser encryptionFieldParser :: RemoteConfigFieldParser
encryptionFieldParser = RemoteConfigFieldParser encryptionFieldParser = RemoteConfigFieldParser

View file

@ -102,8 +102,13 @@ remote = specialRemoteType $ RemoteType
, optionalStringParser mungekeysField HiddenField , optionalStringParser mungekeysField HiddenField
, optionalStringParser AWS.s3credsField HiddenField , optionalStringParser AWS.s3credsField HiddenField
] ]
, remoteConfigRestPassthrough = \f -> , remoteConfigRestPassthrough = Just
isMetaHeader f || isArchiveMetaHeader f ( \f -> isMetaHeader f || isArchiveMetaHeader f
,
[ ("x-amz-meta-*", FieldDesc "http headers to add when storing on S3")
, ("x-archive-meta-*", FieldDesc "http headers to add when storing on Internet Archive")
]
)
} }
, setup = s3Setup , setup = s3Setup
, exportSupported = exportIsSupported , exportSupported = exportIsSupported

View file

@ -53,11 +53,11 @@ newtype ValueDesc = ValueDesc String
data RemoteConfigParser = RemoteConfigParser data RemoteConfigParser = RemoteConfigParser
{ remoteConfigFieldParsers :: [RemoteConfigFieldParser] { remoteConfigFieldParsers :: [RemoteConfigFieldParser]
, remoteConfigRestPassthrough :: RemoteConfigField -> Bool , remoteConfigRestPassthrough :: Maybe (RemoteConfigField -> Bool, [(String, FieldDesc)])
} }
mkRemoteConfigParser :: Monad m => [RemoteConfigFieldParser] -> RemoteConfig -> m RemoteConfigParser mkRemoteConfigParser :: Monad m => [RemoteConfigFieldParser] -> RemoteConfig -> m RemoteConfigParser
mkRemoteConfigParser l _ = pure (RemoteConfigParser l (const False)) mkRemoteConfigParser l _ = pure (RemoteConfigParser l Nothing)
addRemoteConfigParser :: [RemoteConfigFieldParser] -> RemoteConfigParser -> RemoteConfigParser addRemoteConfigParser :: [RemoteConfigFieldParser] -> RemoteConfigParser -> RemoteConfigParser
addRemoteConfigParser l rpc = rpc addRemoteConfigParser l rpc = rpc

View file

@ -140,4 +140,9 @@ the S3 remote.
then use the same bucket. then use the same bucket.
* `x-amz-meta-*` are passed through as http headers when storing keys * `x-amz-meta-*` are passed through as http headers when storing keys
in S3. see [the Internet Archive S3 interface documentation](https://archive.org/help/abouts3.txt) for example headers. in S3.
* `x-archive-meta-*` are passed through as http headers when storing keys
in the Internet Archive. See
[the Internet Archive S3 interface documentation](https://archive.org/help/abouts3.txt)
for example headers.

View file

@ -9,3 +9,9 @@ and indeed I get asked for e.g. encryption to be explicitly specified (why not t
[[!meta author=yoh]] [[!meta author=yoh]]
[[!tag projects/datalad]] [[!tag projects/datalad]]
> [[done]] as eg `git annex initremote type=rsync --describe-other-params`.
>
> External special remotes that implement LISTCONFIGS can also be queried:
>
> git annex inittype type=external externaltype=foo --describe-other-params