-- |
-- Module: PowerDNS.API.Cryptokeys
-- Description: Cryptokeys endpoints for PowerDNS API
--
-- This module implements the endpoints described at [Cryptokeys API](https://doc.powerdns.com/authoritative/http-api/cryptokey.html)

{-# LANGUAGE DataKinds          #-}
{-# LANGUAGE DeriveAnyClass     #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE TypeOperators      #-}
module PowerDNS.API.Cryptokeys
  (
  -- * API
    CryptokeysAPI(..)

  -- * Data types
  , Cryptokey(..)
  )
where

import           Data.Data (Data)

import           Control.DeepSeq (NFData)
import           Data.Aeson (FromJSON(..), ToJSON(..), defaultOptions,
                             fieldLabelModifier, genericParseJSON,
                             genericToJSON)
import qualified Data.Text as T
import           Servant.API
import           Servant.API.Generic

import           PowerDNS.Internal.Utils (Empty(..), strip)

data CryptokeysAPI f = CryptokeysAPI
    { CryptokeysAPI f
-> f
   :- ("servers"
       :> (Capture "server_id" Text
           :> ("zones"
               :> (Capture "zone_id" Text
                   :> ("cryptokeys" :> Get '[JSON] [Cryptokey])))))
apiListCryptokeys :: f  :- "servers" :> Capture "server_id" T.Text :> "zones" :> Capture "zone_id" T.Text :> "cryptokeys"
                              :> Get '[JSON] [Cryptokey]

    , CryptokeysAPI f
-> f
   :- ("servers"
       :> (Capture "server_id" Text
           :> ("zones"
               :> (Capture "zone_id" Text
                   :> ("cryptokeys"
                       :> (ReqBody '[JSON] Cryptokey
                           :> PostCreated '[JSON] Cryptokey))))))
apiCreateCryptokey :: f :- "servers" :> Capture "server_id" T.Text :> "zones" :> Capture "zone_id" T.Text :> "cryptokeys"
                              :> ReqBody '[JSON] Cryptokey
                              :> PostCreated '[JSON] Cryptokey

    , CryptokeysAPI f
-> f
   :- ("servers"
       :> (Capture "server_id" Text
           :> ("zones"
               :> (Capture "zone_id" Text
                   :> ("cryptokeys"
                       :> (Capture "cryptokey_id" Text :> Get '[JSON] Cryptokey))))))
apiGetCryptokey :: f    :- "servers" :> Capture "server_id" T.Text :> "zones" :> Capture "zone_id" T.Text :> "cryptokeys" :> Capture "cryptokey_id" T.Text
                              :> Get '[JSON] Cryptokey

    , CryptokeysAPI f
-> f
   :- ("servers"
       :> (Capture "server_id" Text
           :> ("zones"
               :> (Capture "zone_id" Text
                   :> ("cryptokeys"
                       :> (Capture "cryptokey_id" Text
                           :> (ReqBody '[JSON] Cryptokey :> PutNoContent)))))))
apiUpdateCryptokey :: f :- "servers" :> Capture "server_id" T.Text :> "zones" :> Capture "zone_id" T.Text :> "cryptokeys" :> Capture "cryptokey_id" T.Text
                              :> ReqBody '[JSON] Cryptokey
                              :> PutNoContent

    , CryptokeysAPI f
-> f
   :- ("servers"
       :> (Capture "server_id" Text
           :> ("zones"
               :> (Capture "zone_id" Text
                   :> ("cryptokeys"
                       :> (Capture "cryptokey_id" Text :> DeleteNoContent))))))
apiDeleteCryptokey :: f :- "servers" :> Capture "server_id" T.Text :> "zones" :> Capture "zone_id" T.Text :> "cryptokeys" :> Capture "cryptokey_id" T.Text
                              :> DeleteNoContent

    } deriving (forall x. CryptokeysAPI f -> Rep (CryptokeysAPI f) x)
-> (forall x. Rep (CryptokeysAPI f) x -> CryptokeysAPI f)
-> Generic (CryptokeysAPI f)
forall x. Rep (CryptokeysAPI f) x -> CryptokeysAPI f
forall x. CryptokeysAPI f -> Rep (CryptokeysAPI f) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall f x. Rep (CryptokeysAPI f) x -> CryptokeysAPI f
forall f x. CryptokeysAPI f -> Rep (CryptokeysAPI f) x
$cto :: forall f x. Rep (CryptokeysAPI f) x -> CryptokeysAPI f
$cfrom :: forall f x. CryptokeysAPI f -> Rep (CryptokeysAPI f) x
Generic

----------------------------------------------------------------------------------------

data Cryptokey = Cryptokey
    { Cryptokey -> Maybe Text
ck_type :: Maybe T.Text
    , Cryptokey -> Maybe Integer
ck_id :: Maybe Integer
    , Cryptokey -> Maybe Text
ck_keytype :: Maybe T.Text
    , Cryptokey -> Maybe Bool
ck_active :: Maybe Bool
    , Cryptokey -> Maybe Bool
ck_published :: Maybe Bool
    , Cryptokey -> Maybe Text
ck_dnskey :: Maybe T.Text
    , Cryptokey -> Maybe [Text]
ck_ds :: Maybe [T.Text]
    , Cryptokey -> Maybe Text
ck_privatekey :: Maybe T.Text
    , Cryptokey -> Maybe Text
ck_algorithm :: Maybe T.Text
    , Cryptokey -> Maybe Integer
ck_bits :: Maybe Integer
    } deriving (Cryptokey -> Cryptokey -> Bool
(Cryptokey -> Cryptokey -> Bool)
-> (Cryptokey -> Cryptokey -> Bool) -> Eq Cryptokey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Cryptokey -> Cryptokey -> Bool
$c/= :: Cryptokey -> Cryptokey -> Bool
== :: Cryptokey -> Cryptokey -> Bool
$c== :: Cryptokey -> Cryptokey -> Bool
Eq, Eq Cryptokey
Eq Cryptokey
-> (Cryptokey -> Cryptokey -> Ordering)
-> (Cryptokey -> Cryptokey -> Bool)
-> (Cryptokey -> Cryptokey -> Bool)
-> (Cryptokey -> Cryptokey -> Bool)
-> (Cryptokey -> Cryptokey -> Bool)
-> (Cryptokey -> Cryptokey -> Cryptokey)
-> (Cryptokey -> Cryptokey -> Cryptokey)
-> Ord Cryptokey
Cryptokey -> Cryptokey -> Bool
Cryptokey -> Cryptokey -> Ordering
Cryptokey -> Cryptokey -> Cryptokey
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 :: Cryptokey -> Cryptokey -> Cryptokey
$cmin :: Cryptokey -> Cryptokey -> Cryptokey
max :: Cryptokey -> Cryptokey -> Cryptokey
$cmax :: Cryptokey -> Cryptokey -> Cryptokey
>= :: Cryptokey -> Cryptokey -> Bool
$c>= :: Cryptokey -> Cryptokey -> Bool
> :: Cryptokey -> Cryptokey -> Bool
$c> :: Cryptokey -> Cryptokey -> Bool
<= :: Cryptokey -> Cryptokey -> Bool
$c<= :: Cryptokey -> Cryptokey -> Bool
< :: Cryptokey -> Cryptokey -> Bool
$c< :: Cryptokey -> Cryptokey -> Bool
compare :: Cryptokey -> Cryptokey -> Ordering
$ccompare :: Cryptokey -> Cryptokey -> Ordering
$cp1Ord :: Eq Cryptokey
Ord, Int -> Cryptokey -> ShowS
[Cryptokey] -> ShowS
Cryptokey -> String
(Int -> Cryptokey -> ShowS)
-> (Cryptokey -> String)
-> ([Cryptokey] -> ShowS)
-> Show Cryptokey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Cryptokey] -> ShowS
$cshowList :: [Cryptokey] -> ShowS
show :: Cryptokey -> String
$cshow :: Cryptokey -> String
showsPrec :: Int -> Cryptokey -> ShowS
$cshowsPrec :: Int -> Cryptokey -> ShowS
Show, (forall x. Cryptokey -> Rep Cryptokey x)
-> (forall x. Rep Cryptokey x -> Cryptokey) -> Generic Cryptokey
forall x. Rep Cryptokey x -> Cryptokey
forall x. Cryptokey -> Rep Cryptokey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Cryptokey x -> Cryptokey
$cfrom :: forall x. Cryptokey -> Rep Cryptokey x
Generic, Cryptokey -> ()
(Cryptokey -> ()) -> NFData Cryptokey
forall a. (a -> ()) -> NFData a
rnf :: Cryptokey -> ()
$crnf :: Cryptokey -> ()
NFData, Typeable Cryptokey
DataType
Constr
Typeable Cryptokey
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Cryptokey -> c Cryptokey)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Cryptokey)
-> (Cryptokey -> Constr)
-> (Cryptokey -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Cryptokey))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Cryptokey))
-> ((forall b. Data b => b -> b) -> Cryptokey -> Cryptokey)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Cryptokey -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Cryptokey -> r)
-> (forall u. (forall d. Data d => d -> u) -> Cryptokey -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Cryptokey -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Cryptokey -> m Cryptokey)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Cryptokey -> m Cryptokey)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Cryptokey -> m Cryptokey)
-> Data Cryptokey
Cryptokey -> DataType
Cryptokey -> Constr
(forall b. Data b => b -> b) -> Cryptokey -> Cryptokey
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Cryptokey -> c Cryptokey
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Cryptokey
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Cryptokey -> u
forall u. (forall d. Data d => d -> u) -> Cryptokey -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Cryptokey -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Cryptokey -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Cryptokey -> m Cryptokey
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Cryptokey -> m Cryptokey
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Cryptokey
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Cryptokey -> c Cryptokey
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Cryptokey)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Cryptokey)
$cCryptokey :: Constr
$tCryptokey :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Cryptokey -> m Cryptokey
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Cryptokey -> m Cryptokey
gmapMp :: (forall d. Data d => d -> m d) -> Cryptokey -> m Cryptokey
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Cryptokey -> m Cryptokey
gmapM :: (forall d. Data d => d -> m d) -> Cryptokey -> m Cryptokey
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Cryptokey -> m Cryptokey
gmapQi :: Int -> (forall d. Data d => d -> u) -> Cryptokey -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Cryptokey -> u
gmapQ :: (forall d. Data d => d -> u) -> Cryptokey -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Cryptokey -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Cryptokey -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Cryptokey -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Cryptokey -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Cryptokey -> r
gmapT :: (forall b. Data b => b -> b) -> Cryptokey -> Cryptokey
$cgmapT :: (forall b. Data b => b -> b) -> Cryptokey -> Cryptokey
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Cryptokey)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Cryptokey)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Cryptokey)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Cryptokey)
dataTypeOf :: Cryptokey -> DataType
$cdataTypeOf :: Cryptokey -> DataType
toConstr :: Cryptokey -> Constr
$ctoConstr :: Cryptokey -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Cryptokey
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Cryptokey
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Cryptokey -> c Cryptokey
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Cryptokey -> c Cryptokey
$cp1Data :: Typeable Cryptokey
Data, Cryptokey
Cryptokey -> Empty Cryptokey
forall a. a -> Empty a
empty :: Cryptokey
$cempty :: Cryptokey
Empty)

instance ToJSON Cryptokey where
  toJSON :: Cryptokey -> Value
toJSON = Options -> Cryptokey -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
defaultOptions { fieldLabelModifier :: ShowS
fieldLabelModifier = String -> ShowS
forall a. Eq a => [a] -> [a] -> [a]
strip String
"ck_"}

instance FromJSON Cryptokey where
  parseJSON :: Value -> Parser Cryptokey
parseJSON = Options -> Value -> Parser Cryptokey
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON Options
defaultOptions { fieldLabelModifier :: ShowS
fieldLabelModifier = String -> ShowS
forall a. Eq a => [a] -> [a] -> [a]
strip String
"ck_"}