diff options
| author | Joey Hess <joey@kitenet.net> | 2014-05-31 18:02:56 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-05-31 18:04:41 -0400 |
| commit | 5fc4b006517051e937cbfa13b5f7ccbc25460c1b (patch) | |
| tree | f99b7dcf46d262f13aa80fb39c8fcc1a67c951a9 /src/Propellor/Attr.hs | |
| parent | d3ac75a1a29e9eda60b78d25e7352d4a2d5713cc (diff) | |
remove now redundant _hostname field of Attr
Now that Host includes _hostName, it's redundant to also keep it in Attr.
This requires changing the reader monad to operate on the whole Host.
Diffstat (limited to 'src/Propellor/Attr.hs')
| -rw-r--r-- | src/Propellor/Attr.hs | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/src/Propellor/Attr.hs b/src/Propellor/Attr.hs index 6bc4fcf1..5749a4bf 100644 --- a/src/Propellor/Attr.hs +++ b/src/Propellor/Attr.hs @@ -14,19 +14,15 @@ import Control.Applicative pureAttrProperty :: Desc -> SetAttr -> Property pureAttrProperty desc = Property ("has " ++ desc) (return NoChange) -hostname :: HostName -> Property -hostname name = pureAttrProperty ("hostname " ++ name) $ - \d -> d { _hostname = name } - getHostName :: Propellor HostName -getHostName = asks _hostname +getHostName = asks _hostName os :: System -> Property os system = pureAttrProperty ("Operating " ++ show system) $ \d -> d { _os = Just system } getOS :: Propellor (Maybe System) -getOS = asks _os +getOS = asks (_os . hostAttr) -- | Indidate that a host has an A record in the DNS. -- @@ -74,17 +70,17 @@ addNamedConf conf d = d { _namedconf = new } _ -> M.insert domain conf m getNamedConf :: Propellor (M.Map Domain NamedConf) -getNamedConf = asks _namedconf +getNamedConf = asks (_namedconf . hostAttr) sshPubKey :: String -> Property sshPubKey k = pureAttrProperty ("ssh pubkey known") $ \d -> d { _sshPubKey = Just k } getSshPubKey :: Propellor (Maybe String) -getSshPubKey = asks _sshPubKey +getSshPubKey = asks (_sshPubKey . hostAttr) hostAttr :: Host -> Attr -hostAttr (Host hn _ mkattrs) = mkattrs (newAttr hn) +hostAttr (Host _ _ mkattrs) = mkattrs newAttr hostProperties :: Host -> [Property] hostProperties (Host _ ps _) = ps @@ -92,9 +88,6 @@ hostProperties (Host _ ps _) = ps hostMap :: [Host] -> M.Map HostName Host hostMap l = M.fromList $ zip (map _hostName l) l -hostAttrMap :: [Host] -> M.Map HostName Attr -hostAttrMap l = M.fromList $ zip (map _hostName l) (map hostAttr l) - findHost :: [Host] -> HostName -> Maybe Host findHost l hn = M.lookup hn (hostMap l) @@ -105,12 +98,3 @@ hostAddresses :: HostName -> [Host] -> [IPAddr] hostAddresses hn hosts = case hostAttr <$> findHost hosts hn of Nothing -> [] Just attr -> mapMaybe getIPAddr $ S.toList $ _dns attr - --- | Lifts an action into a different host. --- --- For example, `fromHost hosts "otherhost" getSshPubKey` -fromHost :: [Host] -> HostName -> Propellor a -> Propellor (Maybe a) -fromHost l hn getter = case findHost l hn of - Nothing -> return Nothing - Just h -> liftIO $ Just <$> - runReaderT (runWithAttr getter) (hostAttr h) |
