powerdns 0.1.1 → 0.2.0
raw patch · 8 files changed
+107/−16 lines, 8 filesdep ~base
Dependency ranges changed: base
Files
- CHANGELOG.md +11/−0
- PowerDNS/API.hs +9/−6
- PowerDNS/API/Cryptokeys.hs +1/−1
- PowerDNS/API/Servers.hs +8/−1
- PowerDNS/API/Version.hs +48/−0
- PowerDNS/Client.hs +15/−0
- powerdns.cabal +3/−2
- spec/Spec.hs +12/−6
CHANGELOG.md view
@@ -3,3 +3,14 @@ ## 0.1 -- 2021-05-28 * Initial release++## 0.1.1 -- 2021-06-08++* Relax base constraint++## 0.2 -- 2021-11-16++* Add missing FromHttpApiData instance for ObjectType+* Fix incorrect ToHttpApiData instance for ObjectType+* Rename incorrectly named data constructor for CryptokeysAPI+* Add versions endpoint
PowerDNS/API.hs view
@@ -11,6 +11,7 @@ ( API , api , PowerDNS(..)+ , module PowerDNS.API.Version , module PowerDNS.API.Zones , module PowerDNS.API.Servers , module PowerDNS.API.Cryptokeys@@ -25,6 +26,7 @@ import Servant.API import Servant.API.Generic ((:-), ToServantApi) +import PowerDNS.API.Version import PowerDNS.API.Zones import PowerDNS.API.Servers import PowerDNS.API.Cryptokeys@@ -34,13 +36,14 @@ api :: Proxy API api = Proxy -type API = "api" :> "v1" :> ToServantApi PowerDNS+type API = ToServantApi PowerDNS data PowerDNS f = PowerDNS- { servers :: f :- ToServantApi ServersAPI- , zones :: f :- ToServantApi ZonesAPI- , cryptokeys :: f :- ToServantApi CryptokeysAPI- , metadata :: f :- ToServantApi MetadataAPI- , tsigkeys :: f :- ToServantApi TSIGKeysAPI+ { versions :: f :- "api" :> ToServantApi VersionsAPI+ , servers :: f :- "api" :> "v1" :> ToServantApi ServersAPI+ , zones :: f :- "api" :> "v1" :> ToServantApi ZonesAPI+ , cryptokeys :: f :- "api" :> "v1" :> ToServantApi CryptokeysAPI+ , metadata :: f :- "api" :> "v1" :> ToServantApi MetadataAPI+ , tsigkeys :: f :- "api" :> "v1" :> ToServantApi TSIGKeysAPI } deriving Generic
PowerDNS/API/Cryptokeys.hs view
@@ -31,7 +31,7 @@ import PowerDNS.Internal.Utils (Empty(..), strip) -data CryptokeysAPI f = Cryptokeys+data CryptokeysAPI f = CryptokeysAPI { apiListCryptokeys :: f :- "servers" :> Capture "server_id" T.Text :> "zones" :> Capture "zone_id" T.Text :> "cryptokeys" :> Get '[JSON] [Cryptokey]
PowerDNS/API/Servers.hs view
@@ -127,10 +127,17 @@ parseJSON = genericParseJSON defaultOptions { fieldLabelModifier = fmap toLower . strip "Ty" , allNullaryToStringTag = True } +instance FromHttpApiData ObjectType where+ parseQueryParam "all" = Right TyAll+ parseQueryParam "zone" = Right TyZone+ parseQueryParam "record" = Right TyRecord+ parseQueryParam "comment" = Right TyComment+ parseQueryParam x = Left ("Unknown ObjectType: " <> x)+ instance ToHttpApiData ObjectType where toQueryParam TyAll = "all" toQueryParam TyZone = "zone"- toQueryParam TyRecord = "all"+ toQueryParam TyRecord = "record" toQueryParam TyComment = "comment" ----------------------------------------------------------------------------------------
+ PowerDNS/API/Version.hs view
@@ -0,0 +1,48 @@+-- |+-- Module: PowerDNS.API.Zones+-- Description: API version endpoint for PowerDNS API+--+-- Datatype for version API endpoint++{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveAnyClass #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE TypeOperators #-}+module PowerDNS.API.Version+ (+ -- * API+ VersionsAPI(..)++ -- * Data types+ , Version(..)+ )+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 (strip)++data VersionsAPI f = VersionsAPI+ { apiListVersions :: f :- Get '[JSON] [Version]+ } deriving Generic++data Version = Version+ { version_version :: Int+ , version_url :: T.Text+ } deriving (Eq, Ord, Show, Generic, NFData, Data)++instance ToJSON Version where+ toJSON = genericToJSON defaultOptions { fieldLabelModifier = strip "version_" }++instance FromJSON Version where+ parseJSON = genericParseJSON defaultOptions { fieldLabelModifier = strip "version_" }+
PowerDNS/Client.hs view
@@ -11,6 +11,10 @@ -- * Authentication applyXApiKey + -- * Version+ , listVersions+ , Version(..)+ -- * Zones -- -- | See documentation at [PowerDNS Zones API](https://doc.powerdns.com/authoritative/http-api/zone.html)@@ -136,6 +140,17 @@ pdnsClient :: PowerDNS (AsClientT ClientM) pdnsClient = fromServant (client api)++----------------------------------------------------------------------------------------++versionsClient :: VersionsAPI (AsClientT ClientM)+versionsClient = fromServant (versions pdnsClient)++-- | List the API versions and urls from the server. This is an undocumented endpoint.+listVersions :: ClientM [Version]+listVersions = apiListVersions versionsClient++---------------------------------------------------------------------------------------- zonesClient :: ZonesAPI (AsClientT ClientM) zonesClient = fromServant (zones pdnsClient)
powerdns.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: powerdns-version: 0.1.1+version: 0.2.0 license: BSD3 license-file: LICENSE copyright: (c) 2021 Victor Nawothnig@@ -38,6 +38,7 @@ library exposed-modules: PowerDNS.API+ PowerDNS.API.Version PowerDNS.API.Zones PowerDNS.API.Servers PowerDNS.API.Cryptokeys@@ -68,7 +69,7 @@ hs-source-dirs: spec default-language: Haskell2010 build-depends:- base >=4.12 && <4.14,+ base >=4.12 && <4.15, powerdns -any, tasty >=1.4.1 && <1.5, tasty-hunit >=0.10.0.3 && <0.11,
spec/Spec.hs view
@@ -31,7 +31,8 @@ main = defaultMain tree tree :: TestTree-tree = testGroup "All specs" [ authSpecs+tree = testGroup "All specs" [ versionSpec+ , authSpecs , zoneSpecs ] @@ -43,6 +44,11 @@ r <- run c assertRight "ClientM result" r +versionSpec :: TestTree+versionSpec = testCase "Verifies API version" $ do+ ver <- run listVersions+ assertEqual "API versions" ver (Right [Version 1 "/api/v1"])+ zoneSpecs :: TestTree zoneSpecs = testCaseSteps "Verifies zones can be created, displayed and deleted" $ \step -> do step "Ensure no zone is currently found"@@ -65,7 +71,7 @@ step "Ensure no zone is left over" r <- run (listZones "localhost" Nothing Nothing) assertEqual "list of zones" (Right []) r- + step "Done" where@@ -78,7 +84,7 @@ , rrset_type = A , rrset_ttl = 86003 , rrset_changetype = Nothing- , rrset_records = Just [Record "127.0.0.1" Nothing]+ , rrset_records = Just [Record "127.0.0.1" False] , rrset_comments = Nothing } ]@@ -90,9 +96,9 @@ , rrset_type = AAAA , rrset_ttl = 1234 , rrset_changetype = Nothing- , rrset_records = Just [Record "::1" Nothing]+ , rrset_records = Just [Record "::1" False] , rrset_comments = Nothing- } + } ] -- | Erases all server generated data from a zone. Used to test for equality.@@ -134,7 +140,7 @@ assertIsSuccess :: Show a => Either ClientError a -> Assertion assertIsSuccess = assertPredicate "successful HTTP response" isRight- + assertJust :: HasCallStack => String -> Maybe a -> IO a assertJust preface = maybe (assertFailure msg) pure where msg = (if null preface then "" else preface ++ "\n") ++