{-# LANGUAGE DataKinds, TypeFamilies #-}
module Propellor.Container where
import Propellor.Types
import Propellor.Types.Core
import Propellor.Types.MetaTypes
import Propellor.Types.Info
import Propellor.Info
import Propellor.PrivData
import Propellor.PropAccum
class IsContainer c where
containerProperties :: c -> [ChildProperty]
containerInfo :: c -> Info
setContainerProperties :: c -> [ChildProperty] -> c
instance IsContainer Host where
containerProperties = hostProperties
containerInfo = hostInfo
setContainerProperties h ps = host (hostName h) (Props ps)
containerProps :: IsContainer c => c -> Props UnixLike
containerProps = Props . containerProperties
setContainerProps :: IsContainer c => c -> Props metatypes -> c
setContainerProps c (Props ps) = setContainerProperties c ps
propagateContainer
::
( IncludesInfo metatypes ~ 'True
, IsContainer c
)
=> String
-> c
-> (PropagateInfo -> Bool)
-> Property metatypes
-> Property metatypes
propagateContainer containername c wanted prop = prop
`addChildren` map convert (containerProperties c)
where
convert p =
let n = property'' (getDesc p) (getSatisfy p) :: Property UnixLike
n' = n
`setInfoProperty` mapInfo (forceHostContext containername)
(propagatableInfo wanted (getInfo p))
`addChildren` map convert (getChildren p)
in toChildProperty n'
propagatableInfo :: (PropagateInfo -> Bool) -> Info -> Info
propagatableInfo wanted (Info l) = Info $
filter (\(InfoEntry a) -> wanted (propagateInfo a)) l
normalContainerInfo :: PropagateInfo -> Bool
normalContainerInfo PropagatePrivData = True
normalContainerInfo (PropagateInfo b) = b
onlyPrivData :: PropagateInfo -> Bool
onlyPrivData PropagatePrivData = True
onlyPrivData (PropagateInfo _) = False