summaryrefslogtreecommitdiff
path: root/src/Propellor/Types/Info.hs
diff options
context:
space:
mode:
authorJoey Hess2015-09-30 15:33:14 -0400
committerJoey Hess2015-09-30 15:33:14 -0400
commit84561f6c429a59eaccfc6b957166baf66f7133a1 (patch)
treed5578fcf44df414c9e7c5c3435610fd4ceda0d77 /src/Propellor/Types/Info.hs
parent47ed1b33c3943852e01a4f376aa85187c07e52b7 (diff)
change HostContext for containers
Privdata that uses HostContext inside a container will now have the name of the container as its context, rather than the name of the host(s) where the container is used. This allows eg, having different passwords for a user in different containers. Note that previously, propellor would prompt using the container name as the context, but not actually use privdata using that context; so this is a bug fix. I don't entirely like the implementation; I had to put the code to change the context in PropAccum, and it's not generalized past PrivInfo.
Diffstat (limited to 'src/Propellor/Types/Info.hs')
-rw-r--r--src/Propellor/Types/Info.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/Propellor/Types/Info.hs b/src/Propellor/Types/Info.hs
index a80bb681..347a03e7 100644
--- a/src/Propellor/Types/Info.hs
+++ b/src/Propellor/Types/Info.hs
@@ -5,6 +5,7 @@ module Propellor.Types.Info (
IsInfo(..),
addInfo,
getInfo,
+ mapInfo,
propigatableInfo,
InfoVal(..),
fromInfoVal,
@@ -16,8 +17,6 @@ import Data.Monoid
import Data.Maybe
-- | Information about a Host, which can be provided by its properties.
---
--- Any value in the `IsInfo` type class can be added to an Info.
data Info = Info [(Dynamic, Bool)]
instance Show Info where
@@ -37,12 +36,22 @@ class (Typeable v, Monoid v) => IsInfo v where
-- container to its Host?
propigateInfo :: v -> Bool
+-- | Any value in the `IsInfo` type class can be added to an Info.
addInfo :: IsInfo v => Info -> v -> Info
addInfo (Info l) v = Info ((toDyn v, propigateInfo v):l)
getInfo :: IsInfo v => Info -> v
getInfo (Info l) = mconcat (mapMaybe (fromDynamic . fst) (reverse l))
+-- | Maps a function over all values stored in the Info that are of the
+-- appropriate type.
+mapInfo :: IsInfo v => (v -> v) -> Info -> Info
+mapInfo f (Info l) = Info (map go l)
+ where
+ go (i, p) = case fromDynamic i of
+ Nothing -> (i, p)
+ Just v -> (toDyn (f v), p)
+
-- | Filters out parts of the Info that should not propigate out of a
-- container.
propigatableInfo :: Info -> Info