, NmcRRI2p(..)
, NmcRRTls(..)
, NmcRRDs(..)
- , emptyNmcDom
, mergeNmcDom
) where
import qualified Data.HashMap.Strict as H (lookup)
import Data.Aeson
import Data.Aeson.Types
+import Data.Default.Class
-- Variant of Aeson's `.:?` that interprets a String as a
-- single-element list, so it is possible to have either
, domSrv :: Maybe [String] -- Synthetic
} deriving (Show, Eq)
+instance Default NmcDom where
+ def = NmcDom Nothing Nothing Nothing Nothing Nothing Nothing Nothing
+ Nothing Nothing Nothing Nothing Nothing Nothing Nothing
+ Nothing Nothing Nothing Nothing Nothing Nothing
+
instance FromJSON NmcDom where
-- Wherever we expect a domain object, there may be a string
-- containing IPv4 address. Interpret it as such.
-- Question: shall we try to recognize IPv6 addresses too?
parseJSON (String s) =
return $ if isIPv4 s'
- then emptyNmcDom { domIp = Just [s'] }
- else emptyNmcDom
+ then def { domIp = Just [s'] }
+ else def
where
s' = unpack s
isIPv4 x = all isNibble $ splitOn "." x
mergeNmcDom :: NmcDom -> NmcDom -> NmcDom
mergeNmcDom = merge
-
-emptyNmcDom = NmcDom Nothing Nothing Nothing Nothing Nothing Nothing
- Nothing Nothing Nothing Nothing Nothing Nothing
- Nothing Nothing Nothing Nothing Nothing Nothing
- Nothing Nothing