summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess2014-05-31 20:48:23 -0400
committerJoey Hess2014-05-31 20:48:23 -0400
commit58c8d74b4c4917f9f5e566709202ad432a7b2a6f (patch)
tree65da63c631e875a1bf074da920e145d07d011698
parente133536c3f7cc4dd816b8c5fe97e3131411a5ae9 (diff)
simplified record accessors
-rw-r--r--src/Propellor/Attr.hs11
-rw-r--r--src/Propellor/Engine.hs2
-rw-r--r--src/Propellor/PrivData.hs3
-rw-r--r--src/Propellor/Property/Dns.hs6
-rw-r--r--src/Propellor/Property/Docker.hs2
-rw-r--r--src/Propellor/Property/Hostname.hs2
-rw-r--r--src/Propellor/Property/Postfix.hs2
-rw-r--r--src/Propellor/Types.hs6
8 files changed, 12 insertions, 22 deletions
diff --git a/src/Propellor/Attr.hs b/src/Propellor/Attr.hs
index 8f1c6b7c..29d7a01e 100644
--- a/src/Propellor/Attr.hs
+++ b/src/Propellor/Attr.hs
@@ -15,9 +15,6 @@ import Control.Applicative
pureAttrProperty :: Desc -> Attr -> Property
pureAttrProperty desc = Property ("has " ++ desc) (return NoChange)
-getHostName :: Propellor HostName
-getHostName = asks _hostName
-
os :: System -> Property
os system = pureAttrProperty ("Operating " ++ show system) $
mempty { _os = Just system }
@@ -63,14 +60,8 @@ sshPubKey k = pureAttrProperty ("ssh pubkey known") $
getSshPubKey :: Propellor (Maybe String)
getSshPubKey = asks (_sshPubKey . hostAttr)
-hostAttr :: Host -> Attr
-hostAttr (Host _ _ attr) = attr
-
-hostProperties :: Host -> [Property]
-hostProperties (Host _ ps _) = ps
-
hostMap :: [Host] -> M.Map HostName Host
-hostMap l = M.fromList $ zip (map _hostName l) l
+hostMap l = M.fromList $ zip (map hostName l) l
findHost :: [Host] -> HostName -> Maybe Host
findHost l hn = M.lookup hn (hostMap l)
diff --git a/src/Propellor/Engine.hs b/src/Propellor/Engine.hs
index 7cee42e8..ca0f7265 100644
--- a/src/Propellor/Engine.hs
+++ b/src/Propellor/Engine.hs
@@ -32,7 +32,7 @@ ensureProperties ps = ensure ps NoChange
where
ensure [] rs = return rs
ensure (l:ls) rs = do
- hn <- getHostName
+ hn <- asks hostName
r <- actionMessageOn hn (propertyDesc l) (ensureProperty l)
ensure ls (r <> rs)
diff --git a/src/Propellor/PrivData.hs b/src/Propellor/PrivData.hs
index ad2c8d22..54f67d73 100644
--- a/src/Propellor/PrivData.hs
+++ b/src/Propellor/PrivData.hs
@@ -13,7 +13,6 @@ import Control.Monad
import "mtl" Control.Monad.Reader
import Propellor.Types
-import Propellor.Attr
import Propellor.Message
import Utility.Monad
import Utility.PartialPrelude
@@ -30,7 +29,7 @@ withPrivData :: PrivDataField -> (String -> Propellor Result) -> Propellor Resul
withPrivData field a = maybe missing a =<< liftIO (getPrivData field)
where
missing = do
- host <- getHostName
+ host <- asks hostName
let host' = if ".docker" `isSuffixOf` host
then "$parent_host"
else host
diff --git a/src/Propellor/Property/Dns.hs b/src/Propellor/Property/Dns.hs
index 44378491..3e5c7828 100644
--- a/src/Propellor/Property/Dns.hs
+++ b/src/Propellor/Property/Dns.hs
@@ -352,11 +352,11 @@ genZone hosts zdomain soa =
-- so warn.
hostips :: Host -> [Either WarningMessage (BindDomain, Record)]
hostips h
- | null l = [Left $ "no IP address defined for host " ++ _hostName h]
+ | null l = [Left $ "no IP address defined for host " ++ hostName h]
| otherwise = map Right l
where
attr = hostAttr h
- l = zip (repeat $ AbsDomain $ _hostName h)
+ l = zip (repeat $ AbsDomain $ hostName h)
(map Address $ getAddresses attr)
-- Any host, whether its hostname is in the zdomain or not,
@@ -387,7 +387,7 @@ genZone hosts zdomain soa =
hostrecords h = map Right l
where
attr = hostAttr h
- l = zip (repeat $ AbsDomain $ _hostName h)
+ l = zip (repeat $ AbsDomain $ hostName h)
(S.toList $ S.filter (\r -> isNothing (getIPAddr r) && isNothing (getCNAME r)) (_dns attr))
inDomain :: Domain -> BindDomain -> Bool
diff --git a/src/Propellor/Property/Docker.hs b/src/Propellor/Property/Docker.hs
index 3e925bb6..8e081ae4 100644
--- a/src/Propellor/Property/Docker.hs
+++ b/src/Propellor/Property/Docker.hs
@@ -72,7 +72,7 @@ docked hosts cn = RevertableProperty
(go "undocked" teardown)
where
go desc a = property (desc ++ " " ++ cn) $ do
- hn <- getHostName
+ hn <- asks hostName
let cid = ContainerId hn cn
ensureProperties [findContainer mhost cid cn $ a cid]
diff --git a/src/Propellor/Property/Hostname.hs b/src/Propellor/Property/Hostname.hs
index 3859649e..3a6283cf 100644
--- a/src/Propellor/Property/Hostname.hs
+++ b/src/Propellor/Property/Hostname.hs
@@ -9,7 +9,7 @@ import qualified Propellor.Property.File as File
-- A FQDN also configures /etc/hosts, with an entry for 127.0.1.1, which is
-- standard at least on Debian to set the FDQN (127.0.0.1 is localhost).
sane :: Property
-sane = property ("sane hostname") (ensureProperty . setTo =<< getHostName)
+sane = property ("sane hostname") (ensureProperty . setTo =<< asks hostName)
setTo :: HostName -> Property
setTo hn = combineProperties desc go
diff --git a/src/Propellor/Property/Postfix.hs b/src/Propellor/Property/Postfix.hs
index 9fa4a2c3..ef96e086 100644
--- a/src/Propellor/Property/Postfix.hs
+++ b/src/Propellor/Property/Postfix.hs
@@ -16,7 +16,7 @@ satellite :: Property
satellite = setup `requires` installed
where
setup = trivial $ property "postfix satellite system" $ do
- hn <- getHostName
+ hn <- asks hostName
ensureProperty $ Apt.reConfigure "postfix"
[ ("postfix/main_mailer_type", "select", "Satellite system")
, ("postfix/root_address", "string", "root")
diff --git a/src/Propellor/Types.hs b/src/Propellor/Types.hs
index e0d471ff..4ea97bce 100644
--- a/src/Propellor/Types.hs
+++ b/src/Propellor/Types.hs
@@ -36,9 +36,9 @@ import Propellor.Types.Dns
-- | Everything Propellor knows about a system: Its hostname,
-- properties and attributes.
data Host = Host
- { _hostName :: HostName
- , _hostProps :: [Property]
- , _hostAttr :: Attr
+ { hostName :: HostName
+ , hostProperties :: [Property]
+ , hostAttr :: Attr
}
-- | Propellor's monad provides read-only access to the host it's running