diff options
| author | Joey Hess <joeyh@joeyh.name> | 2014-12-14 15:24:21 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2014-12-14 15:24:21 -0400 |
| commit | fbf9cc6f2b66ba5e56993a239e511cc6bae4af54 (patch) | |
| tree | cd00a21d0a0b27603374a04f3de505facee651ec /src/Propellor/PrivData.hs | |
| parent | 9d06d2f835143c308bc409b7dc737c4292d9bc72 (diff) | |
| parent | 71723ca09f369ccf96462cef1e0200e1615677d1 (diff) | |
Merge branch 'joeyconfig'
Diffstat (limited to 'src/Propellor/PrivData.hs')
| -rw-r--r-- | src/Propellor/PrivData.hs | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/src/Propellor/PrivData.hs b/src/Propellor/PrivData.hs index 06438515..b0228b46 100644 --- a/src/Propellor/PrivData.hs +++ b/src/Propellor/PrivData.hs @@ -53,18 +53,43 @@ withPrivData -> c -> (((PrivData -> Propellor Result) -> Propellor Result) -> Property) -> Property -withPrivData field c mkprop = addinfo $ mkprop $ \a -> - maybe missing a =<< get +withPrivData field = withPrivData' snd [field] + +-- Like withPrivData, but here any of a list of PrivDataFields can be used. +withSomePrivData + :: IsContext c + => [PrivDataField] + -> c + -> ((((PrivDataField, PrivData) -> Propellor Result) -> Propellor Result) -> Property) + -> Property +withSomePrivData = withPrivData' id + +withPrivData' + :: IsContext c + => ((PrivDataField, PrivData) -> v) + -> [PrivDataField] + -> c + -> (((v -> Propellor Result) -> Propellor Result) -> Property) + -> Property +withPrivData' feed fieldlist c mkprop = addinfo $ mkprop $ \a -> + maybe missing (a . feed) =<< getM get fieldlist where - get = do + get field = do context <- mkHostContext hc <$> asks hostName - liftIO $ getLocalPrivData field context + maybe Nothing (\privdata -> Just (field, privdata)) + <$> liftIO (getLocalPrivData field context) missing = do Context cname <- mkHostContext hc <$> asks hostName - warningMessage $ "Missing privdata " ++ show field ++ " (for " ++ cname ++ ")" - liftIO $ putStrLn $ "Fix this by running: propellor --set '" ++ show field ++ "' '" ++ cname ++ "'" + warningMessage $ "Missing privdata " ++ intercalate " or " fieldnames ++ " (for " ++ cname ++ ")" + liftIO $ putStrLn $ "Fix this by running:" + liftIO $ forM_ fieldlist $ \f -> do + putStrLn $ " propellor --set '" ++ show f ++ "' '" ++ cname ++ "'" + putStrLn $ " < ( " ++ howtoMkPrivDataField f ++ " )" + putStrLn "" return FailedChange - addinfo p = p { propertyInfo = propertyInfo p <> mempty { _privDataFields = S.singleton (field, hc) } } + addinfo p = p { propertyInfo = propertyInfo p <> mempty { _privDataFields = fieldset } } + fieldnames = map show fieldlist + fieldset = S.fromList $ zip fieldlist (repeat hc) hc = asHostContext c addPrivDataField :: (PrivDataField, HostContext) -> Property |
