{-# LANGUAGE PackageImports, TypeFamilies, DataKinds, PolyKinds #-}
module Propellor.Info (
osDebian,
osBuntish,
osArchLinux,
osFreeBSD,
setInfoProperty,
addInfoProperty,
pureInfoProperty,
pureInfoProperty',
askInfo,
getOS,
hasContainerCapability,
ipv4,
ipv6,
alias,
addDNS,
hostMap,
aliasMap,
findHost,
findHostNoAlias,
getAddresses,
hostAddresses,
) where
import Propellor.Types
import Propellor.Types.Info
import Propellor.Types.MetaTypes
import Propellor.Types.Container
import "mtl" Control.Monad.Reader
import qualified Data.Set as S
import qualified Data.Map as M
import Data.Maybe
import Data.Monoid
import Control.Applicative
import Prelude
setInfoProperty
:: (MetaTypes metatypes' ~ (+) HasInfo metatypes, SingI metatypes')
=> Property metatypes
-> Info
-> Property (MetaTypes metatypes')
setInfoProperty :: forall {k} (metatypes' :: k) metatypes.
(MetaTypes metatypes' ~ (HasInfo + metatypes), SingI metatypes') =>
Property metatypes -> Info -> Property (MetaTypes metatypes')
setInfoProperty (Property metatypes
_ HostName
d Maybe (Propellor Result)
a Info
oldi [ChildProperty]
c) Info
newi =
MetaTypes metatypes'
-> HostName
-> Maybe (Propellor Result)
-> Info
-> [ChildProperty]
-> Property (MetaTypes metatypes')
forall metatypes.
metatypes
-> HostName
-> Maybe (Propellor Result)
-> Info
-> [ChildProperty]
-> Property metatypes
Property MetaTypes metatypes'
forall {k} (t :: k). SingI t => Sing t
sing HostName
d Maybe (Propellor Result)
a (Info
oldi Info -> Info -> Info
forall a. Semigroup a => a -> a -> a
<> Info
newi) [ChildProperty]
c
addInfoProperty
:: (IncludesInfo metatypes ~ 'True)
=> Property metatypes
-> Info
-> Property metatypes
addInfoProperty :: forall metatypes.
(IncludesInfo metatypes ~ 'True) =>
Property metatypes -> Info -> Property metatypes
addInfoProperty (Property metatypes
t HostName
d Maybe (Propellor Result)
a Info
oldi [ChildProperty]
c) Info
newi =
metatypes
-> HostName
-> Maybe (Propellor Result)
-> Info
-> [ChildProperty]
-> Property metatypes
forall metatypes.
metatypes
-> HostName
-> Maybe (Propellor Result)
-> Info
-> [ChildProperty]
-> Property metatypes
Property metatypes
t HostName
d Maybe (Propellor Result)
a (Info
oldi Info -> Info -> Info
forall a. Semigroup a => a -> a -> a
<> Info
newi) [ChildProperty]
c
pureInfoProperty :: (IsInfo v) => Desc -> v -> Property (HasInfo + UnixLike)
pureInfoProperty :: forall v.
IsInfo v =>
HostName -> v -> Property (HasInfo + UnixLike)
pureInfoProperty HostName
desc v
v = HostName -> Info -> Property (HasInfo + UnixLike)
pureInfoProperty' HostName
desc (v -> Info
forall v. IsInfo v => v -> Info
toInfo v
v)
pureInfoProperty' :: Desc -> Info -> Property (HasInfo + UnixLike)
pureInfoProperty' :: HostName -> Info -> Property (HasInfo + UnixLike)
pureInfoProperty' HostName
desc Info
i = Property UnixLike
-> Info
-> Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD])
forall {k} (metatypes' :: k) metatypes.
(MetaTypes metatypes' ~ (HasInfo + metatypes), SingI metatypes') =>
Property metatypes -> Info -> Property (MetaTypes metatypes')
setInfoProperty Property UnixLike
p Info
i
where
p :: Property UnixLike
p :: Property UnixLike
p = HostName -> Propellor Result -> Property UnixLike
forall {k} (metatypes :: k).
SingI metatypes =>
HostName -> Propellor Result -> Property (MetaTypes metatypes)
property (HostName
"has " HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName
desc) (Result -> Propellor Result
forall a. a -> Propellor a
forall (m :: * -> *) a. Monad m => a -> m a
return Result
NoChange)
askInfo :: (IsInfo v) => Propellor v
askInfo :: forall v. IsInfo v => Propellor v
askInfo = (Host -> v) -> Propellor v
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Info -> v
forall v. IsInfo v => Info -> v
fromInfo (Info -> v) -> (Host -> Info) -> Host -> v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Host -> Info
hostInfo)
hasContainerCapability :: ContainerCapability -> Propellor Bool
hasContainerCapability :: ContainerCapability -> Propellor Bool
hasContainerCapability ContainerCapability
c = ContainerCapability -> [ContainerCapability] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem ContainerCapability
c
([ContainerCapability] -> Bool)
-> Propellor [ContainerCapability] -> Propellor Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Propellor [ContainerCapability]
forall v. IsInfo v => Propellor v
askInfo :: Propellor [ContainerCapability])
osDebian :: DebianSuite -> Architecture -> Property (HasInfo + Debian)
osDebian :: DebianSuite -> Architecture -> Property (HasInfo + Debian)
osDebian = DebianKernel
-> DebianSuite -> Architecture -> Property (HasInfo + Debian)
osDebian' DebianKernel
Linux
osDebian' :: DebianKernel -> DebianSuite -> Architecture -> Property (HasInfo + Debian)
osDebian' :: DebianKernel
-> DebianSuite -> Architecture -> Property (HasInfo + Debian)
osDebian' DebianKernel
kernel DebianSuite
suite Architecture
arch = Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD])
-> Property (MetaTypes '[ 'WithInfo, 'Targeting 'OSDebian])
forall (untightened :: [MetaType]) (tightened :: [MetaType]).
(TightenTargetsAllowed untightened tightened, SingI tightened) =>
Property (MetaTypes untightened) -> Property (MetaTypes tightened)
forall (p :: * -> *) (untightened :: [MetaType])
(tightened :: [MetaType]).
(TightenTargets p, TightenTargetsAllowed untightened tightened,
SingI tightened) =>
p (MetaTypes untightened) -> p (MetaTypes tightened)
tightenTargets (Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD])
-> Property (MetaTypes '[ 'WithInfo, 'Targeting 'OSDebian]))
-> Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD])
-> Property (MetaTypes '[ 'WithInfo, 'Targeting 'OSDebian])
forall a b. (a -> b) -> a -> b
$ System -> Property (HasInfo + UnixLike)
os (Distribution -> Architecture -> System
System (DebianKernel -> DebianSuite -> Distribution
Debian DebianKernel
kernel DebianSuite
suite) Architecture
arch)
osBuntish :: Release -> Architecture -> Property (HasInfo + Buntish)
osBuntish :: HostName -> Architecture -> Property (HasInfo + Buntish)
osBuntish HostName
release Architecture
arch = Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD])
-> Property (MetaTypes '[ 'WithInfo, 'Targeting 'OSBuntish])
forall (untightened :: [MetaType]) (tightened :: [MetaType]).
(TightenTargetsAllowed untightened tightened, SingI tightened) =>
Property (MetaTypes untightened) -> Property (MetaTypes tightened)
forall (p :: * -> *) (untightened :: [MetaType])
(tightened :: [MetaType]).
(TightenTargets p, TightenTargetsAllowed untightened tightened,
SingI tightened) =>
p (MetaTypes untightened) -> p (MetaTypes tightened)
tightenTargets (Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD])
-> Property (MetaTypes '[ 'WithInfo, 'Targeting 'OSBuntish]))
-> Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD])
-> Property (MetaTypes '[ 'WithInfo, 'Targeting 'OSBuntish])
forall a b. (a -> b) -> a -> b
$ System -> Property (HasInfo + UnixLike)
os (Distribution -> Architecture -> System
System (HostName -> Distribution
Buntish HostName
release) Architecture
arch)
osFreeBSD :: FreeBSDRelease -> Architecture -> Property (HasInfo + FreeBSD)
osFreeBSD :: FreeBSDRelease -> Architecture -> Property (HasInfo + FreeBSD)
osFreeBSD FreeBSDRelease
release Architecture
arch = Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD])
-> Property (MetaTypes '[ 'WithInfo, 'Targeting 'OSFreeBSD])
forall (untightened :: [MetaType]) (tightened :: [MetaType]).
(TightenTargetsAllowed untightened tightened, SingI tightened) =>
Property (MetaTypes untightened) -> Property (MetaTypes tightened)
forall (p :: * -> *) (untightened :: [MetaType])
(tightened :: [MetaType]).
(TightenTargets p, TightenTargetsAllowed untightened tightened,
SingI tightened) =>
p (MetaTypes untightened) -> p (MetaTypes tightened)
tightenTargets (Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD])
-> Property (MetaTypes '[ 'WithInfo, 'Targeting 'OSFreeBSD]))
-> Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD])
-> Property (MetaTypes '[ 'WithInfo, 'Targeting 'OSFreeBSD])
forall a b. (a -> b) -> a -> b
$ System -> Property (HasInfo + UnixLike)
os (Distribution -> Architecture -> System
System (FreeBSDRelease -> Distribution
FreeBSD FreeBSDRelease
release) Architecture
arch)
osArchLinux :: Architecture -> Property (HasInfo + ArchLinux)
osArchLinux :: Architecture -> Property (HasInfo + ArchLinux)
osArchLinux Architecture
arch = Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD])
-> Property (MetaTypes '[ 'WithInfo, 'Targeting 'OSArchLinux])
forall (untightened :: [MetaType]) (tightened :: [MetaType]).
(TightenTargetsAllowed untightened tightened, SingI tightened) =>
Property (MetaTypes untightened) -> Property (MetaTypes tightened)
forall (p :: * -> *) (untightened :: [MetaType])
(tightened :: [MetaType]).
(TightenTargets p, TightenTargetsAllowed untightened tightened,
SingI tightened) =>
p (MetaTypes untightened) -> p (MetaTypes tightened)
tightenTargets (Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD])
-> Property (MetaTypes '[ 'WithInfo, 'Targeting 'OSArchLinux]))
-> Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD])
-> Property (MetaTypes '[ 'WithInfo, 'Targeting 'OSArchLinux])
forall a b. (a -> b) -> a -> b
$ System -> Property (HasInfo + UnixLike)
os (Distribution -> Architecture -> System
System (Distribution
ArchLinux) Architecture
arch)
os :: System -> Property (HasInfo + UnixLike)
os :: System -> Property (HasInfo + UnixLike)
os System
system = HostName -> InfoVal System -> Property (HasInfo + UnixLike)
forall v.
IsInfo v =>
HostName -> v -> Property (HasInfo + UnixLike)
pureInfoProperty (HostName
"Operating " HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ System -> HostName
forall a. Show a => a -> HostName
show System
system) (System -> InfoVal System
forall v. v -> InfoVal v
InfoVal System
system)
getOS :: Propellor (Maybe System)
getOS :: Propellor (Maybe System)
getOS = InfoVal System -> Maybe System
forall v. InfoVal v -> Maybe v
fromInfoVal (InfoVal System -> Maybe System)
-> Propellor (InfoVal System) -> Propellor (Maybe System)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Propellor (InfoVal System)
forall v. IsInfo v => Propellor v
askInfo
ipv4 :: String -> Property (HasInfo + UnixLike)
ipv4 :: HostName -> Property (HasInfo + UnixLike)
ipv4 = Bool -> Record -> Property (HasInfo + UnixLike)
addDNS Bool
False (Record
-> Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD]))
-> (HostName -> Record)
-> HostName
-> Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IPAddr -> Record
Address (IPAddr -> Record) -> (HostName -> IPAddr) -> HostName -> Record
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HostName -> IPAddr
IPv4
ipv6 :: String -> Property (HasInfo + UnixLike)
ipv6 :: HostName -> Property (HasInfo + UnixLike)
ipv6 = Bool -> Record -> Property (HasInfo + UnixLike)
addDNS Bool
False (Record
-> Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD]))
-> (HostName -> Record)
-> HostName
-> Property
(MetaTypes
'[ 'WithInfo, 'Targeting 'OSDebian, 'Targeting 'OSBuntish,
'Targeting 'OSArchLinux, 'Targeting 'OSFreeBSD])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IPAddr -> Record
Address (IPAddr -> Record) -> (HostName -> IPAddr) -> HostName -> Record
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HostName -> IPAddr
IPv6
alias :: Domain -> Property (HasInfo + UnixLike)
alias :: HostName -> Property (HasInfo + UnixLike)
alias HostName
d = HostName -> Info -> Property (HasInfo + UnixLike)
pureInfoProperty' (HostName
"alias " HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName
d) (Info -> Property (HasInfo + UnixLike))
-> Info -> Property (HasInfo + UnixLike)
forall a b. (a -> b) -> a -> b
$ Info
forall a. Monoid a => a
mempty
Info -> AliasesInfo -> Info
forall v. IsInfo v => Info -> v -> Info
`addInfo` [HostName] -> AliasesInfo
toAliasesInfo [HostName
d]
Info -> DnsInfoPropagated -> Info
forall v. IsInfo v => Info -> v -> Info
`addInfo` (Set Record -> DnsInfoPropagated
toDnsInfoPropagated (Set Record -> DnsInfoPropagated)
-> Set Record -> DnsInfoPropagated
forall a b. (a -> b) -> a -> b
$ Record -> Set Record
forall a. a -> Set a
S.singleton (Record -> Set Record) -> Record -> Set Record
forall a b. (a -> b) -> a -> b
$ BindDomain -> Record
CNAME (BindDomain -> Record) -> BindDomain -> Record
forall a b. (a -> b) -> a -> b
$ HostName -> BindDomain
AbsDomain HostName
d)
addDNS
:: Bool
-> Record
-> Property (HasInfo + UnixLike)
addDNS :: Bool -> Record -> Property (HasInfo + UnixLike)
addDNS Bool
prop Record
r
| Bool
prop = HostName -> DnsInfoPropagated -> Property (HasInfo + UnixLike)
forall v.
IsInfo v =>
HostName -> v -> Property (HasInfo + UnixLike)
pureInfoProperty (Record -> HostName
rdesc Record
r) (Set Record -> DnsInfoPropagated
toDnsInfoPropagated Set Record
s)
| Bool
otherwise = HostName -> DnsInfoUnpropagated -> Property (HasInfo + UnixLike)
forall v.
IsInfo v =>
HostName -> v -> Property (HasInfo + UnixLike)
pureInfoProperty (Record -> HostName
rdesc Record
r) (Set Record -> DnsInfoUnpropagated
toDnsInfoUnpropagated Set Record
s)
where
s :: Set Record
s = Record -> Set Record
forall a. a -> Set a
S.singleton Record
r
rdesc :: Record -> HostName
rdesc (CNAME BindDomain
d) = [HostName] -> HostName
unwords [HostName
"alias", BindDomain -> HostName
ddesc BindDomain
d]
rdesc (Address (IPv4 HostName
addr)) = [HostName] -> HostName
unwords [HostName
"ipv4", HostName
addr]
rdesc (Address (IPv6 HostName
addr)) = [HostName] -> HostName
unwords [HostName
"ipv6", HostName
addr]
rdesc (MX Int
n BindDomain
d) = [HostName] -> HostName
unwords [HostName
"MX", Int -> HostName
forall a. Show a => a -> HostName
show Int
n, BindDomain -> HostName
ddesc BindDomain
d]
rdesc (NS BindDomain
d) = [HostName] -> HostName
unwords [HostName
"NS", BindDomain -> HostName
ddesc BindDomain
d]
rdesc (TXT HostName
t) = [HostName] -> HostName
unwords [HostName
"TXT", HostName
t]
rdesc (SRV Word16
x Word16
y Word16
z BindDomain
d) = [HostName] -> HostName
unwords [HostName
"SRV", Word16 -> HostName
forall a. Show a => a -> HostName
show Word16
x, Word16 -> HostName
forall a. Show a => a -> HostName
show Word16
y, Word16 -> HostName
forall a. Show a => a -> HostName
show Word16
z, BindDomain -> HostName
ddesc BindDomain
d]
rdesc (SSHFP Int
x Int
y HostName
t) = [HostName] -> HostName
unwords [HostName
"SSHFP", Int -> HostName
forall a. Show a => a -> HostName
show Int
x, Int -> HostName
forall a. Show a => a -> HostName
show Int
y, HostName
t]
rdesc (INCLUDE HostName
f) = [HostName] -> HostName
unwords [HostName
"$INCLUDE", HostName
f]
rdesc (PTR HostName
x) = [HostName] -> HostName
unwords [HostName
"PTR", HostName
x]
ddesc :: BindDomain -> HostName
ddesc (AbsDomain HostName
domain) = HostName
domain
ddesc (RelDomain HostName
domain) = HostName
domain
ddesc BindDomain
RootDomain = HostName
"@"
hostMap :: [Host] -> M.Map HostName Host
hostMap :: [Host] -> Map HostName Host
hostMap [Host]
l = [(HostName, Host)] -> Map HostName Host
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(HostName, Host)] -> Map HostName Host)
-> [(HostName, Host)] -> Map HostName Host
forall a b. (a -> b) -> a -> b
$ [HostName] -> [Host] -> [(HostName, Host)]
forall a b. [a] -> [b] -> [(a, b)]
zip ((Host -> HostName) -> [Host] -> [HostName]
forall a b. (a -> b) -> [a] -> [b]
map Host -> HostName
hostName [Host]
l) [Host]
l
aliasMap :: [Host] -> M.Map HostName Host
aliasMap :: [Host] -> Map HostName Host
aliasMap = [(HostName, Host)] -> Map HostName Host
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(HostName, Host)] -> Map HostName Host)
-> ([Host] -> [(HostName, Host)]) -> [Host] -> Map HostName Host
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[(HostName, Host)]] -> [(HostName, Host)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[(HostName, Host)]] -> [(HostName, Host)])
-> ([Host] -> [[(HostName, Host)]]) -> [Host] -> [(HostName, Host)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(Host -> [(HostName, Host)]) -> [Host] -> [[(HostName, Host)]]
forall a b. (a -> b) -> [a] -> [b]
map (\Host
h -> (HostName -> (HostName, Host)) -> [HostName] -> [(HostName, Host)]
forall a b. (a -> b) -> [a] -> [b]
map (\HostName
aka -> (HostName
aka, Host
h)) ([HostName] -> [(HostName, Host)])
-> [HostName] -> [(HostName, Host)]
forall a b. (a -> b) -> a -> b
$ AliasesInfo -> [HostName]
fromAliasesInfo (AliasesInfo -> [HostName]) -> AliasesInfo -> [HostName]
forall a b. (a -> b) -> a -> b
$ Info -> AliasesInfo
forall v. IsInfo v => Info -> v
fromInfo (Info -> AliasesInfo) -> Info -> AliasesInfo
forall a b. (a -> b) -> a -> b
$ Host -> Info
hostInfo Host
h)
findHost :: [Host] -> HostName -> Maybe Host
findHost :: [Host] -> HostName -> Maybe Host
findHost [Host]
l HostName
hn = ([Host] -> HostName -> Maybe Host
findHostNoAlias [Host]
l HostName
hn) Maybe Host -> Maybe Host -> Maybe Host
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ([Host] -> HostName -> Maybe Host
findAlias [Host]
l HostName
hn)
findHostNoAlias :: [Host] -> HostName -> Maybe Host
findHostNoAlias :: [Host] -> HostName -> Maybe Host
findHostNoAlias [Host]
l HostName
hn = HostName -> Map HostName Host -> Maybe Host
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup HostName
hn ([Host] -> Map HostName Host
hostMap [Host]
l)
findAlias :: [Host] -> HostName -> Maybe Host
findAlias :: [Host] -> HostName -> Maybe Host
findAlias [Host]
l HostName
hn = HostName -> Map HostName Host -> Maybe Host
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup HostName
hn ([Host] -> Map HostName Host
aliasMap [Host]
l)
getAddresses :: Info -> [IPAddr]
getAddresses :: Info -> [IPAddr]
getAddresses = (Record -> Maybe IPAddr) -> [Record] -> [IPAddr]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Record -> Maybe IPAddr
getIPAddr ([Record] -> [IPAddr]) -> (Info -> [Record]) -> Info -> [IPAddr]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set Record -> [Record]
forall a. Set a -> [a]
S.toList (Set Record -> [Record])
-> (Info -> Set Record) -> Info -> [Record]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Info -> Set Record
getDnsInfo
hostAddresses :: HostName -> [Host] -> [IPAddr]
hostAddresses :: HostName -> [Host] -> [IPAddr]
hostAddresses HostName
hn [Host]
hosts = [IPAddr] -> (Host -> [IPAddr]) -> Maybe Host -> [IPAddr]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (Info -> [IPAddr]
getAddresses (Info -> [IPAddr]) -> (Host -> Info) -> Host -> [IPAddr]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Host -> Info
hostInfo) ([Host] -> HostName -> Maybe Host
findHost [Host]
hosts HostName
hn)