summaryrefslogtreecommitdiff
path: root/src/Propellor/Types/Dns.hs
diff options
context:
space:
mode:
authorJoey Hess2014-05-31 20:39:56 -0400
committerJoey Hess2014-05-31 20:43:23 -0400
commit4f70fceb3a79f2c2b746407768faf363d11c11a4 (patch)
tree3f0c05ed545b761bbe3f07576d1ef0259a48c4af /src/Propellor/Types/Dns.hs
parent6b835c5eeb352718a11e707a0e10d2bc5092782b (diff)
got rid of the Attr -> Attr SetAttr hack, and use monoids for Attr
The SetAttr hack used to be needed because the hostname was part of the Attr, and was required to be present. Now that it's moved to Host, let's get rid of that, since it tended to waste CPU.
Diffstat (limited to 'src/Propellor/Types/Dns.hs')
-rw-r--r--src/Propellor/Types/Dns.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Propellor/Types/Dns.hs b/src/Propellor/Types/Dns.hs
index ba6a92dd..66fbd1a4 100644
--- a/src/Propellor/Types/Dns.hs
+++ b/src/Propellor/Types/Dns.hs
@@ -3,6 +3,8 @@ module Propellor.Types.Dns where
import Propellor.Types.OS (HostName)
import Data.Word
+import Data.Monoid
+import qualified Data.Map as M
type Domain = String
@@ -90,3 +92,21 @@ domainHostName :: BindDomain -> Maybe HostName
domainHostName (RelDomain d) = Just d
domainHostName (AbsDomain d) = Just d
domainHostName RootDomain = Nothing
+
+newtype NamedConfMap = NamedConfMap (M.Map Domain NamedConf)
+ deriving (Eq, Ord, Show)
+
+-- | Adding a Master NamedConf stanza for a particulr domain always
+-- overrides an existing Secondary stanza for that domain, while a
+-- Secondary stanza is only added when there is no existing Master stanza.
+instance Monoid NamedConfMap where
+ mempty = NamedConfMap M.empty
+ mappend (NamedConfMap old) (NamedConfMap new) = NamedConfMap $
+ M.unionWith combiner new old
+ where
+ combiner n o = case (confDnsServerType n, confDnsServerType o) of
+ (Secondary, Master) -> o
+ _ -> n
+
+fromNamedConfMap :: NamedConfMap -> M.Map Domain NamedConf
+fromNamedConfMap (NamedConfMap m) = m