{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE RankNTypes #-}
module Network.Cloudflare.DNS.Record where

import           Control.Lens             hiding ((.=))
import           Data.Aeson
import           Data.Aeson.Types
import qualified Data.ByteString          as BS
import qualified Data.ByteString.Lazy     as BSL
import           Data.Int
import           Data.Maybe
import           Data.Text                (Text)
import qualified Data.Text                as Text
import qualified Data.Text.Encoding       as Text
import           Data.Time
import           Data.Word
import           Network.Cloudflare.Types
import           Network.Wreq
import           Network.Wreq.Types       (Auth (OAuth2Bearer))

-- | Create a new DNS record for a zone
createDNSRecord :: DNSRecord record
                => CloudflareAuth
                -> Text -- ^ Zone Identifier
                -> CreateDNSRecord record
                -> IO (Either String (ResultResponse (DNSRecordEntry record)))
createDNSRecord :: forall record.
DNSRecord record =>
CloudflareAuth
-> Text
-> CreateDNSRecord record
-> IO (Either String (ResultResponse (DNSRecordEntry record)))
createDNSRecord CloudflareAuth
authInfo Text
zone CreateDNSRecord record
create = do
  let opts :: Options
opts = Options
defaults forall a b. a -> (a -> b) -> b
& HeaderName -> Lens' Options [ByteString]
header HeaderName
"Authorization" forall s t a b. ASetter s t a b -> b -> s -> t
.~ [ByteString
"Bearer " forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (CloudflareAuth -> Text
cloudflareAuthToken CloudflareAuth
authInfo)]
      url :: String
url = String
"https://api.cloudflare.com/client/v4/zones/" forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
zone forall a. Semigroup a => a -> a -> a
<> String
"/dns_records"
  Response ByteString
r <- forall a.
Postable a =>
Options -> String -> a -> IO (Response ByteString)
postWith Options
opts String
url forall a b. (a -> b) -> a -> b
$ forall a. ToJSON a => a -> Value
toJSON CreateDNSRecord record
create
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Response ByteString
r forall s a. s -> Getting a s a -> a
^. forall body0 body1.
Lens (Response body0) (Response body1) body0 body1
responseBody forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to forall a. FromJSON a => ByteString -> Either String a
eitherDecode

-- | List DNS records for a zone
listDNSRecords :: CloudflareAuth
               -> Text -- ^ Zone Identifier
               -> IO (Either String (ResultWithInfo [DNSEntry]))
listDNSRecords :: CloudflareAuth
-> Text -> IO (Either String (ResultWithInfo [DNSEntry]))
listDNSRecords CloudflareAuth
authInfo Text
zId = do
  let opts :: Options
opts = Options
defaults forall a b. a -> (a -> b) -> b
& Lens' Options (Maybe Auth)
auth forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. a -> Maybe a
Just (ByteString -> Auth
OAuth2Bearer (Text -> ByteString
Text.encodeUtf8 (CloudflareAuth -> Text
cloudflareAuthToken CloudflareAuth
authInfo)))
  Response ByteString
r <- Options -> String -> IO (Response ByteString)
getWith Options
opts forall a b. (a -> b) -> a -> b
$ String
"https://api.cloudflare.com/client/v4/zones/" forall a. [a] -> [a] -> [a]
++ Text -> String
Text.unpack Text
zId forall a. [a] -> [a] -> [a]
++ String
"/dns_records"
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Response ByteString
r forall s a. s -> Getting a s a -> a
^. forall body0 body1.
Lens (Response body0) (Response body1) body0 body1
responseBody forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to forall a. FromJSON a => ByteString -> Either String a
eitherDecode

-- | Export a zone's DNS records in BIND format
exportDNSRecords :: CloudflareAuth
                 -> Text -- ^ Zone identifier
                 -> IO Text -- ^ Exported BIND zone file
exportDNSRecords :: CloudflareAuth -> Text -> IO Text
exportDNSRecords CloudflareAuth
authInfo Text
zoneIdentifier = do
  let opts :: Options
opts = Options
defaults forall a b. a -> (a -> b) -> b
& Lens' Options (Maybe Auth)
auth forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. a -> Maybe a
Just (ByteString -> Auth
OAuth2Bearer (Text -> ByteString
Text.encodeUtf8 (CloudflareAuth -> Text
cloudflareAuthToken CloudflareAuth
authInfo)))
  Response ByteString
resp <- Options -> String -> IO (Response ByteString)
getWith Options
opts forall a b. (a -> b) -> a -> b
$ String
"https://api.cloudflare.com/client/v4/zones/" forall a. Semigroup a => a -> a -> a
<> (Text -> String
Text.unpack Text
zoneIdentifier) forall a. Semigroup a => a -> a -> a
<> String
"/dns_records/export"
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
Text.decodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
BSL.toStrict forall a b. (a -> b) -> a -> b
$ Response ByteString
resp forall s a. s -> Getting a s a -> a
^. forall body0 body1.
Lens (Response body0) (Response body1) body0 body1
responseBody


-- | Import DNS records in BIND format
importDNSRecords :: CloudflareAuth
                 -> Text -- ^ Zone identifier
                 -> Text -- ^ Bind config
                 -> Bool -- ^ If true, proxy the DNS record through Cloudflare
                 -> IO (Either String (ResultResponse ImportResponse))
importDNSRecords :: CloudflareAuth
-> Text
-> Text
-> Bool
-> IO (Either String (ResultResponse ImportResponse))
importDNSRecords CloudflareAuth
authInfo Text
zoneIdentifier Text
bindConfig Bool
proxied = do
  let opts :: Options
opts = Options
defaults forall a b. a -> (a -> b) -> b
& Lens' Options (Maybe Auth)
auth forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. a -> Maybe a
Just (ByteString -> Auth
OAuth2Bearer (Text -> ByteString
Text.encodeUtf8 (CloudflareAuth -> Text
cloudflareAuthToken CloudflareAuth
authInfo)))
  Response ByteString
resp <- forall a.
Postable a =>
Options -> String -> a -> IO (Response ByteString)
postWith Options
opts (String
"https://api.cloudflare.com/client/v4/zones/" forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack  Text
zoneIdentifier forall a. Semigroup a => a -> a -> a
<> String
"/dns_records/import") [Part]
form
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Response ByteString
resp forall s a. s -> Getting a s a -> a
^. forall body0 body1.
Lens (Response body0) (Response body1) body0 body1
responseBody forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to forall a. FromJSON a => ByteString -> Either String a
eitherDecode
  where
    form :: [Part]
    form :: [Part]
form = [
        -- TODO should this be utf8 encoded?
          forall (m :: * -> *).
Applicative m =>
Text -> ByteString -> PartM m
partBS Text
"file" forall a b. (a -> b) -> a -> b
$ Text -> ByteString
Text.encodeUtf8 Text
bindConfig
        , forall (m :: * -> *).
Applicative m =>
Text -> ByteString -> PartM m
partBS Text
"proxied" forall a b. (a -> b) -> a -> b
$ ByteString
proxiedStr
      ]
    proxiedStr :: ByteString
proxiedStr =
      case Bool
proxied of
        Bool
True -> ByteString
"true"
        Bool
False -> ByteString
"false"

-- | Scan DNS records for a zone
scanDNSRecords :: CloudflareAuth 
               -> Text -- ^ Zone identifier
               -> IO (Either String (ResultResponse ImportResponse))
scanDNSRecords :: CloudflareAuth
-> Text -> IO (Either String (ResultResponse ImportResponse))
scanDNSRecords CloudflareAuth
authInfo Text
zoneIdentifier = do
  let opts :: Options
opts = Options
defaults forall a b. a -> (a -> b) -> b
& Lens' Options (Maybe Auth)
auth forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. a -> Maybe a
Just (ByteString -> Auth
OAuth2Bearer (Text -> ByteString
Text.encodeUtf8 (CloudflareAuth -> Text
cloudflareAuthToken CloudflareAuth
authInfo)))
  Response ByteString
response <- forall a.
Postable a =>
Options -> String -> a -> IO (Response ByteString)
postWith Options
opts (String
"https://api.cloudflare.com/client/v4/zones/" forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack  Text
zoneIdentifier forall a. Semigroup a => a -> a -> a
<> String
"/dns_records/scan") (forall a. Monoid a => a
mempty :: BS.ByteString)
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Response ByteString
response forall s a. s -> Getting a s a -> a
^. forall body0 body1.
Lens (Response body0) (Response body1) body0 body1
responseBody forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to forall a. FromJSON a => ByteString -> Either String a
eitherDecode

-- | Delete a DNS record
deleteDNSRecord :: CloudflareAuth
                -> Text -- ^ Zone identifier
                -> Text -- ^ DNS identifier
                -> IO (Either String (ResultOnly DNSIdentifier))
deleteDNSRecord :: CloudflareAuth
-> Text -> Text -> IO (Either String (ResultOnly DNSIdentifier))
deleteDNSRecord CloudflareAuth
authInfo Text
zoneIdentifier Text
dnsIdentifier = do
  let opts :: Options
opts = Options
defaults forall a b. a -> (a -> b) -> b
& Lens' Options (Maybe Auth)
auth forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. a -> Maybe a
Just (ByteString -> Auth
OAuth2Bearer (Text -> ByteString
Text.encodeUtf8 (CloudflareAuth -> Text
cloudflareAuthToken CloudflareAuth
authInfo)))
  Response ByteString
response <- Options -> String -> IO (Response ByteString)
deleteWith Options
opts (String
"https://api.cloudflare.com/client/v4/zones/" forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
zoneIdentifier forall a. Semigroup a => a -> a -> a
<> String
"/dns_records/" forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
dnsIdentifier)
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Response ByteString
response forall s a. s -> Getting a s a -> a
^. forall body0 body1.
Lens (Response body0) (Response body1) body0 body1
responseBody forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to forall a. FromJSON a => ByteString -> Either String a
eitherDecode

-- | Get a single DNS record for
dnsRecordDetails :: CloudflareAuth
                 -> Text -- ^ Zone identifier
                 -> Text -- ^ DNS identifier
                 -> IO (Response (ResultResponse DNSEntry))
dnsRecordDetails :: CloudflareAuth
-> Text -> Text -> IO (Response (ResultResponse DNSEntry))
dnsRecordDetails CloudflareAuth
authInfo Text
zoneIdentifier Text
dnsIdentifier = do
  let opts :: Options
opts = Options
defaults forall a b. a -> (a -> b) -> b
& Lens' Options (Maybe Auth)
auth forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. a -> Maybe a
Just (ByteString -> Auth
OAuth2Bearer (Text -> ByteString
Text.encodeUtf8 (CloudflareAuth -> Text
cloudflareAuthToken CloudflareAuth
authInfo)))
  forall (m :: * -> *) a.
(MonadThrow m, FromJSON a) =>
Response ByteString -> m (Response a)
asJSON forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Options -> String -> IO (Response ByteString)
getWith Options
opts (String
"https://api.cloudflare.com/client/v4/zones/" forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
zoneIdentifier forall a. Semigroup a => a -> a -> a
<> String
"/dns_records/" forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
dnsIdentifier)

-- | Patch a DNS record
patchDNSRecord :: DNSRecord record
               => CloudflareAuth
               -> Text -- ^ Zone identifier
               -> Text -- ^ DNS identifier
               -> CreateDNSRecord record
               -> IO (Either String (ResultResponse DNSEntry))
patchDNSRecord :: forall record.
DNSRecord record =>
CloudflareAuth
-> Text
-> Text
-> CreateDNSRecord record
-> IO (Either String (ResultResponse DNSEntry))
patchDNSRecord CloudflareAuth
authInfo Text
zoneIdentifier Text
dnsIdentifier CreateDNSRecord record
create = do
  let opts :: Options
opts = Options
defaults forall a b. a -> (a -> b) -> b
& Lens' Options (Maybe Auth)
auth forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. a -> Maybe a
Just (ByteString -> Auth
OAuth2Bearer (Text -> ByteString
Text.encodeUtf8 (CloudflareAuth -> Text
cloudflareAuthToken CloudflareAuth
authInfo)))
  Response ByteString
response <- forall a.
Patchable a =>
Options -> String -> a -> IO (Response ByteString)
patchWith Options
opts (String
"https://api.cloudflare.com/client/v4/zones/" forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
zoneIdentifier forall a. Semigroup a => a -> a -> a
<> String
"/dns_records/" forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
dnsIdentifier) (forall a. ToJSON a => a -> Value
toJSON CreateDNSRecord record
create)
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Response ByteString
response forall s a. s -> Getting a s a -> a
^. forall body0 body1.
Lens (Response body0) (Response body1) body0 body1
responseBody forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to forall a. FromJSON a => ByteString -> Either String a
eitherDecode

-- | Update a DNS record
updateDNSRecord :: DNSRecord record
                => CloudflareAuth
                -> Text -- ^ Zone identifier
                -> Text -- ^ DNS identifier
                -> CreateDNSRecord record
                -> IO (Either String (ResultResponse DNSEntry))
updateDNSRecord :: forall record.
DNSRecord record =>
CloudflareAuth
-> Text
-> Text
-> CreateDNSRecord record
-> IO (Either String (ResultResponse DNSEntry))
updateDNSRecord CloudflareAuth
authInfo Text
zoneIdentifier Text
dnsIdentifier CreateDNSRecord record
create = do
  let opts :: Options
opts = Options
defaults forall a b. a -> (a -> b) -> b
& Lens' Options (Maybe Auth)
auth forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. a -> Maybe a
Just (ByteString -> Auth
OAuth2Bearer (Text -> ByteString
Text.encodeUtf8 (CloudflareAuth -> Text
cloudflareAuthToken CloudflareAuth
authInfo)))
  Response ByteString
response <- forall a.
Putable a =>
Options -> String -> a -> IO (Response ByteString)
putWith Options
opts (String
"https://api.cloudflare.com/client/v4/zones/" forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
zoneIdentifier forall a. Semigroup a => a -> a -> a
<> String
"/dns_records/" forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
dnsIdentifier) (forall a. ToJSON a => a -> Value
toJSON CreateDNSRecord record
create)
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Response ByteString
response forall s a. s -> Getting a s a -> a
^. forall body0 body1.
Lens (Response body0) (Response body1) body0 body1
responseBody forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to forall a. FromJSON a => ByteString -> Either String a
eitherDecode

-- TODO add timing from response
data ImportResponse = ImportResponse {
  ImportResponse -> Int
importResponseRecsAdded :: Int -- ^ Number of DNS records added
, ImportResponse -> Int
importResponseTotalRecordsParsed :: Int -- ^ Total number of DNS records parsed
} deriving (ImportResponse -> ImportResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ImportResponse -> ImportResponse -> Bool
$c/= :: ImportResponse -> ImportResponse -> Bool
== :: ImportResponse -> ImportResponse -> Bool
$c== :: ImportResponse -> ImportResponse -> Bool
Eq, Eq ImportResponse
ImportResponse -> ImportResponse -> Bool
ImportResponse -> ImportResponse -> Ordering
ImportResponse -> ImportResponse -> ImportResponse
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ImportResponse -> ImportResponse -> ImportResponse
$cmin :: ImportResponse -> ImportResponse -> ImportResponse
max :: ImportResponse -> ImportResponse -> ImportResponse
$cmax :: ImportResponse -> ImportResponse -> ImportResponse
>= :: ImportResponse -> ImportResponse -> Bool
$c>= :: ImportResponse -> ImportResponse -> Bool
> :: ImportResponse -> ImportResponse -> Bool
$c> :: ImportResponse -> ImportResponse -> Bool
<= :: ImportResponse -> ImportResponse -> Bool
$c<= :: ImportResponse -> ImportResponse -> Bool
< :: ImportResponse -> ImportResponse -> Bool
$c< :: ImportResponse -> ImportResponse -> Bool
compare :: ImportResponse -> ImportResponse -> Ordering
$ccompare :: ImportResponse -> ImportResponse -> Ordering
Ord, Int -> ImportResponse -> ShowS
[ImportResponse] -> ShowS
ImportResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ImportResponse] -> ShowS
$cshowList :: [ImportResponse] -> ShowS
show :: ImportResponse -> String
$cshow :: ImportResponse -> String
showsPrec :: Int -> ImportResponse -> ShowS
$cshowsPrec :: Int -> ImportResponse -> ShowS
Show)

instance FromJSON ImportResponse where
  parseJSON :: Value -> Parser ImportResponse
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ImportResponse" forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    Int
added <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"recs_added"
    Int
parsed <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"total_records_parsed"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Int -> Int -> ImportResponse
ImportResponse Int
added Int
parsed

newtype DNSIdentifier = DNSIdentifier {
  DNSIdentifier -> Text
dnsIdentifierId :: Text
} deriving (DNSIdentifier -> DNSIdentifier -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DNSIdentifier -> DNSIdentifier -> Bool
$c/= :: DNSIdentifier -> DNSIdentifier -> Bool
== :: DNSIdentifier -> DNSIdentifier -> Bool
$c== :: DNSIdentifier -> DNSIdentifier -> Bool
Eq, Eq DNSIdentifier
DNSIdentifier -> DNSIdentifier -> Bool
DNSIdentifier -> DNSIdentifier -> Ordering
DNSIdentifier -> DNSIdentifier -> DNSIdentifier
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: DNSIdentifier -> DNSIdentifier -> DNSIdentifier
$cmin :: DNSIdentifier -> DNSIdentifier -> DNSIdentifier
max :: DNSIdentifier -> DNSIdentifier -> DNSIdentifier
$cmax :: DNSIdentifier -> DNSIdentifier -> DNSIdentifier
>= :: DNSIdentifier -> DNSIdentifier -> Bool
$c>= :: DNSIdentifier -> DNSIdentifier -> Bool
> :: DNSIdentifier -> DNSIdentifier -> Bool
$c> :: DNSIdentifier -> DNSIdentifier -> Bool
<= :: DNSIdentifier -> DNSIdentifier -> Bool
$c<= :: DNSIdentifier -> DNSIdentifier -> Bool
< :: DNSIdentifier -> DNSIdentifier -> Bool
$c< :: DNSIdentifier -> DNSIdentifier -> Bool
compare :: DNSIdentifier -> DNSIdentifier -> Ordering
$ccompare :: DNSIdentifier -> DNSIdentifier -> Ordering
Ord, Int -> DNSIdentifier -> ShowS
[DNSIdentifier] -> ShowS
DNSIdentifier -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DNSIdentifier] -> ShowS
$cshowList :: [DNSIdentifier] -> ShowS
show :: DNSIdentifier -> String
$cshow :: DNSIdentifier -> String
showsPrec :: Int -> DNSIdentifier -> ShowS
$cshowsPrec :: Int -> DNSIdentifier -> ShowS
Show)

instance FromJSON DNSIdentifier where
  parseJSON :: Value -> Parser DNSIdentifier
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"DNSIdentifier" forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    Text
id' <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> DNSIdentifier
DNSIdentifier Text
id'

data DNSEntry =
    ARecordEntry (DNSRecordEntry ARecord)
  | AAAARecordEntry (DNSRecordEntry AAAARecord)
  | CAARecordEntry (DNSRecordEntry CAARecord)
  | CERTRecordEntry (DNSRecordEntry CERTRecord)
  | CNAMERecordEntry (DNSRecordEntry CNAMERecord)
  | DNSKEYRecordEntry (DNSRecordEntry DNSKEYRecord)
  | DSRecordEntry (DNSRecordEntry DSRecord)
  | HTTPSRecordEntry (DNSRecordEntry HTTPSRecord)
  | LOCRecordEntry (DNSRecordEntry LOCRecord)
  | MXRecordEntry (DNSRecordEntry MXRecord)
  | NAPTRRecordEntry (DNSRecordEntry NAPTRRecord)
  | NSRecordEntry (DNSRecordEntry NSRecord)
  | PTRRecordEntry (DNSRecordEntry PTRRecord)
  | SMIMEARecordEntry (DNSRecordEntry SMIMEARecord)
  | SRVRecordEntry (DNSRecordEntry SRVRecord)
  | SSHFPRecordEntry (DNSRecordEntry SSHFPRecord)
  | SVCBRecordEntry (DNSRecordEntry SVCBRecord)
  | TLSARecordEntry (DNSRecordEntry TLSARecord)
  | TXTRecordEntry (DNSRecordEntry TXTRecord)
  | URIRecordEntry (DNSRecordEntry URIRecord)
  deriving (DNSEntry -> DNSEntry -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DNSEntry -> DNSEntry -> Bool
$c/= :: DNSEntry -> DNSEntry -> Bool
== :: DNSEntry -> DNSEntry -> Bool
$c== :: DNSEntry -> DNSEntry -> Bool
Eq, Eq DNSEntry
DNSEntry -> DNSEntry -> Bool
DNSEntry -> DNSEntry -> Ordering
DNSEntry -> DNSEntry -> DNSEntry
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: DNSEntry -> DNSEntry -> DNSEntry
$cmin :: DNSEntry -> DNSEntry -> DNSEntry
max :: DNSEntry -> DNSEntry -> DNSEntry
$cmax :: DNSEntry -> DNSEntry -> DNSEntry
>= :: DNSEntry -> DNSEntry -> Bool
$c>= :: DNSEntry -> DNSEntry -> Bool
> :: DNSEntry -> DNSEntry -> Bool
$c> :: DNSEntry -> DNSEntry -> Bool
<= :: DNSEntry -> DNSEntry -> Bool
$c<= :: DNSEntry -> DNSEntry -> Bool
< :: DNSEntry -> DNSEntry -> Bool
$c< :: DNSEntry -> DNSEntry -> Bool
compare :: DNSEntry -> DNSEntry -> Ordering
$ccompare :: DNSEntry -> DNSEntry -> Ordering
Ord, Int -> DNSEntry -> ShowS
[DNSEntry] -> ShowS
DNSEntry -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DNSEntry] -> ShowS
$cshowList :: [DNSEntry] -> ShowS
show :: DNSEntry -> String
$cshow :: DNSEntry -> String
showsPrec :: Int -> DNSEntry -> ShowS
$cshowsPrec :: Int -> DNSEntry -> ShowS
Show)

withDNSEntry :: (forall record. DNSRecord record => DNSRecordEntry record -> a) -> DNSEntry -> a
withDNSEntry :: forall a.
(forall record. DNSRecord record => DNSRecordEntry record -> a)
-> DNSEntry -> a
withDNSEntry forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSEntry
entry =
  case DNSEntry
entry of
    ARecordEntry DNSRecordEntry ARecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry ARecord
e
    AAAARecordEntry DNSRecordEntry AAAARecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry AAAARecord
e
    CAARecordEntry DNSRecordEntry CAARecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry CAARecord
e
    CERTRecordEntry DNSRecordEntry CERTRecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry CERTRecord
e
    CNAMERecordEntry DNSRecordEntry CNAMERecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry CNAMERecord
e
    DNSKEYRecordEntry DNSRecordEntry DNSKEYRecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry DNSKEYRecord
e
    DSRecordEntry DNSRecordEntry DSRecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry DSRecord
e
    HTTPSRecordEntry DNSRecordEntry HTTPSRecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry HTTPSRecord
e
    LOCRecordEntry DNSRecordEntry LOCRecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry LOCRecord
e
    MXRecordEntry DNSRecordEntry MXRecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry MXRecord
e
    NAPTRRecordEntry DNSRecordEntry NAPTRRecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry NAPTRRecord
e
    NSRecordEntry DNSRecordEntry NSRecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry NSRecord
e
    PTRRecordEntry DNSRecordEntry PTRRecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry PTRRecord
e
    SMIMEARecordEntry DNSRecordEntry SMIMEARecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry SMIMEARecord
e
    SRVRecordEntry DNSRecordEntry SRVRecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry SRVRecord
e
    SSHFPRecordEntry DNSRecordEntry SSHFPRecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry SSHFPRecord
e
    SVCBRecordEntry DNSRecordEntry SVCBRecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry SVCBRecord
e
    TLSARecordEntry DNSRecordEntry TLSARecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry TLSARecord
e
    TXTRecordEntry DNSRecordEntry TXTRecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry TXTRecord
e
    URIRecordEntry DNSRecordEntry URIRecord
e -> forall record. DNSRecord record => DNSRecordEntry record -> a
f DNSRecordEntry URIRecord
e

instance FromJSON DNSEntry where
  parseJSON :: Value -> Parser DNSEntry
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"DNSEntry" forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    Text
type' :: Text <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
    case Text
type' of
      Text
"A" -> DNSRecordEntry ARecord -> DNSEntry
ARecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"AAAA" -> DNSRecordEntry AAAARecord -> DNSEntry
AAAARecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"CAA" -> DNSRecordEntry CAARecord -> DNSEntry
CAARecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"CERT" -> DNSRecordEntry CERTRecord -> DNSEntry
CERTRecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"CNAME" -> DNSRecordEntry CNAMERecord -> DNSEntry
CNAMERecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"DNSKEY" -> DNSRecordEntry DNSKEYRecord -> DNSEntry
DNSKEYRecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"DS" -> DNSRecordEntry DSRecord -> DNSEntry
DSRecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"HTTPS" -> DNSRecordEntry HTTPSRecord -> DNSEntry
HTTPSRecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"LOC" -> DNSRecordEntry LOCRecord -> DNSEntry
LOCRecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"MX" -> DNSRecordEntry MXRecord -> DNSEntry
MXRecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"NAPTR" -> DNSRecordEntry NAPTRRecord -> DNSEntry
NAPTRRecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"NS" -> DNSRecordEntry NSRecord -> DNSEntry
NSRecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"PTR" -> DNSRecordEntry PTRRecord -> DNSEntry
PTRRecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"SMIMEA" -> DNSRecordEntry SMIMEARecord -> DNSEntry
SMIMEARecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"SRV" -> DNSRecordEntry SRVRecord -> DNSEntry
SRVRecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"SSHFP" -> DNSRecordEntry SSHFPRecord -> DNSEntry
SSHFPRecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"SVCB" -> DNSRecordEntry SVCBRecord -> DNSEntry
SVCBRecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"TLSA" -> DNSRecordEntry TLSARecord -> DNSEntry
TLSARecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"TXT" -> DNSRecordEntry TXTRecord -> DNSEntry
TXTRecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
"URI" -> DNSRecordEntry URIRecord -> DNSEntry
URIRecordEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
      Text
_ -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"Unknown DNS record type: " forall a. [a] -> [a] -> [a]
++ Text -> String
Text.unpack Text
type'

class DNSRecord record where
  dnsRecordToJSON :: record -> [Pair] -- ^ Type of the record and a list the fields of the record
  dnsRecordType :: record -> Text -- ^ DNS record type
  dnsRecordParse :: Object -> Parser record -- ^ Parse the fields of the record

-- | DNS entries returned by the Cloudflare API 
data DNSRecordEntry record = DNSRecordEntry {
  forall record. DNSRecordEntry record -> record
dnsRecordEntryData :: record
, forall record. DNSRecordEntry record -> Text
dnsRecordEntryType :: Text -- ^ DNS record type
, forall record. DNSRecordEntry record -> Text
dnsRecordEntryContent :: Text -- ^ DNS record content
, forall record. DNSRecordEntry record -> Maybe Text
dnsRecordEntryComment :: Maybe Text -- ^ Comments or notes about the DNS record. This field has no effect on DNS responses
, forall record. DNSRecordEntry record -> UTCTime
dnsRecordEntryCreatedOn :: UTCTime
, forall record. DNSRecordEntry record -> Text
dnsRecordEntryId :: Text
, forall record. DNSRecordEntry record -> Bool
dnsRecordEntryLocked :: Bool
, forall record. DNSRecordEntry record -> Maybe Object
dnsRecordEntryMeta :: Maybe Object -- TODO maybe make this a specific type
, forall record. DNSRecordEntry record -> UTCTime
dnsRecordEntryModifiedOn :: UTCTime
, forall record. DNSRecordEntry record -> Bool
dnsRecordEntryProxiable :: Bool
, forall record. DNSRecordEntry record -> [Text]
dnsRecordEntryTags :: [Text] -- ^ Custom tags for the DNS record. This field has no effect on DNS responses.
, forall record. DNSRecordEntry record -> Word32
dnsRecordEntryTTL :: Word32 -- ^ Time To Live (TTL) of the DNS record in seconds. Setting to 1 means 'automatic'. Value must be between 60 and 86400, with the minimum reduced to 30 for Enterprise zones.
, forall record. DNSRecordEntry record -> Text
dnsRecordEntryZoneId :: Text -- ^ Zone identifier
, forall record. DNSRecordEntry record -> Text
dnsRecordEntryZoneName :: Text -- ^ Zone name
} deriving (DNSRecordEntry record -> DNSRecordEntry record -> Bool
forall record.
Eq record =>
DNSRecordEntry record -> DNSRecordEntry record -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DNSRecordEntry record -> DNSRecordEntry record -> Bool
$c/= :: forall record.
Eq record =>
DNSRecordEntry record -> DNSRecordEntry record -> Bool
== :: DNSRecordEntry record -> DNSRecordEntry record -> Bool
$c== :: forall record.
Eq record =>
DNSRecordEntry record -> DNSRecordEntry record -> Bool
Eq, DNSRecordEntry record -> DNSRecordEntry record -> Bool
DNSRecordEntry record -> DNSRecordEntry record -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {record}. Ord record => Eq (DNSRecordEntry record)
forall record.
Ord record =>
DNSRecordEntry record -> DNSRecordEntry record -> Bool
forall record.
Ord record =>
DNSRecordEntry record -> DNSRecordEntry record -> Ordering
forall record.
Ord record =>
DNSRecordEntry record
-> DNSRecordEntry record -> DNSRecordEntry record
min :: DNSRecordEntry record
-> DNSRecordEntry record -> DNSRecordEntry record
$cmin :: forall record.
Ord record =>
DNSRecordEntry record
-> DNSRecordEntry record -> DNSRecordEntry record
max :: DNSRecordEntry record
-> DNSRecordEntry record -> DNSRecordEntry record
$cmax :: forall record.
Ord record =>
DNSRecordEntry record
-> DNSRecordEntry record -> DNSRecordEntry record
>= :: DNSRecordEntry record -> DNSRecordEntry record -> Bool
$c>= :: forall record.
Ord record =>
DNSRecordEntry record -> DNSRecordEntry record -> Bool
> :: DNSRecordEntry record -> DNSRecordEntry record -> Bool
$c> :: forall record.
Ord record =>
DNSRecordEntry record -> DNSRecordEntry record -> Bool
<= :: DNSRecordEntry record -> DNSRecordEntry record -> Bool
$c<= :: forall record.
Ord record =>
DNSRecordEntry record -> DNSRecordEntry record -> Bool
< :: DNSRecordEntry record -> DNSRecordEntry record -> Bool
$c< :: forall record.
Ord record =>
DNSRecordEntry record -> DNSRecordEntry record -> Bool
compare :: DNSRecordEntry record -> DNSRecordEntry record -> Ordering
$ccompare :: forall record.
Ord record =>
DNSRecordEntry record -> DNSRecordEntry record -> Ordering
Ord, Int -> DNSRecordEntry record -> ShowS
forall record. Show record => Int -> DNSRecordEntry record -> ShowS
forall record. Show record => [DNSRecordEntry record] -> ShowS
forall record. Show record => DNSRecordEntry record -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DNSRecordEntry record] -> ShowS
$cshowList :: forall record. Show record => [DNSRecordEntry record] -> ShowS
show :: DNSRecordEntry record -> String
$cshow :: forall record. Show record => DNSRecordEntry record -> String
showsPrec :: Int -> DNSRecordEntry record -> ShowS
$cshowsPrec :: forall record. Show record => Int -> DNSRecordEntry record -> ShowS
Show)

instance DNSRecord record => FromJSON (DNSRecordEntry record) where
  parseJSON :: Value -> Parser (DNSRecordEntry record)
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"DNSRecordEntry" forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    record
data' <- forall record. DNSRecord record => Object -> Parser record
dnsRecordParse Object
o
    Text
content <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"content"
    Text
type' <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
    Maybe Text
comment <- Object
o forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"comment"
    UTCTime
createdOn <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"created_on"
    Text
id' <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
    Bool
locked <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"locked"
    Maybe Object
meta <- Object
o forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"meta"
    UTCTime
modifiedOn <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"modified_on"
    Bool
proxiable <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"proxiable"
    [Text]
tags <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"tags"
    Word32
ttl <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"ttl"
    Text
zId <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"zone_id"
    Text
zName <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"zone_name"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall record.
record
-> Text
-> Text
-> Maybe Text
-> UTCTime
-> Text
-> Bool
-> Maybe Object
-> UTCTime
-> Bool
-> [Text]
-> Word32
-> Text
-> Text
-> DNSRecordEntry record
DNSRecordEntry record
data' Text
type' Text
content Maybe Text
comment UTCTime
createdOn Text
id' Bool
locked Maybe Object
meta UTCTime
modifiedOn Bool
proxiable [Text]
tags Word32
ttl Text
zId Text
zName

-- | Create a new DNS record for a zone
data CreateDNSRecord record = CreateDNSRecord {
  forall record. CreateDNSRecord record -> record
createDNSRecordData :: record -- ^ The data for the DNS record
, forall record. CreateDNSRecord record -> Text
createDNSRecordName :: Text -- ^ DNS record name (or @ for the zone apex) in Punycode
, forall record. CreateDNSRecord record -> Bool
createDNSRecordProxied :: Bool -- ^ Use Cloudflare's proxying for this record
, forall record. CreateDNSRecord record -> Maybe Text
createDNSRecordComment :: Maybe Text -- ^ Comments or notes about the DNS record. This field has no effect on DNS responses
, forall record. CreateDNSRecord record -> [Text]
createDNSRecordTags :: [Text] -- ^ Custom tags for the DNS record. This field has no effect on DNS responses. Not available in the free plan
, forall record. CreateDNSRecord record -> Word32
createDNSRecordTTL :: Word32 -- ^ Time To Live (TTL) of the DNS record in seconds. Setting to 1 means 'automatic'. Value must be between 60 and 86400, with the minimum reduced to 30 for Enterprise zones.
} deriving (CreateDNSRecord record -> CreateDNSRecord record -> Bool
forall record.
Eq record =>
CreateDNSRecord record -> CreateDNSRecord record -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateDNSRecord record -> CreateDNSRecord record -> Bool
$c/= :: forall record.
Eq record =>
CreateDNSRecord record -> CreateDNSRecord record -> Bool
== :: CreateDNSRecord record -> CreateDNSRecord record -> Bool
$c== :: forall record.
Eq record =>
CreateDNSRecord record -> CreateDNSRecord record -> Bool
Eq, CreateDNSRecord record -> CreateDNSRecord record -> Bool
CreateDNSRecord record -> CreateDNSRecord record -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {record}. Ord record => Eq (CreateDNSRecord record)
forall record.
Ord record =>
CreateDNSRecord record -> CreateDNSRecord record -> Bool
forall record.
Ord record =>
CreateDNSRecord record -> CreateDNSRecord record -> Ordering
forall record.
Ord record =>
CreateDNSRecord record
-> CreateDNSRecord record -> CreateDNSRecord record
min :: CreateDNSRecord record
-> CreateDNSRecord record -> CreateDNSRecord record
$cmin :: forall record.
Ord record =>
CreateDNSRecord record
-> CreateDNSRecord record -> CreateDNSRecord record
max :: CreateDNSRecord record
-> CreateDNSRecord record -> CreateDNSRecord record
$cmax :: forall record.
Ord record =>
CreateDNSRecord record
-> CreateDNSRecord record -> CreateDNSRecord record
>= :: CreateDNSRecord record -> CreateDNSRecord record -> Bool
$c>= :: forall record.
Ord record =>
CreateDNSRecord record -> CreateDNSRecord record -> Bool
> :: CreateDNSRecord record -> CreateDNSRecord record -> Bool
$c> :: forall record.
Ord record =>
CreateDNSRecord record -> CreateDNSRecord record -> Bool
<= :: CreateDNSRecord record -> CreateDNSRecord record -> Bool
$c<= :: forall record.
Ord record =>
CreateDNSRecord record -> CreateDNSRecord record -> Bool
< :: CreateDNSRecord record -> CreateDNSRecord record -> Bool
$c< :: forall record.
Ord record =>
CreateDNSRecord record -> CreateDNSRecord record -> Bool
compare :: CreateDNSRecord record -> CreateDNSRecord record -> Ordering
$ccompare :: forall record.
Ord record =>
CreateDNSRecord record -> CreateDNSRecord record -> Ordering
Ord, Int -> CreateDNSRecord record -> ShowS
forall record.
Show record =>
Int -> CreateDNSRecord record -> ShowS
forall record. Show record => [CreateDNSRecord record] -> ShowS
forall record. Show record => CreateDNSRecord record -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateDNSRecord record] -> ShowS
$cshowList :: forall record. Show record => [CreateDNSRecord record] -> ShowS
show :: CreateDNSRecord record -> String
$cshow :: forall record. Show record => CreateDNSRecord record -> String
showsPrec :: Int -> CreateDNSRecord record -> ShowS
$cshowsPrec :: forall record.
Show record =>
Int -> CreateDNSRecord record -> ShowS
Show)

instance DNSRecord record => ToJSON (CreateDNSRecord record) where
  toJSON :: CreateDNSRecord record -> Value
toJSON (CreateDNSRecord record
record Text
name Bool
proxied Maybe Text
comment [Text]
tags Word32
ttl) =
    [Pair] -> Value
object forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => [a] -> a
mconcat [
      forall record. DNSRecord record => record -> [Pair]
dnsRecordToJSON record
record
    , [ Key
"type" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= forall record. DNSRecord record => record -> Text
dnsRecordType record
record
      , Key
"name" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
name
      , Key
"tags" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [Text]
tags
      , Key
"ttl" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word32
ttl
      , Key
"proxied" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Bool
proxied
      ]
    , forall a. [Maybe a] -> [a]
catMaybes [
          (Key
"comment" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
comment
        ]
    ]

-- | RFC 1035 A record
data ARecord = ARecord {
  ARecord -> Text
aRecordContent :: Text -- ^ Valid IPv4 address.
} deriving (ARecord -> ARecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ARecord -> ARecord -> Bool
$c/= :: ARecord -> ARecord -> Bool
== :: ARecord -> ARecord -> Bool
$c== :: ARecord -> ARecord -> Bool
Eq, Eq ARecord
ARecord -> ARecord -> Bool
ARecord -> ARecord -> Ordering
ARecord -> ARecord -> ARecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ARecord -> ARecord -> ARecord
$cmin :: ARecord -> ARecord -> ARecord
max :: ARecord -> ARecord -> ARecord
$cmax :: ARecord -> ARecord -> ARecord
>= :: ARecord -> ARecord -> Bool
$c>= :: ARecord -> ARecord -> Bool
> :: ARecord -> ARecord -> Bool
$c> :: ARecord -> ARecord -> Bool
<= :: ARecord -> ARecord -> Bool
$c<= :: ARecord -> ARecord -> Bool
< :: ARecord -> ARecord -> Bool
$c< :: ARecord -> ARecord -> Bool
compare :: ARecord -> ARecord -> Ordering
$ccompare :: ARecord -> ARecord -> Ordering
Ord, Int -> ARecord -> ShowS
[ARecord] -> ShowS
ARecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ARecord] -> ShowS
$cshowList :: [ARecord] -> ShowS
show :: ARecord -> String
$cshow :: ARecord -> String
showsPrec :: Int -> ARecord -> ShowS
$cshowsPrec :: Int -> ARecord -> ShowS
Show)

instance DNSRecord ARecord where
  dnsRecordType :: ARecord -> Text
dnsRecordType ARecord
_ = Text
"A"
  dnsRecordToJSON :: ARecord -> [Pair]
dnsRecordToJSON (ARecord Text
content) =
    [ Key
"content" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
content
    ]
  dnsRecordParse :: Object -> Parser ARecord
dnsRecordParse Object
o = do
    Text
content <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"content"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> ARecord
ARecord Text
content

-- | RFC 3596 AAAA record
data AAAARecord = AAAARecord {
  AAAARecord -> Text
aaaaRecordContent :: Text -- ^ Valid IPv6 address.
} deriving (AAAARecord -> AAAARecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AAAARecord -> AAAARecord -> Bool
$c/= :: AAAARecord -> AAAARecord -> Bool
== :: AAAARecord -> AAAARecord -> Bool
$c== :: AAAARecord -> AAAARecord -> Bool
Eq, Eq AAAARecord
AAAARecord -> AAAARecord -> Bool
AAAARecord -> AAAARecord -> Ordering
AAAARecord -> AAAARecord -> AAAARecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: AAAARecord -> AAAARecord -> AAAARecord
$cmin :: AAAARecord -> AAAARecord -> AAAARecord
max :: AAAARecord -> AAAARecord -> AAAARecord
$cmax :: AAAARecord -> AAAARecord -> AAAARecord
>= :: AAAARecord -> AAAARecord -> Bool
$c>= :: AAAARecord -> AAAARecord -> Bool
> :: AAAARecord -> AAAARecord -> Bool
$c> :: AAAARecord -> AAAARecord -> Bool
<= :: AAAARecord -> AAAARecord -> Bool
$c<= :: AAAARecord -> AAAARecord -> Bool
< :: AAAARecord -> AAAARecord -> Bool
$c< :: AAAARecord -> AAAARecord -> Bool
compare :: AAAARecord -> AAAARecord -> Ordering
$ccompare :: AAAARecord -> AAAARecord -> Ordering
Ord, Int -> AAAARecord -> ShowS
[AAAARecord] -> ShowS
AAAARecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AAAARecord] -> ShowS
$cshowList :: [AAAARecord] -> ShowS
show :: AAAARecord -> String
$cshow :: AAAARecord -> String
showsPrec :: Int -> AAAARecord -> ShowS
$cshowsPrec :: Int -> AAAARecord -> ShowS
Show)

instance DNSRecord AAAARecord where
  dnsRecordType :: AAAARecord -> Text
dnsRecordType AAAARecord
_ = Text
"AAAA"
  dnsRecordToJSON :: AAAARecord -> [Pair]
dnsRecordToJSON (AAAARecord Text
content) =
    [ Key
"content" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
content
    ]
  dnsRecordParse :: Object -> Parser AAAARecord
dnsRecordParse Object
o = do
    Text
content <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"content"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> AAAARecord
AAAARecord Text
content

-- | RFC 6844 CAA record
data CAARecord = CAARecord {
  CAARecord -> Word8
caaRecordFlags :: Word8 -- ^ Flags for the CAA record see RFC 6844 section 1
, CAARecord -> Text
caaRecordTag :: Text -- ^ Name of the property controlled by this record (e.g.: issue, issuewild, iodef). TODO make a specific type
, CAARecord -> Text
caaRecordValue :: Text -- ^ Value of the record. This field's semantics depend on the chosen tag.
} deriving (CAARecord -> CAARecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CAARecord -> CAARecord -> Bool
$c/= :: CAARecord -> CAARecord -> Bool
== :: CAARecord -> CAARecord -> Bool
$c== :: CAARecord -> CAARecord -> Bool
Eq, Eq CAARecord
CAARecord -> CAARecord -> Bool
CAARecord -> CAARecord -> Ordering
CAARecord -> CAARecord -> CAARecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CAARecord -> CAARecord -> CAARecord
$cmin :: CAARecord -> CAARecord -> CAARecord
max :: CAARecord -> CAARecord -> CAARecord
$cmax :: CAARecord -> CAARecord -> CAARecord
>= :: CAARecord -> CAARecord -> Bool
$c>= :: CAARecord -> CAARecord -> Bool
> :: CAARecord -> CAARecord -> Bool
$c> :: CAARecord -> CAARecord -> Bool
<= :: CAARecord -> CAARecord -> Bool
$c<= :: CAARecord -> CAARecord -> Bool
< :: CAARecord -> CAARecord -> Bool
$c< :: CAARecord -> CAARecord -> Bool
compare :: CAARecord -> CAARecord -> Ordering
$ccompare :: CAARecord -> CAARecord -> Ordering
Ord, Int -> CAARecord -> ShowS
[CAARecord] -> ShowS
CAARecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CAARecord] -> ShowS
$cshowList :: [CAARecord] -> ShowS
show :: CAARecord -> String
$cshow :: CAARecord -> String
showsPrec :: Int -> CAARecord -> ShowS
$cshowsPrec :: Int -> CAARecord -> ShowS
Show)

instance DNSRecord CAARecord where
  dnsRecordType :: CAARecord -> Text
dnsRecordType CAARecord
_ = Text
"CAA"
  dnsRecordToJSON :: CAARecord -> [Pair]
dnsRecordToJSON (CAARecord Word8
flags Text
tag Text
value) =
    [
      (Key
"data", [Pair] -> Value
object [
          Key
"flags" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word8
flags
        , Key
"tag" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
tag
        , Key
"value" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
value
      ])
    ]
  dnsRecordParse :: Object -> Parser CAARecord
dnsRecordParse Object
o = do
    Object
dataObj <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"data"
    Word8
flags <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"flags"
    Text
tag <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"tag"
    Text
value <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Word8 -> Text -> Text -> CAARecord
CAARecord Word8
flags Text
tag Text
value

-- | RFC4398 CERT record 
data CERTRecord = CERTRecord {
  CERTRecord -> Int
certRecordAlgorithm :: Int -- ^ Algorithm, defined in 2.1.3 of RFC4034
, CERTRecord -> Text
certRecordCertificate :: Text -- ^ Certificate
, CERTRecord -> Word16
certRecordKeyTag :: Word16 -- ^ Key tag, defined in appendix B of RFC4034
, CERTRecord -> Int
certRecordType :: Int -- ^ Type, section 2.1 of RFC4398 1 for X.509
} deriving (CERTRecord -> CERTRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CERTRecord -> CERTRecord -> Bool
$c/= :: CERTRecord -> CERTRecord -> Bool
== :: CERTRecord -> CERTRecord -> Bool
$c== :: CERTRecord -> CERTRecord -> Bool
Eq, Eq CERTRecord
CERTRecord -> CERTRecord -> Bool
CERTRecord -> CERTRecord -> Ordering
CERTRecord -> CERTRecord -> CERTRecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CERTRecord -> CERTRecord -> CERTRecord
$cmin :: CERTRecord -> CERTRecord -> CERTRecord
max :: CERTRecord -> CERTRecord -> CERTRecord
$cmax :: CERTRecord -> CERTRecord -> CERTRecord
>= :: CERTRecord -> CERTRecord -> Bool
$c>= :: CERTRecord -> CERTRecord -> Bool
> :: CERTRecord -> CERTRecord -> Bool
$c> :: CERTRecord -> CERTRecord -> Bool
<= :: CERTRecord -> CERTRecord -> Bool
$c<= :: CERTRecord -> CERTRecord -> Bool
< :: CERTRecord -> CERTRecord -> Bool
$c< :: CERTRecord -> CERTRecord -> Bool
compare :: CERTRecord -> CERTRecord -> Ordering
$ccompare :: CERTRecord -> CERTRecord -> Ordering
Ord, Int -> CERTRecord -> ShowS
[CERTRecord] -> ShowS
CERTRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CERTRecord] -> ShowS
$cshowList :: [CERTRecord] -> ShowS
show :: CERTRecord -> String
$cshow :: CERTRecord -> String
showsPrec :: Int -> CERTRecord -> ShowS
$cshowsPrec :: Int -> CERTRecord -> ShowS
Show)

instance DNSRecord CERTRecord where
  dnsRecordType :: CERTRecord -> Text
dnsRecordType CERTRecord
_ = Text
"CERT"
  dnsRecordToJSON :: CERTRecord -> [Pair]
dnsRecordToJSON (CERTRecord Int
algorithm Text
certificate Word16
keyTag Int
type') =
    [
      (Key
"data", [Pair] -> Value
object [
          Key
"algorithm" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
algorithm
        , Key
"certificate" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
certificate
        , Key
"key_tag" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word16
keyTag
        , Key
"type" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
type'
      ])
    ]
  dnsRecordParse :: Object -> Parser CERTRecord
dnsRecordParse Object
o = do
    Object
dataObj <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"data"
    Int
algorithm <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"algorithm"
    Text
certificate <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"certificate"
    Word16
keyTag <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"key_tag"
    Int
type' <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Int -> Text -> Word16 -> Int -> CERTRecord
CERTRecord Int
algorithm Text
certificate Word16
keyTag Int
type'

-- | RFC 1035 CNAME record, section 3.3.1
data CNAMERecord = CNAMERecord {
  CNAMERecord -> Text
cnameRecordContent :: Text -- ^ Domain name to which the record points to
} deriving (CNAMERecord -> CNAMERecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CNAMERecord -> CNAMERecord -> Bool
$c/= :: CNAMERecord -> CNAMERecord -> Bool
== :: CNAMERecord -> CNAMERecord -> Bool
$c== :: CNAMERecord -> CNAMERecord -> Bool
Eq, Eq CNAMERecord
CNAMERecord -> CNAMERecord -> Bool
CNAMERecord -> CNAMERecord -> Ordering
CNAMERecord -> CNAMERecord -> CNAMERecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CNAMERecord -> CNAMERecord -> CNAMERecord
$cmin :: CNAMERecord -> CNAMERecord -> CNAMERecord
max :: CNAMERecord -> CNAMERecord -> CNAMERecord
$cmax :: CNAMERecord -> CNAMERecord -> CNAMERecord
>= :: CNAMERecord -> CNAMERecord -> Bool
$c>= :: CNAMERecord -> CNAMERecord -> Bool
> :: CNAMERecord -> CNAMERecord -> Bool
$c> :: CNAMERecord -> CNAMERecord -> Bool
<= :: CNAMERecord -> CNAMERecord -> Bool
$c<= :: CNAMERecord -> CNAMERecord -> Bool
< :: CNAMERecord -> CNAMERecord -> Bool
$c< :: CNAMERecord -> CNAMERecord -> Bool
compare :: CNAMERecord -> CNAMERecord -> Ordering
$ccompare :: CNAMERecord -> CNAMERecord -> Ordering
Ord, Int -> CNAMERecord -> ShowS
[CNAMERecord] -> ShowS
CNAMERecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CNAMERecord] -> ShowS
$cshowList :: [CNAMERecord] -> ShowS
show :: CNAMERecord -> String
$cshow :: CNAMERecord -> String
showsPrec :: Int -> CNAMERecord -> ShowS
$cshowsPrec :: Int -> CNAMERecord -> ShowS
Show)

instance DNSRecord CNAMERecord where
  dnsRecordType :: CNAMERecord -> Text
dnsRecordType CNAMERecord
_ = Text
"CNAME"
  dnsRecordToJSON :: CNAMERecord -> [Pair]
dnsRecordToJSON (CNAMERecord Text
content) =
    [ Key
"content" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
content
    ]
  dnsRecordParse :: Object -> Parser CNAMERecord
dnsRecordParse Object
o = do
    Text
content <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"content"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> CNAMERecord
CNAMERecord Text
content

-- | RFC4034 DNSKEY record, defined in section 2
data DNSKEYRecord = DNSKEYRecord {
  DNSKEYRecord -> Word8
dnskeyRecordAlgorithm :: Word8 -- ^ Algorithm, defined in 2.1.3 of RFC4034
, DNSKEYRecord -> Word16
dnskeyRecordFlags :: Word16 -- ^ Flags for the DNSKEY record, defined in 2.1.1 of RFC4034
, DNSKEYRecord -> Word8
dnskeyRecordProtocol :: Word8 -- ^ Protocol for the DNSKEY record, defined in 2.1.2 of RFC4034
, DNSKEYRecord -> Text
dnskeyRecordPublicKey :: Text -- ^ Public key for the DNSKEY record, depends on the algorithm used, see appendix section A.1 of RFC4034
} deriving (DNSKEYRecord -> DNSKEYRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DNSKEYRecord -> DNSKEYRecord -> Bool
$c/= :: DNSKEYRecord -> DNSKEYRecord -> Bool
== :: DNSKEYRecord -> DNSKEYRecord -> Bool
$c== :: DNSKEYRecord -> DNSKEYRecord -> Bool
Eq, Eq DNSKEYRecord
DNSKEYRecord -> DNSKEYRecord -> Bool
DNSKEYRecord -> DNSKEYRecord -> Ordering
DNSKEYRecord -> DNSKEYRecord -> DNSKEYRecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: DNSKEYRecord -> DNSKEYRecord -> DNSKEYRecord
$cmin :: DNSKEYRecord -> DNSKEYRecord -> DNSKEYRecord
max :: DNSKEYRecord -> DNSKEYRecord -> DNSKEYRecord
$cmax :: DNSKEYRecord -> DNSKEYRecord -> DNSKEYRecord
>= :: DNSKEYRecord -> DNSKEYRecord -> Bool
$c>= :: DNSKEYRecord -> DNSKEYRecord -> Bool
> :: DNSKEYRecord -> DNSKEYRecord -> Bool
$c> :: DNSKEYRecord -> DNSKEYRecord -> Bool
<= :: DNSKEYRecord -> DNSKEYRecord -> Bool
$c<= :: DNSKEYRecord -> DNSKEYRecord -> Bool
< :: DNSKEYRecord -> DNSKEYRecord -> Bool
$c< :: DNSKEYRecord -> DNSKEYRecord -> Bool
compare :: DNSKEYRecord -> DNSKEYRecord -> Ordering
$ccompare :: DNSKEYRecord -> DNSKEYRecord -> Ordering
Ord, Int -> DNSKEYRecord -> ShowS
[DNSKEYRecord] -> ShowS
DNSKEYRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DNSKEYRecord] -> ShowS
$cshowList :: [DNSKEYRecord] -> ShowS
show :: DNSKEYRecord -> String
$cshow :: DNSKEYRecord -> String
showsPrec :: Int -> DNSKEYRecord -> ShowS
$cshowsPrec :: Int -> DNSKEYRecord -> ShowS
Show)

instance DNSRecord DNSKEYRecord where
  dnsRecordType :: DNSKEYRecord -> Text
dnsRecordType DNSKEYRecord
_ = Text
"DNSKEY"
  dnsRecordToJSON :: DNSKEYRecord -> [Pair]
dnsRecordToJSON (DNSKEYRecord Word8
algorithm Word16
flags Word8
protocol Text
publicKey) =
    [
      (Key
"data", [Pair] -> Value
object [
          Key
"algorithm" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word8
algorithm
        , Key
"flags" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word16
flags
        , Key
"protocol" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word8
protocol
        , Key
"public_key" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
publicKey
      ])
    ]
  dnsRecordParse :: Object -> Parser DNSKEYRecord
dnsRecordParse Object
o = do
    Object
dataObj <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"data"
    Word8
algorithm <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"algorithm"
    Word16
flags <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"flags"
    Word8
protocol <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"protocol"
    Text
publicKey <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"public_key"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Word8 -> Word16 -> Word8 -> Text -> DNSKEYRecord
DNSKEYRecord Word8
algorithm Word16
flags Word8
protocol Text
publicKey

-- | RFC4034 DS record, defined in section 5.1
data DSRecord = DSRecord {
  DSRecord -> Word8
dsRecordAlgorithm :: Word8 -- ^ Algorithm, defined in 5.1.2 of RFC4034
, DSRecord -> Text
dsRecordDigest :: Text -- ^ Digest, defined in 5.1.4 of RFC4034
, DSRecord -> Word8
dsRecordDigestType :: Word8 -- ^ Digest type, defined in 5.1.3 of RFC4034
, DSRecord -> Word16
dsRecordKeyTag :: Word16 -- ^ Key tag, defined in 5.1.1 of RFC4034
} deriving (DSRecord -> DSRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DSRecord -> DSRecord -> Bool
$c/= :: DSRecord -> DSRecord -> Bool
== :: DSRecord -> DSRecord -> Bool
$c== :: DSRecord -> DSRecord -> Bool
Eq, Eq DSRecord
DSRecord -> DSRecord -> Bool
DSRecord -> DSRecord -> Ordering
DSRecord -> DSRecord -> DSRecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: DSRecord -> DSRecord -> DSRecord
$cmin :: DSRecord -> DSRecord -> DSRecord
max :: DSRecord -> DSRecord -> DSRecord
$cmax :: DSRecord -> DSRecord -> DSRecord
>= :: DSRecord -> DSRecord -> Bool
$c>= :: DSRecord -> DSRecord -> Bool
> :: DSRecord -> DSRecord -> Bool
$c> :: DSRecord -> DSRecord -> Bool
<= :: DSRecord -> DSRecord -> Bool
$c<= :: DSRecord -> DSRecord -> Bool
< :: DSRecord -> DSRecord -> Bool
$c< :: DSRecord -> DSRecord -> Bool
compare :: DSRecord -> DSRecord -> Ordering
$ccompare :: DSRecord -> DSRecord -> Ordering
Ord, Int -> DSRecord -> ShowS
[DSRecord] -> ShowS
DSRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DSRecord] -> ShowS
$cshowList :: [DSRecord] -> ShowS
show :: DSRecord -> String
$cshow :: DSRecord -> String
showsPrec :: Int -> DSRecord -> ShowS
$cshowsPrec :: Int -> DSRecord -> ShowS
Show)

instance DNSRecord DSRecord where
  dnsRecordType :: DSRecord -> Text
dnsRecordType DSRecord
_ = Text
"DS"
  dnsRecordToJSON :: DSRecord -> [Pair]
dnsRecordToJSON (DSRecord Word8
algorithm Text
digest Word8
digestType Word16
keyTag) =
    [
      (Key
"data", [Pair] -> Value
object [
          Key
"algorithm" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word8
algorithm
        , Key
"digest" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
digest
        , Key
"digest_type" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word8
digestType
        , Key
"key_tag" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word16
keyTag
      ])
    ]
  dnsRecordParse :: Object -> Parser DSRecord
dnsRecordParse Object
o = do
    Object
dataObj <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"data"
    Word8
algorithm <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"algorithm"
    Text
digest <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"digest"
    Word8
digestType <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"digest_type"
    Word16
keyTag <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"key_tag"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Word8 -> Text -> Word8 -> Word16 -> DSRecord
DSRecord Word8
algorithm Text
digest Word8
digestType Word16
keyTag

-- | Defined in section 1.2 of draft-ietf-dnsop-svcb-https-12, it shares the same structure as the SVCB record
data HTTPSRecord = HTTPSRecord {
  HTTPSRecord -> Word16
httpsRecordPriority :: Word16 -- ^ priority
, HTTPSRecord -> Text
httpsRecordTarget :: Text -- ^ target
, HTTPSRecord -> Text
httpsRecordValue :: Text -- ^ value TODO this could be made into a [(Text, Text))] 
} deriving (HTTPSRecord -> HTTPSRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HTTPSRecord -> HTTPSRecord -> Bool
$c/= :: HTTPSRecord -> HTTPSRecord -> Bool
== :: HTTPSRecord -> HTTPSRecord -> Bool
$c== :: HTTPSRecord -> HTTPSRecord -> Bool
Eq, Eq HTTPSRecord
HTTPSRecord -> HTTPSRecord -> Bool
HTTPSRecord -> HTTPSRecord -> Ordering
HTTPSRecord -> HTTPSRecord -> HTTPSRecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: HTTPSRecord -> HTTPSRecord -> HTTPSRecord
$cmin :: HTTPSRecord -> HTTPSRecord -> HTTPSRecord
max :: HTTPSRecord -> HTTPSRecord -> HTTPSRecord
$cmax :: HTTPSRecord -> HTTPSRecord -> HTTPSRecord
>= :: HTTPSRecord -> HTTPSRecord -> Bool
$c>= :: HTTPSRecord -> HTTPSRecord -> Bool
> :: HTTPSRecord -> HTTPSRecord -> Bool
$c> :: HTTPSRecord -> HTTPSRecord -> Bool
<= :: HTTPSRecord -> HTTPSRecord -> Bool
$c<= :: HTTPSRecord -> HTTPSRecord -> Bool
< :: HTTPSRecord -> HTTPSRecord -> Bool
$c< :: HTTPSRecord -> HTTPSRecord -> Bool
compare :: HTTPSRecord -> HTTPSRecord -> Ordering
$ccompare :: HTTPSRecord -> HTTPSRecord -> Ordering
Ord, Int -> HTTPSRecord -> ShowS
[HTTPSRecord] -> ShowS
HTTPSRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HTTPSRecord] -> ShowS
$cshowList :: [HTTPSRecord] -> ShowS
show :: HTTPSRecord -> String
$cshow :: HTTPSRecord -> String
showsPrec :: Int -> HTTPSRecord -> ShowS
$cshowsPrec :: Int -> HTTPSRecord -> ShowS
Show)

instance DNSRecord HTTPSRecord where
  dnsRecordType :: HTTPSRecord -> Text
dnsRecordType HTTPSRecord
_ = Text
"HTTPS"
  dnsRecordToJSON :: HTTPSRecord -> [Pair]
dnsRecordToJSON (HTTPSRecord Word16
priority Text
target Text
value) =
    [
      (Key
"data", [Pair] -> Value
object [
          Key
"priority" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word16
priority
        , Key
"target" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
target
        , Key
"value" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
value
      ])
    ]
  dnsRecordParse :: Object -> Parser HTTPSRecord
dnsRecordParse Object
o = do
    Object
dataObj <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"data"
    Word16
priority <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"priority"
    Text
target <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"target"
    Text
value <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Word16 -> Text -> Text -> HTTPSRecord
HTTPSRecord Word16
priority Text
target Text
value

-- | RFC 1876 LOC record, defined in section 2
data LOCRecord = LOCRecord {
  LOCRecord -> Int32
locRecordAltitude :: Int32 -- ^ Altitude of location in meters from 0e0 to 9e9, from a base of 100,000 meters below the WGS 84 reference spheroid used by GPS
, LOCRecord -> Int
locRecordLatDegrees :: Int -- ^ Degrees of latitude
, LOCRecord -> Text
locRecordLatDirection :: Text -- ^ Direction of latitude (N or S) TODO make this a specific type
, LOCRecord -> Int
locRecordLatMinutes :: Int -- ^ Minutes of latitude
, LOCRecord -> Double
locRecordLatSeconds :: Double -- ^ Seconds of latitude rounded to 3 decimal places
, LOCRecord -> Int
locRecordLongDegrees :: Int -- ^ Degrees of longitude
, LOCRecord -> Text
locRecordLongDirection :: Text -- ^ Direction of longitude (E or W) TODO make this a specific type
, LOCRecord -> Int
locRecordLongMinutes :: Int -- ^ Minutes of longitude
, LOCRecord -> Double
locRecordLongSeconds :: Double -- ^ Seconds of longitude rounded to 3 decimal places
, LOCRecord -> Int
locRecordPrecisionHoriz :: Int -- ^ Horizontal precision of location in meters
, LOCRecord -> Int
locRecordPrecisionVert :: Int -- ^ Vertical precision of location in meters from 0e0 to 9e9
, LOCRecord -> Int
locRecordSize :: Int -- ^ Size of location in meters from 0e0 to 9e9
} deriving (LOCRecord -> LOCRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LOCRecord -> LOCRecord -> Bool
$c/= :: LOCRecord -> LOCRecord -> Bool
== :: LOCRecord -> LOCRecord -> Bool
$c== :: LOCRecord -> LOCRecord -> Bool
Eq, Eq LOCRecord
LOCRecord -> LOCRecord -> Bool
LOCRecord -> LOCRecord -> Ordering
LOCRecord -> LOCRecord -> LOCRecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: LOCRecord -> LOCRecord -> LOCRecord
$cmin :: LOCRecord -> LOCRecord -> LOCRecord
max :: LOCRecord -> LOCRecord -> LOCRecord
$cmax :: LOCRecord -> LOCRecord -> LOCRecord
>= :: LOCRecord -> LOCRecord -> Bool
$c>= :: LOCRecord -> LOCRecord -> Bool
> :: LOCRecord -> LOCRecord -> Bool
$c> :: LOCRecord -> LOCRecord -> Bool
<= :: LOCRecord -> LOCRecord -> Bool
$c<= :: LOCRecord -> LOCRecord -> Bool
< :: LOCRecord -> LOCRecord -> Bool
$c< :: LOCRecord -> LOCRecord -> Bool
compare :: LOCRecord -> LOCRecord -> Ordering
$ccompare :: LOCRecord -> LOCRecord -> Ordering
Ord, Int -> LOCRecord -> ShowS
[LOCRecord] -> ShowS
LOCRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LOCRecord] -> ShowS
$cshowList :: [LOCRecord] -> ShowS
show :: LOCRecord -> String
$cshow :: LOCRecord -> String
showsPrec :: Int -> LOCRecord -> ShowS
$cshowsPrec :: Int -> LOCRecord -> ShowS
Show)

instance DNSRecord LOCRecord where
  dnsRecordType :: LOCRecord -> Text
dnsRecordType LOCRecord
_ = Text
"LOC"
  dnsRecordToJSON :: LOCRecord -> [Pair]
dnsRecordToJSON (LOCRecord Int32
altitude Int
latDegrees Text
latDirection Int
latMinutes Double
latSeconds Int
longDegrees Text
longDirection Int
longMinutes Double
longSeconds Int
precisionHoriz Int
precisionVert Int
size) =
    [
      (Key
"data", [Pair] -> Value
object [
          Key
"altitude" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int32
altitude
        , Key
"lat_degrees" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
latDegrees
        , Key
"lat_direction" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
latDirection
        , Key
"lat_minutes" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
latMinutes
        , Key
"lat_seconds" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Double
latSeconds
        , Key
"long_degrees" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
longDegrees
        , Key
"long_direction" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
longDirection
        , Key
"long_minutes" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
longMinutes
        , Key
"long_seconds" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Double
longSeconds
        , Key
"precision_horz" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
precisionHoriz
        , Key
"precision_vert" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
precisionVert
        , Key
"size" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
size
      ])
    ]
  dnsRecordParse :: Object -> Parser LOCRecord
dnsRecordParse Object
o = do
    Object
dataObj <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"data"
    Int32
altitude <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"altitude"
    Int
latDegrees <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"lat_degrees"
    Text
latDirection <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"lat_direction"
    Int
latMinutes <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"lat_minutes"
    Double
latSeconds <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"lat_seconds"
    Int
longDegrees <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"long_degrees"
    Text
longDirection <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"long_direction"
    Int
longMinutes <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"long_minutes"
    Double
longSeconds <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"long_seconds"
    Int
precisionHoriz <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"precision_horz"
    Int
precisionVert <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"precision_vert"
    Int
size <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"size"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Int32
-> Int
-> Text
-> Int
-> Double
-> Int
-> Text
-> Int
-> Double
-> Int
-> Int
-> Int
-> LOCRecord
LOCRecord Int32
altitude Int
latDegrees Text
latDirection Int
latMinutes Double
latSeconds Int
longDegrees Text
longDirection Int
longMinutes Double
longSeconds Int
precisionHoriz Int
precisionVert Int
size

-- | RFC 1035 MX record, defined in section 3.3.9
data MXRecord = MXRecord {
  MXRecord -> Text
mxRecordContent :: Text -- ^ A domain name to act as a mail exchange
, MXRecord -> Word16
mxRecordPriority :: Word16 -- ^ Priority of the target host, client MUST attempt to contact the target host with the lowest priority it can reach
} deriving (MXRecord -> MXRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MXRecord -> MXRecord -> Bool
$c/= :: MXRecord -> MXRecord -> Bool
== :: MXRecord -> MXRecord -> Bool
$c== :: MXRecord -> MXRecord -> Bool
Eq, Eq MXRecord
MXRecord -> MXRecord -> Bool
MXRecord -> MXRecord -> Ordering
MXRecord -> MXRecord -> MXRecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: MXRecord -> MXRecord -> MXRecord
$cmin :: MXRecord -> MXRecord -> MXRecord
max :: MXRecord -> MXRecord -> MXRecord
$cmax :: MXRecord -> MXRecord -> MXRecord
>= :: MXRecord -> MXRecord -> Bool
$c>= :: MXRecord -> MXRecord -> Bool
> :: MXRecord -> MXRecord -> Bool
$c> :: MXRecord -> MXRecord -> Bool
<= :: MXRecord -> MXRecord -> Bool
$c<= :: MXRecord -> MXRecord -> Bool
< :: MXRecord -> MXRecord -> Bool
$c< :: MXRecord -> MXRecord -> Bool
compare :: MXRecord -> MXRecord -> Ordering
$ccompare :: MXRecord -> MXRecord -> Ordering
Ord, Int -> MXRecord -> ShowS
[MXRecord] -> ShowS
MXRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MXRecord] -> ShowS
$cshowList :: [MXRecord] -> ShowS
show :: MXRecord -> String
$cshow :: MXRecord -> String
showsPrec :: Int -> MXRecord -> ShowS
$cshowsPrec :: Int -> MXRecord -> ShowS
Show)

instance DNSRecord MXRecord where
  dnsRecordType :: MXRecord -> Text
dnsRecordType MXRecord
_ = Text
"MX"
  dnsRecordToJSON :: MXRecord -> [Pair]
dnsRecordToJSON (MXRecord Text
content Word16
priority) =
    [ Key
"content" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
content
    , Key
"priority" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word16
priority
    ]
  dnsRecordParse :: Object -> Parser MXRecord
dnsRecordParse Object
o = do
    Text
content <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"content"
    Word16
priority <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"priority"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> Word16 -> MXRecord
MXRecord Text
content Word16
priority

-- | RFC 3403 NAPTR, Name Authority Pointer record
data NAPTRRecord = NAPTRRecord {
  NAPTRRecord -> Text
naptrRecordFlags :: Text -- ^ Flags to control the rewriting and interpretation of the fields in the record, characters from A-Z and 0-9, defined in section 4.1
, NAPTRRecord -> Word16
naptrRecordOrder :: Word16 -- ^ Order that the records MUST be processed in, defined in section 4.1
, NAPTRRecord -> Word16
naptrRecordPreference :: Word16 -- ^ Preference, equivalent to priority in DDDS, defined in section 4.1
, NAPTRRecord -> Text
naptrRecordRegexp :: Text -- ^ Regexp, substitution expression that is applied to the original string, defined in section 4.1
, NAPTRRecord -> Text
naptrRecordReplacement :: Text -- ^ Replacement, MUST be a fully qualified domain name, defined in section 4.1
, NAPTRRecord -> Text
naptrRecordService :: Text -- ^ Service parameters applicable to this delegation path, defined in section 4.1
} deriving (NAPTRRecord -> NAPTRRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NAPTRRecord -> NAPTRRecord -> Bool
$c/= :: NAPTRRecord -> NAPTRRecord -> Bool
== :: NAPTRRecord -> NAPTRRecord -> Bool
$c== :: NAPTRRecord -> NAPTRRecord -> Bool
Eq, Eq NAPTRRecord
NAPTRRecord -> NAPTRRecord -> Bool
NAPTRRecord -> NAPTRRecord -> Ordering
NAPTRRecord -> NAPTRRecord -> NAPTRRecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: NAPTRRecord -> NAPTRRecord -> NAPTRRecord
$cmin :: NAPTRRecord -> NAPTRRecord -> NAPTRRecord
max :: NAPTRRecord -> NAPTRRecord -> NAPTRRecord
$cmax :: NAPTRRecord -> NAPTRRecord -> NAPTRRecord
>= :: NAPTRRecord -> NAPTRRecord -> Bool
$c>= :: NAPTRRecord -> NAPTRRecord -> Bool
> :: NAPTRRecord -> NAPTRRecord -> Bool
$c> :: NAPTRRecord -> NAPTRRecord -> Bool
<= :: NAPTRRecord -> NAPTRRecord -> Bool
$c<= :: NAPTRRecord -> NAPTRRecord -> Bool
< :: NAPTRRecord -> NAPTRRecord -> Bool
$c< :: NAPTRRecord -> NAPTRRecord -> Bool
compare :: NAPTRRecord -> NAPTRRecord -> Ordering
$ccompare :: NAPTRRecord -> NAPTRRecord -> Ordering
Ord, Int -> NAPTRRecord -> ShowS
[NAPTRRecord] -> ShowS
NAPTRRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NAPTRRecord] -> ShowS
$cshowList :: [NAPTRRecord] -> ShowS
show :: NAPTRRecord -> String
$cshow :: NAPTRRecord -> String
showsPrec :: Int -> NAPTRRecord -> ShowS
$cshowsPrec :: Int -> NAPTRRecord -> ShowS
Show)

instance DNSRecord NAPTRRecord where
  dnsRecordType :: NAPTRRecord -> Text
dnsRecordType NAPTRRecord
_ = Text
"NAPTR"
  dnsRecordToJSON :: NAPTRRecord -> [Pair]
dnsRecordToJSON (NAPTRRecord Text
flags Word16
order Word16
preference Text
regexp Text
replacement Text
service) =
    [
      (Key
"data", [Pair] -> Value
object [
          Key
"flags" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
flags
        , Key
"order" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word16
order
        , Key
"preference" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word16
preference
        , Key
"regexp" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
regexp
        , Key
"replacement" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
replacement
        , Key
"service" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
service
      ])
    ]
  dnsRecordParse :: Object -> Parser NAPTRRecord
dnsRecordParse Object
o = do
    Object
dataObj <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"data"
    Text
flags <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"flags"
    Word16
order <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"order"
    Word16
preference <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"preference"
    Text
regexp <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"regexp"
    Text
replacement <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"replacement"
    Text
service <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"service"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> Word16 -> Word16 -> Text -> Text -> Text -> NAPTRRecord
NAPTRRecord Text
flags Word16
order Word16
preference Text
regexp Text
replacement Text
service

-- | RFC 1035 NS, name server record defined in section 3.3.11
data NSRecord = NSRecord {
  NSRecord -> Text
nsRecordContent :: Text -- ^ A domain name to act as a name server
} deriving (NSRecord -> NSRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NSRecord -> NSRecord -> Bool
$c/= :: NSRecord -> NSRecord -> Bool
== :: NSRecord -> NSRecord -> Bool
$c== :: NSRecord -> NSRecord -> Bool
Eq, Eq NSRecord
NSRecord -> NSRecord -> Bool
NSRecord -> NSRecord -> Ordering
NSRecord -> NSRecord -> NSRecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: NSRecord -> NSRecord -> NSRecord
$cmin :: NSRecord -> NSRecord -> NSRecord
max :: NSRecord -> NSRecord -> NSRecord
$cmax :: NSRecord -> NSRecord -> NSRecord
>= :: NSRecord -> NSRecord -> Bool
$c>= :: NSRecord -> NSRecord -> Bool
> :: NSRecord -> NSRecord -> Bool
$c> :: NSRecord -> NSRecord -> Bool
<= :: NSRecord -> NSRecord -> Bool
$c<= :: NSRecord -> NSRecord -> Bool
< :: NSRecord -> NSRecord -> Bool
$c< :: NSRecord -> NSRecord -> Bool
compare :: NSRecord -> NSRecord -> Ordering
$ccompare :: NSRecord -> NSRecord -> Ordering
Ord, Int -> NSRecord -> ShowS
[NSRecord] -> ShowS
NSRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NSRecord] -> ShowS
$cshowList :: [NSRecord] -> ShowS
show :: NSRecord -> String
$cshow :: NSRecord -> String
showsPrec :: Int -> NSRecord -> ShowS
$cshowsPrec :: Int -> NSRecord -> ShowS
Show)

instance DNSRecord NSRecord where
  dnsRecordType :: NSRecord -> Text
dnsRecordType NSRecord
_ = Text
"NS"
  dnsRecordToJSON :: NSRecord -> [Pair]
dnsRecordToJSON (NSRecord Text
content) =
    [ Key
"content" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
content
    ]
  dnsRecordParse :: Object -> Parser NSRecord
dnsRecordParse Object
o = do
    Text
content <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"content"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> NSRecord
NSRecord Text
content

-- | RFC 1035 PTR, pointer record defined in section 3.3.12
data PTRRecord = PTRRecord {
  PTRRecord -> Text
ptrRecordContent :: Text -- ^ A valid PTR target host name
} deriving (PTRRecord -> PTRRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PTRRecord -> PTRRecord -> Bool
$c/= :: PTRRecord -> PTRRecord -> Bool
== :: PTRRecord -> PTRRecord -> Bool
$c== :: PTRRecord -> PTRRecord -> Bool
Eq, Eq PTRRecord
PTRRecord -> PTRRecord -> Bool
PTRRecord -> PTRRecord -> Ordering
PTRRecord -> PTRRecord -> PTRRecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: PTRRecord -> PTRRecord -> PTRRecord
$cmin :: PTRRecord -> PTRRecord -> PTRRecord
max :: PTRRecord -> PTRRecord -> PTRRecord
$cmax :: PTRRecord -> PTRRecord -> PTRRecord
>= :: PTRRecord -> PTRRecord -> Bool
$c>= :: PTRRecord -> PTRRecord -> Bool
> :: PTRRecord -> PTRRecord -> Bool
$c> :: PTRRecord -> PTRRecord -> Bool
<= :: PTRRecord -> PTRRecord -> Bool
$c<= :: PTRRecord -> PTRRecord -> Bool
< :: PTRRecord -> PTRRecord -> Bool
$c< :: PTRRecord -> PTRRecord -> Bool
compare :: PTRRecord -> PTRRecord -> Ordering
$ccompare :: PTRRecord -> PTRRecord -> Ordering
Ord, Int -> PTRRecord -> ShowS
[PTRRecord] -> ShowS
PTRRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PTRRecord] -> ShowS
$cshowList :: [PTRRecord] -> ShowS
show :: PTRRecord -> String
$cshow :: PTRRecord -> String
showsPrec :: Int -> PTRRecord -> ShowS
$cshowsPrec :: Int -> PTRRecord -> ShowS
Show)

instance DNSRecord PTRRecord where
  dnsRecordType :: PTRRecord -> Text
dnsRecordType PTRRecord
_ = Text
"PTR"
  dnsRecordToJSON :: PTRRecord -> [Pair]
dnsRecordToJSON (PTRRecord Text
content) =
    [ Key
"content" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
content
    ]
  dnsRecordParse :: Object -> Parser PTRRecord
dnsRecordParse Object
o = do
    Text
content <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"content"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> PTRRecord
PTRRecord Text
content

-- | RFC 8162 SMIMEA record
data SMIMEARecord = SMIMEARecord {
  SMIMEARecord -> Text
smimeaRecordCertificate :: Text -- ^ Certificate
, SMIMEARecord -> Int
smimeaMathingType :: Int -- ^ Matching type
, SMIMEARecord -> Int
smimeaRecordSelector :: Int -- ^ Selector
, SMIMEARecord -> Int
smimeaRecordUsage :: Int -- ^ Usage
} deriving (SMIMEARecord -> SMIMEARecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SMIMEARecord -> SMIMEARecord -> Bool
$c/= :: SMIMEARecord -> SMIMEARecord -> Bool
== :: SMIMEARecord -> SMIMEARecord -> Bool
$c== :: SMIMEARecord -> SMIMEARecord -> Bool
Eq, Eq SMIMEARecord
SMIMEARecord -> SMIMEARecord -> Bool
SMIMEARecord -> SMIMEARecord -> Ordering
SMIMEARecord -> SMIMEARecord -> SMIMEARecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: SMIMEARecord -> SMIMEARecord -> SMIMEARecord
$cmin :: SMIMEARecord -> SMIMEARecord -> SMIMEARecord
max :: SMIMEARecord -> SMIMEARecord -> SMIMEARecord
$cmax :: SMIMEARecord -> SMIMEARecord -> SMIMEARecord
>= :: SMIMEARecord -> SMIMEARecord -> Bool
$c>= :: SMIMEARecord -> SMIMEARecord -> Bool
> :: SMIMEARecord -> SMIMEARecord -> Bool
$c> :: SMIMEARecord -> SMIMEARecord -> Bool
<= :: SMIMEARecord -> SMIMEARecord -> Bool
$c<= :: SMIMEARecord -> SMIMEARecord -> Bool
< :: SMIMEARecord -> SMIMEARecord -> Bool
$c< :: SMIMEARecord -> SMIMEARecord -> Bool
compare :: SMIMEARecord -> SMIMEARecord -> Ordering
$ccompare :: SMIMEARecord -> SMIMEARecord -> Ordering
Ord, Int -> SMIMEARecord -> ShowS
[SMIMEARecord] -> ShowS
SMIMEARecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SMIMEARecord] -> ShowS
$cshowList :: [SMIMEARecord] -> ShowS
show :: SMIMEARecord -> String
$cshow :: SMIMEARecord -> String
showsPrec :: Int -> SMIMEARecord -> ShowS
$cshowsPrec :: Int -> SMIMEARecord -> ShowS
Show)

instance DNSRecord SMIMEARecord where
  dnsRecordType :: SMIMEARecord -> Text
dnsRecordType SMIMEARecord
_ = Text
"SMIMEA"
  dnsRecordToJSON :: SMIMEARecord -> [Pair]
dnsRecordToJSON (SMIMEARecord Text
certificate Int
matchingType Int
selector Int
usage) =
    [
      (Key
"data", [Pair] -> Value
object [
          Key
"certificate" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
certificate
        , Key
"matching_type" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
matchingType
        , Key
"selector" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
selector
        , Key
"usage" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
usage
      ])
    ]
  dnsRecordParse :: Object -> Parser SMIMEARecord
dnsRecordParse Object
o = do
    Object
dataObj <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"data"
    Text
certificate <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"certificate"
    Int
matchingType <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"matching_type"
    Int
selector <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"selector"
    Int
usage <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"usage"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> Int -> Int -> Int -> SMIMEARecord
SMIMEARecord Text
certificate Int
matchingType Int
selector Int
usage

-- | RFC 2782 SRV, service record
data SRVRecord = SRVRecord {
  SRVRecord -> Text
srvRecordName :: Text -- ^ Domain name of the service
, SRVRecord -> Word16
srvRecordPort :: Word16 -- ^ The port of the service
, SRVRecord -> Word16
srvRecordPriority :: Word16 -- ^ The priority of the target host, client MUST attempt to contact the target host with the lowest priority it can reach
, SRVRecord -> Text
srvRecordProto :: Text -- ^ Name of the protocol for the service, prepended with an underscore ('_TCP', '_UDP')
, SRVRecord -> Text
srvRecordService :: Text -- ^ A service type, prefixed with an underscore (Example '_SIP'), defined in RFC 1700 or locally 
, SRVRecord -> Text
srvRecordTarget :: Text -- ^ Domain name of the target host, there can not be an alias
, SRVRecord -> Word16
srvRecordWeight :: Word16 -- ^ Relative weight for records with the same priority, higher value means higher chance of being selected
} deriving (SRVRecord -> SRVRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SRVRecord -> SRVRecord -> Bool
$c/= :: SRVRecord -> SRVRecord -> Bool
== :: SRVRecord -> SRVRecord -> Bool
$c== :: SRVRecord -> SRVRecord -> Bool
Eq, Eq SRVRecord
SRVRecord -> SRVRecord -> Bool
SRVRecord -> SRVRecord -> Ordering
SRVRecord -> SRVRecord -> SRVRecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: SRVRecord -> SRVRecord -> SRVRecord
$cmin :: SRVRecord -> SRVRecord -> SRVRecord
max :: SRVRecord -> SRVRecord -> SRVRecord
$cmax :: SRVRecord -> SRVRecord -> SRVRecord
>= :: SRVRecord -> SRVRecord -> Bool
$c>= :: SRVRecord -> SRVRecord -> Bool
> :: SRVRecord -> SRVRecord -> Bool
$c> :: SRVRecord -> SRVRecord -> Bool
<= :: SRVRecord -> SRVRecord -> Bool
$c<= :: SRVRecord -> SRVRecord -> Bool
< :: SRVRecord -> SRVRecord -> Bool
$c< :: SRVRecord -> SRVRecord -> Bool
compare :: SRVRecord -> SRVRecord -> Ordering
$ccompare :: SRVRecord -> SRVRecord -> Ordering
Ord, Int -> SRVRecord -> ShowS
[SRVRecord] -> ShowS
SRVRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SRVRecord] -> ShowS
$cshowList :: [SRVRecord] -> ShowS
show :: SRVRecord -> String
$cshow :: SRVRecord -> String
showsPrec :: Int -> SRVRecord -> ShowS
$cshowsPrec :: Int -> SRVRecord -> ShowS
Show)

instance DNSRecord SRVRecord where
  dnsRecordType :: SRVRecord -> Text
dnsRecordType SRVRecord
_ = Text
"SRV"
  dnsRecordToJSON :: SRVRecord -> [Pair]
dnsRecordToJSON (SRVRecord Text
name Word16
port Word16
priority Text
proto Text
service Text
target Word16
weight) =
    [
      (Key
"data", [Pair] -> Value
object [
          Key
"name" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
name
        , Key
"port" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word16
port
        , Key
"priority" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word16
priority
        , Key
"proto" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
proto
        , Key
"service" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
service
        , Key
"target" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
target
        , Key
"weight" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word16
weight
      ])
    ]
  dnsRecordParse :: Object -> Parser SRVRecord
dnsRecordParse Object
o = do
    Object
dataObj <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"data"
    Text
name <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
    Word16
port <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"port"
    Word16
priority <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"priority"
    Text
proto <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"proto"
    Text
service <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"service"
    Text
target <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"target"
    Word16
weight <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"weight"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text
-> Word16 -> Word16 -> Text -> Text -> Text -> Word16 -> SRVRecord
SRVRecord Text
name Word16
port Word16
priority Text
proto Text
service Text
target Word16
weight

-- | RFC 4255 SSHFP record
data SSHFPRecord = SSHFPRecord {
  SSHFPRecord -> Int
sshfpRecordAlgorithm :: Int -- ^ Algorithm
, SSHFPRecord -> Text
sshfpRecordFingerprint :: Text -- ^ Fingerprint
, SSHFPRecord -> Int
sshfpRecordType :: Int -- ^ Type
} deriving (SSHFPRecord -> SSHFPRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SSHFPRecord -> SSHFPRecord -> Bool
$c/= :: SSHFPRecord -> SSHFPRecord -> Bool
== :: SSHFPRecord -> SSHFPRecord -> Bool
$c== :: SSHFPRecord -> SSHFPRecord -> Bool
Eq, Eq SSHFPRecord
SSHFPRecord -> SSHFPRecord -> Bool
SSHFPRecord -> SSHFPRecord -> Ordering
SSHFPRecord -> SSHFPRecord -> SSHFPRecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: SSHFPRecord -> SSHFPRecord -> SSHFPRecord
$cmin :: SSHFPRecord -> SSHFPRecord -> SSHFPRecord
max :: SSHFPRecord -> SSHFPRecord -> SSHFPRecord
$cmax :: SSHFPRecord -> SSHFPRecord -> SSHFPRecord
>= :: SSHFPRecord -> SSHFPRecord -> Bool
$c>= :: SSHFPRecord -> SSHFPRecord -> Bool
> :: SSHFPRecord -> SSHFPRecord -> Bool
$c> :: SSHFPRecord -> SSHFPRecord -> Bool
<= :: SSHFPRecord -> SSHFPRecord -> Bool
$c<= :: SSHFPRecord -> SSHFPRecord -> Bool
< :: SSHFPRecord -> SSHFPRecord -> Bool
$c< :: SSHFPRecord -> SSHFPRecord -> Bool
compare :: SSHFPRecord -> SSHFPRecord -> Ordering
$ccompare :: SSHFPRecord -> SSHFPRecord -> Ordering
Ord, Int -> SSHFPRecord -> ShowS
[SSHFPRecord] -> ShowS
SSHFPRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SSHFPRecord] -> ShowS
$cshowList :: [SSHFPRecord] -> ShowS
show :: SSHFPRecord -> String
$cshow :: SSHFPRecord -> String
showsPrec :: Int -> SSHFPRecord -> ShowS
$cshowsPrec :: Int -> SSHFPRecord -> ShowS
Show)

instance DNSRecord SSHFPRecord where
  dnsRecordType :: SSHFPRecord -> Text
dnsRecordType SSHFPRecord
_ = Text
"SSHFP"
  dnsRecordToJSON :: SSHFPRecord -> [Pair]
dnsRecordToJSON (SSHFPRecord Int
algorithm Text
fingerprint Int
type') =
    [
      (Key
"data", [Pair] -> Value
object [
          Key
"algorithm" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
algorithm
        , Key
"fingerprint" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
fingerprint
        , Key
"type" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
type'
      ])
    ]
  dnsRecordParse :: Object -> Parser SSHFPRecord
dnsRecordParse Object
o = do
    Object
dataObj <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"data"
    Int
algorithm <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"algorithm"
    Text
fingerprint <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"fingerprint"
    Int
type' <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Int -> Text -> Int -> SSHFPRecord
SSHFPRecord Int
algorithm Text
fingerprint Int
type'

-- | draft-ietf-dnsop-svcb-https-12 SVCB record
data SVCBRecord = SVCBRecord {
  SVCBRecord -> Int
svcBRecordPriority :: Int -- ^ Priority
, SVCBRecord -> Text
svcBRecordTarget :: Text -- ^ Target
, SVCBRecord -> Text
svcBRecordValue :: Text -- ^ Value (Example 'alpn="h3,h2" ipv4hint="127.0.0.1" ipv6hint="::1"')
} deriving (SVCBRecord -> SVCBRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SVCBRecord -> SVCBRecord -> Bool
$c/= :: SVCBRecord -> SVCBRecord -> Bool
== :: SVCBRecord -> SVCBRecord -> Bool
$c== :: SVCBRecord -> SVCBRecord -> Bool
Eq, Eq SVCBRecord
SVCBRecord -> SVCBRecord -> Bool
SVCBRecord -> SVCBRecord -> Ordering
SVCBRecord -> SVCBRecord -> SVCBRecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: SVCBRecord -> SVCBRecord -> SVCBRecord
$cmin :: SVCBRecord -> SVCBRecord -> SVCBRecord
max :: SVCBRecord -> SVCBRecord -> SVCBRecord
$cmax :: SVCBRecord -> SVCBRecord -> SVCBRecord
>= :: SVCBRecord -> SVCBRecord -> Bool
$c>= :: SVCBRecord -> SVCBRecord -> Bool
> :: SVCBRecord -> SVCBRecord -> Bool
$c> :: SVCBRecord -> SVCBRecord -> Bool
<= :: SVCBRecord -> SVCBRecord -> Bool
$c<= :: SVCBRecord -> SVCBRecord -> Bool
< :: SVCBRecord -> SVCBRecord -> Bool
$c< :: SVCBRecord -> SVCBRecord -> Bool
compare :: SVCBRecord -> SVCBRecord -> Ordering
$ccompare :: SVCBRecord -> SVCBRecord -> Ordering
Ord, Int -> SVCBRecord -> ShowS
[SVCBRecord] -> ShowS
SVCBRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SVCBRecord] -> ShowS
$cshowList :: [SVCBRecord] -> ShowS
show :: SVCBRecord -> String
$cshow :: SVCBRecord -> String
showsPrec :: Int -> SVCBRecord -> ShowS
$cshowsPrec :: Int -> SVCBRecord -> ShowS
Show)

instance DNSRecord SVCBRecord where
  dnsRecordType :: SVCBRecord -> Text
dnsRecordType SVCBRecord
_ = Text
"SVCB"
  dnsRecordToJSON :: SVCBRecord -> [Pair]
dnsRecordToJSON (SVCBRecord Int
priority Text
target Text
value) =
    [
      (Key
"data", [Pair] -> Value
object [
          Key
"priority" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
priority
        , Key
"target" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
target
        , Key
"value" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
value
      ])
    ]
  dnsRecordParse :: Object -> Parser SVCBRecord
dnsRecordParse Object
o = do
    Object
dataObj <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"data"
    Int
priority <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"priority"
    Text
target <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"target"
    Text
value <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Int -> Text -> Text -> SVCBRecord
SVCBRecord Int
priority Text
target Text
value

-- | RFC 6698 TLSA record, defined in section 2
data TLSARecord = TLSARecord {
  TLSARecord -> Text
tlsaRecordCertificate :: Text -- ^ Certificate, either raw data (full certificate or
                                -- SubjectPublicKeyInfo based on the selector) for matching
                                -- type 0, or the hash of the raw certificate data for types 1
                                -- and 2. The hash is in binary form, not hex-encoded.
                                -- Defined in section 2.1.4
, TLSARecord -> Word8
tlsaRecordMatchingType :: Word8 -- ^ Matching type specifies how the certificate association is presented, defined in section 2.1.3
, TLSARecord -> Word8
tlsaRecordSelector :: Word8 -- ^ Selector the part of the TLS certificate to match against, defined in section 2.1.2
, TLSARecord -> Word8
tlsaRecordUsage :: Word8 -- ^ Usage of the certificate, defined in section 2.1.1 
} deriving (TLSARecord -> TLSARecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TLSARecord -> TLSARecord -> Bool
$c/= :: TLSARecord -> TLSARecord -> Bool
== :: TLSARecord -> TLSARecord -> Bool
$c== :: TLSARecord -> TLSARecord -> Bool
Eq, Eq TLSARecord
TLSARecord -> TLSARecord -> Bool
TLSARecord -> TLSARecord -> Ordering
TLSARecord -> TLSARecord -> TLSARecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TLSARecord -> TLSARecord -> TLSARecord
$cmin :: TLSARecord -> TLSARecord -> TLSARecord
max :: TLSARecord -> TLSARecord -> TLSARecord
$cmax :: TLSARecord -> TLSARecord -> TLSARecord
>= :: TLSARecord -> TLSARecord -> Bool
$c>= :: TLSARecord -> TLSARecord -> Bool
> :: TLSARecord -> TLSARecord -> Bool
$c> :: TLSARecord -> TLSARecord -> Bool
<= :: TLSARecord -> TLSARecord -> Bool
$c<= :: TLSARecord -> TLSARecord -> Bool
< :: TLSARecord -> TLSARecord -> Bool
$c< :: TLSARecord -> TLSARecord -> Bool
compare :: TLSARecord -> TLSARecord -> Ordering
$ccompare :: TLSARecord -> TLSARecord -> Ordering
Ord, Int -> TLSARecord -> ShowS
[TLSARecord] -> ShowS
TLSARecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TLSARecord] -> ShowS
$cshowList :: [TLSARecord] -> ShowS
show :: TLSARecord -> String
$cshow :: TLSARecord -> String
showsPrec :: Int -> TLSARecord -> ShowS
$cshowsPrec :: Int -> TLSARecord -> ShowS
Show)

instance DNSRecord TLSARecord where
  dnsRecordType :: TLSARecord -> Text
dnsRecordType TLSARecord
_ = Text
"TLSA"
  dnsRecordToJSON :: TLSARecord -> [Pair]
dnsRecordToJSON (TLSARecord Text
certificate Word8
matchingType Word8
selector Word8
usage) =
    [
      (Key
"data", [Pair] -> Value
object [
          Key
"certificate" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
certificate
        , Key
"matching_type" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word8
matchingType
        , Key
"selector" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word8
selector
        , Key
"usage" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word8
usage
      ])
    ]
  dnsRecordParse :: Object -> Parser TLSARecord
dnsRecordParse Object
o = do
    Object
dataObj <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"data"
    Text
certificate <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"certificate"
    Word8
matchingType <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"matching_type"
    Word8
selector <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"selector"
    Word8
usage <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"usage"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> Word8 -> Word8 -> Word8 -> TLSARecord
TLSARecord Text
certificate Word8
matchingType Word8
selector Word8
usage

-- | RFC 1035 TXT record, defined in section 3.3.14
data TXTRecord = TXTRecord {
  TXTRecord -> Text
txtRecordContent :: Text -- ^ Text content of the record
} deriving (TXTRecord -> TXTRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TXTRecord -> TXTRecord -> Bool
$c/= :: TXTRecord -> TXTRecord -> Bool
== :: TXTRecord -> TXTRecord -> Bool
$c== :: TXTRecord -> TXTRecord -> Bool
Eq, Eq TXTRecord
TXTRecord -> TXTRecord -> Bool
TXTRecord -> TXTRecord -> Ordering
TXTRecord -> TXTRecord -> TXTRecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TXTRecord -> TXTRecord -> TXTRecord
$cmin :: TXTRecord -> TXTRecord -> TXTRecord
max :: TXTRecord -> TXTRecord -> TXTRecord
$cmax :: TXTRecord -> TXTRecord -> TXTRecord
>= :: TXTRecord -> TXTRecord -> Bool
$c>= :: TXTRecord -> TXTRecord -> Bool
> :: TXTRecord -> TXTRecord -> Bool
$c> :: TXTRecord -> TXTRecord -> Bool
<= :: TXTRecord -> TXTRecord -> Bool
$c<= :: TXTRecord -> TXTRecord -> Bool
< :: TXTRecord -> TXTRecord -> Bool
$c< :: TXTRecord -> TXTRecord -> Bool
compare :: TXTRecord -> TXTRecord -> Ordering
$ccompare :: TXTRecord -> TXTRecord -> Ordering
Ord, Int -> TXTRecord -> ShowS
[TXTRecord] -> ShowS
TXTRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TXTRecord] -> ShowS
$cshowList :: [TXTRecord] -> ShowS
show :: TXTRecord -> String
$cshow :: TXTRecord -> String
showsPrec :: Int -> TXTRecord -> ShowS
$cshowsPrec :: Int -> TXTRecord -> ShowS
Show)

instance DNSRecord TXTRecord where
  dnsRecordType :: TXTRecord -> Text
dnsRecordType TXTRecord
_ = Text
"TXT"
  dnsRecordToJSON :: TXTRecord -> [Pair]
dnsRecordToJSON (TXTRecord Text
content) =
    [ Key
"content" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
content
    ]
  dnsRecordParse :: Object -> Parser TXTRecord
dnsRecordParse Object
o = do
    Text
content <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"content"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> TXTRecord
TXTRecord Text
content

-- | RFC 7553 URI record
data URIRecord = URIRecord {
  URIRecord -> Text
uriRecordContent :: Text -- ^ URI content, defined in section 2
, URIRecord -> Word16
uriRecordPriority :: Word16 -- ^ Priority, lower value means higher chance of being selected
} deriving (URIRecord -> URIRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: URIRecord -> URIRecord -> Bool
$c/= :: URIRecord -> URIRecord -> Bool
== :: URIRecord -> URIRecord -> Bool
$c== :: URIRecord -> URIRecord -> Bool
Eq, Eq URIRecord
URIRecord -> URIRecord -> Bool
URIRecord -> URIRecord -> Ordering
URIRecord -> URIRecord -> URIRecord
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: URIRecord -> URIRecord -> URIRecord
$cmin :: URIRecord -> URIRecord -> URIRecord
max :: URIRecord -> URIRecord -> URIRecord
$cmax :: URIRecord -> URIRecord -> URIRecord
>= :: URIRecord -> URIRecord -> Bool
$c>= :: URIRecord -> URIRecord -> Bool
> :: URIRecord -> URIRecord -> Bool
$c> :: URIRecord -> URIRecord -> Bool
<= :: URIRecord -> URIRecord -> Bool
$c<= :: URIRecord -> URIRecord -> Bool
< :: URIRecord -> URIRecord -> Bool
$c< :: URIRecord -> URIRecord -> Bool
compare :: URIRecord -> URIRecord -> Ordering
$ccompare :: URIRecord -> URIRecord -> Ordering
Ord, Int -> URIRecord -> ShowS
[URIRecord] -> ShowS
URIRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [URIRecord] -> ShowS
$cshowList :: [URIRecord] -> ShowS
show :: URIRecord -> String
$cshow :: URIRecord -> String
showsPrec :: Int -> URIRecord -> ShowS
$cshowsPrec :: Int -> URIRecord -> ShowS
Show)

instance DNSRecord URIRecord where
  dnsRecordType :: URIRecord -> Text
dnsRecordType URIRecord
_ = Text
"URI"
  dnsRecordToJSON :: URIRecord -> [Pair]
dnsRecordToJSON (URIRecord Text
content Word16
priority) =
    [
      (Key
"data", [Pair] -> Value
object [
          Key
"content" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
content
        , Key
"priority" forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word16
priority
      ])
    ]
  dnsRecordParse :: Object -> Parser URIRecord
dnsRecordParse Object
o = do
    Object
dataObj <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"data"
    Text
content <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"content"
    Word16
priority <- Object
dataObj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"priority"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> Word16 -> URIRecord
URIRecord Text
content Word16
priority