From aa225472fb586486b5839e5362a555a476e9a45d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 26 Feb 2017 16:48:26 -0400 Subject: convert fromIPAddr to val --- debian/changelog | 2 +- src/Propellor/Property/Dns.hs | 2 +- src/Propellor/Property/Firewall.hs | 8 ++++---- src/Propellor/Property/Munin.hs | 2 +- src/Propellor/Property/Unbound.hs | 2 +- src/Propellor/Spin.hs | 2 +- src/Propellor/Types/Dns.hs | 9 +++++---- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/debian/changelog b/debian/changelog index e3009188..f965a58c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,7 +3,7 @@ propellor (3.4.0) UNRELEASED; urgency=medium * Added ConfigurableValue type class, for values that can be used in a config file, or to otherwise configure a program. * The val function converts such values to String. - * Removed fromPort (use val instead). (API change) + * Removed fromPort and fromIPAddr (use val instead). (API change) * Removed several Show instances that were only used for generating configuration, replacing with ConfigurableValue instances. (API change) diff --git a/src/Propellor/Property/Dns.hs b/src/Propellor/Property/Dns.hs index 3fcffed3..889aece5 100644 --- a/src/Propellor/Property/Dns.hs +++ b/src/Propellor/Property/Dns.hs @@ -250,7 +250,7 @@ confStanza c = cfgline f v = "\t" ++ f ++ " " ++ v ++ ";" ipblock name l = [ "\t" ++ name ++ " {" ] ++ - (map (\ip -> "\t\t" ++ fromIPAddr ip ++ ";") l) ++ + (map (\ip -> "\t\t" ++ val ip ++ ";") l) ++ [ "\t};" ] mastersblock | null (confMasters c) = [] diff --git a/src/Propellor/Property/Firewall.hs b/src/Propellor/Property/Firewall.hs index ab667da3..736a4458 100644 --- a/src/Propellor/Property/Firewall.hs +++ b/src/Propellor/Property/Firewall.hs @@ -99,7 +99,7 @@ toIpTableArg (NotDestination ipwm) = ] toIpTableArg (NatDestination ip mport) = [ "--to-destination" - , fromIPAddr ip ++ maybe "" (\p -> ":" ++ val p) mport + , val ip ++ maybe "" (\p -> ":" ++ val p) mport ] toIpTableArg (r :- r') = toIpTableArg r <> toIpTableArg r' @@ -107,9 +107,9 @@ data IPWithMask = IPWithNoMask IPAddr | IPWithIPMask IPAddr IPAddr | IPWithNumMa deriving (Eq, Show) instance ConfigurableValue IPWithMask where - val (IPWithNoMask ip) = fromIPAddr ip - val (IPWithIPMask ip ipm) = fromIPAddr ip ++ "/" ++ fromIPAddr ipm - val (IPWithNumMask ip m) = fromIPAddr ip ++ "/" ++ show m + val (IPWithNoMask ip) = val ip + val (IPWithIPMask ip ipm) = val ip ++ "/" ++ val ipm + val (IPWithNumMask ip m) = val ip ++ "/" ++ val m data Rule = Rule { ruleChain :: Chain diff --git a/src/Propellor/Property/Munin.hs b/src/Propellor/Property/Munin.hs index 13c72f3a..6dab25ef 100644 --- a/src/Propellor/Property/Munin.hs +++ b/src/Propellor/Property/Munin.hs @@ -46,7 +46,7 @@ hostListFragment' hs os = concatMap muninHost hs where muninHost :: Host -> [String] muninHost h = [ "[" ++ (hostName h) ++ "]" - , " address " ++ maybe (hostName h) (fromIPAddr . fst) (hOverride h) + , " address " ++ maybe (hostName h) (val . fst) (hOverride h) ] ++ (maybe [] (\x -> [" port " ++ (val $ snd x)]) (hOverride h)) ++ [""] hOverride :: Host -> Maybe (IPAddr, Port) hOverride h = lookup (hostName h) os diff --git a/src/Propellor/Property/Unbound.hs b/src/Propellor/Property/Unbound.hs index 9eb8f8c9..470aad7e 100644 --- a/src/Propellor/Property/Unbound.hs +++ b/src/Propellor/Property/Unbound.hs @@ -133,7 +133,7 @@ genAddress dom ttl addr = case addr of IPv6 _ -> genAddress' "AAAA" dom ttl addr genAddress' :: String -> BindDomain -> Maybe Int -> IPAddr -> String -genAddress' recordtype dom ttl addr = dValue dom ++ " " ++ maybe "" (\ttl' -> val ttl' ++ " ") ttl ++ "IN " ++ recordtype ++ " " ++ fromIPAddr addr +genAddress' recordtype dom ttl addr = dValue dom ++ " " ++ maybe "" (\ttl' -> val ttl' ++ " ") ttl ++ "IN " ++ recordtype ++ " " ++ val addr genMX :: BindDomain -> Int -> BindDomain -> String genMX dom priority dest = dValue dom ++ " " ++ "MX" ++ " " ++ val priority ++ " " ++ dValue dest diff --git a/src/Propellor/Spin.hs b/src/Propellor/Spin.hs index c6699961f..447f8e9f 100644 --- a/src/Propellor/Spin.hs +++ b/src/Propellor/Spin.hs @@ -169,7 +169,7 @@ getSshTarget target hst warningMessage $ "DNS seems out of date for " ++ target ++ " (" ++ why ++ "); using IP address from configuration instead." return ip - configips = map fromIPAddr $ mapMaybe getIPAddr $ + configips = map val $ mapMaybe getIPAddr $ S.toList $ fromDnsInfo $ fromInfo $ hostInfo hst -- Update the privdata, repo url, and git repo over the ssh diff --git a/src/Propellor/Types/Dns.hs b/src/Propellor/Types/Dns.hs index 8f15d156..4cb8b111 100644 --- a/src/Propellor/Types/Dns.hs +++ b/src/Propellor/Types/Dns.hs @@ -5,6 +5,7 @@ module Propellor.Types.Dns where import Propellor.Types.OS (HostName) import Propellor.Types.Empty import Propellor.Types.Info +import Propellor.Types.ConfigurableValue import Data.Word import qualified Data.Map as M @@ -19,9 +20,9 @@ type Domain = String data IPAddr = IPv4 String | IPv6 String deriving (Read, Show, Eq, Ord) -fromIPAddr :: IPAddr -> String -fromIPAddr (IPv4 addr) = addr -fromIPAddr (IPv6 addr) = addr +instance ConfigurableValue IPAddr where + val (IPv4 addr) = addr + val (IPv6 addr) = addr newtype AliasesInfo = AliasesInfo (S.Set HostName) deriving (Show, Eq, Ord, Monoid, Typeable) @@ -102,7 +103,7 @@ type ReverseIP = String reverseIP :: IPAddr -> ReverseIP reverseIP (IPv4 addr) = intercalate "." (reverse $ split "." addr) ++ ".in-addr.arpa" -reverseIP addr@(IPv6 _) = reverse (intersperse '.' $ replace ":" "" $ fromIPAddr $ canonicalIP addr) ++ ".ip6.arpa" +reverseIP addr@(IPv6 _) = reverse (intersperse '.' $ replace ":" "" $ val $ canonicalIP addr) ++ ".ip6.arpa" -- | Converts an IP address (particularly IPv6) to canonical, fully -- expanded form. -- cgit v1.2.3