summaryrefslogtreecommitdiff
path: root/src/Propellor/PrivData.hs
diff options
context:
space:
mode:
authorJoey Hess2015-01-24 22:38:10 -0400
committerJoey Hess2015-01-24 22:38:51 -0400
commit0ee04ecc43e047b00437fb660e71f7dd67dd3afc (patch)
tree621e0ebc68a2afb9410ce6f368bec865f31cc507 /src/Propellor/PrivData.hs
parent141a7c028bba8d5b9743f2ab1397e69c313a523c (diff)
GADT properties seem to work (untested)
* Property has been converted to a GADT, and will be Property NoInfo or Property HasInfo. This was done to make sure that ensureProperty is only used on properties that do not have Info. Transition guide: - Change all "Property" to "Property NoInfo" or "Property WithInfo" (The compiler can tell you if you got it wrong!) - To construct a RevertableProperty, it is useful to use the new (<!>) operator - Constructing a list of properties can be problimatic, since Property NoInto and Property WithInfo are different types and cannot appear in the same list. To deal with this, "props" has been added, and can built up a list of properties of different types, using the same (&) and (!) operators that are used to build up a host's properties.
Diffstat (limited to 'src/Propellor/PrivData.hs')
-rw-r--r--src/Propellor/PrivData.hs23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/Propellor/PrivData.hs b/src/Propellor/PrivData.hs
index 1e7a9d28..71aa820d 100644
--- a/src/Propellor/PrivData.hs
+++ b/src/Propellor/PrivData.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE PackageImports #-}
+{-# LANGUAGE FlexibleContexts #-}
module Propellor.PrivData (
withPrivData,
@@ -60,29 +61,29 @@ import Utility.Table
-- being used, which is necessary to ensure that the privdata is sent to
-- the remote host by propellor.
withPrivData
- :: (IsContext c, IsPrivDataSource s)
+ :: (IsContext c, IsPrivDataSource s, IsProp (Property i))
=> s
-> c
- -> (((PrivData -> Propellor Result) -> Propellor Result) -> Property)
- -> Property
+ -> (((PrivData -> Propellor Result) -> Propellor Result) -> Property i)
+ -> Property HasInfo
withPrivData s = withPrivData' snd [s]
-- Like withPrivData, but here any one of a list of PrivDataFields can be used.
withSomePrivData
- :: (IsContext c, IsPrivDataSource s)
+ :: (IsContext c, IsPrivDataSource s, IsProp (Property i))
=> [s]
-> c
- -> ((((PrivDataField, PrivData) -> Propellor Result) -> Propellor Result) -> Property)
- -> Property
+ -> ((((PrivDataField, PrivData) -> Propellor Result) -> Propellor Result) -> Property i)
+ -> Property HasInfo
withSomePrivData = withPrivData' id
withPrivData'
- :: (IsContext c, IsPrivDataSource s)
+ :: (IsContext c, IsPrivDataSource s, IsProp (Property i))
=> ((PrivDataField, PrivData) -> v)
-> [s]
-> c
- -> (((v -> Propellor Result) -> Propellor Result) -> Property)
- -> Property
+ -> (((v -> Propellor Result) -> Propellor Result) -> Property i)
+ -> Property HasInfo
withPrivData' feed srclist c mkprop = addinfo $ mkprop $ \a ->
maybe missing (a . feed) =<< getM get fieldlist
where
@@ -97,7 +98,7 @@ withPrivData' feed srclist c mkprop = addinfo $ mkprop $ \a ->
liftIO $ showSet $
map (\s -> (privDataField s, Context cname, describePrivDataSource s)) srclist
return FailedChange
- addinfo p = mkProperty
+ addinfo p = infoProperty
(propertyDesc p)
(propertySatisfy p)
(propertyInfo p <> mempty { _privData = privset })
@@ -113,7 +114,7 @@ showSet l = forM_ l $ \(f, Context c, md) -> do
maybe noop (\d -> putStrLn $ " " ++ d) md
putStrLn ""
-addPrivData :: (PrivDataField, Maybe PrivDataSourceDesc, HostContext) -> Property
+addPrivData :: (PrivDataField, Maybe PrivDataSourceDesc, HostContext) -> Property HasInfo
addPrivData v = pureInfoProperty (show v) $
mempty { _privData = S.singleton v }