From 7f0f48fb3f9619fd65d2ac15f7fdcad6afae90f2 Mon Sep 17 00:00:00 2001 From: Ollie Charles Date: Tue, 1 Aug 2023 11:20:49 +0100 Subject: [PATCH 1/6] Support `servant-0.20` and GHC 9.6 --- servant-hmac-auth.cabal | 18 ++++++------ src/Servant/Auth/Hmac/Client.hs | 50 ++++++++++++++++----------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/servant-hmac-auth.cabal b/servant-hmac-auth.cabal index e6aa2db..927ce35 100644 --- a/servant-hmac-auth.cabal +++ b/servant-hmac-auth.cabal @@ -24,7 +24,7 @@ source-repository head location: https://github.com/holmusk/servant-hmac-auth.git common common-options - build-depends: base >= 4.11.1.0 && < 4.18 + build-depends: base >= 4.11.1.0 && < 4.19 ghc-options: -Wall -Wincomplete-uni-patterns @@ -74,12 +74,12 @@ library , http-types ^>= 0.12 , http-client >= 0.6.4 && < 0.8 , memory >= 0.15 && < 0.19 - , mtl ^>= 2.2.2 - , servant ^>= 0.18 || ^>= 0.19 - , servant-client ^>= 0.18 || ^>= 0.19 - , servant-client-core ^>= 0.18 || ^>= 0.19 - , servant-server ^>= 0.18 || ^>= 0.19 - , transformers ^>= 0.5 + , mtl ^>= 2.2.2 || ^>= 2.3 + , servant ^>= 0.18 || ^>= 0.19 || ^>= 0.20 + , servant-client ^>= 0.20 + , servant-client-core ^>= 0.18 || ^>= 0.19 || ^>= 0.20 + , servant-server ^>= 0.18 || ^>= 0.19 || ^>= 0.20 + , transformers ^>= 0.5 || ^>= 0.6 , wai ^>= 3.2.2.1 test-suite servant-hmac-auth-test @@ -95,8 +95,8 @@ test-suite servant-hmac-auth-test , hspec-golden ^>= 0.2 , http-client >= 0.6.4 && < 0.8 , http-types ^>= 0.12 - , servant-client ^>= 0.18 || ^>= 0.19 - , servant-server ^>= 0.18 || ^>= 0.19 + , servant-client ^>= 0.20 + , servant-server ^>= 0.18 || ^>= 0.19 || ^>= 0.20 , text , warp ^>= 3.3 other-modules: Servant.Auth.Hmac.CryptoSpec diff --git a/src/Servant/Auth/Hmac/Client.hs b/src/Servant/Auth/Hmac/Client.hs index fe6ab53..4a0a345 100644 --- a/src/Servant/Auth/Hmac/Client.hs +++ b/src/Servant/Auth/Hmac/Client.hs @@ -90,7 +90,7 @@ hmacClientSign :: Servant.Request -> HmacClientM Servant.Request hmacClientSign req = HmacClientM $ do HmacSettings{..} <- ask url <- lift $ asks baseUrl - let signedRequest = signRequestHmac hmacSigner hmacSecretKey url req + signedRequest <- liftIO $ signRequestHmac hmacSigner hmacSecretKey url req case hmacRequestHook of Nothing -> pure () Just hook -> lift $ hook signedRequest @@ -118,9 +118,27 @@ hmacClient = Proxy @api `clientIn` Proxy @HmacClientM -- Internals ---------------------------------------------------------------------------- -servantRequestToPayload :: BaseUrl -> Servant.Request -> RequestPayload -servantRequestToPayload url sreq = - RequestPayload +servantRequestToPayload :: BaseUrl -> Servant.Request -> IO RequestPayload +servantRequestToPayload url sreq = do + req <- + defaultMakeClientRequest + url + sreq + { Servant.requestQueryString = + fromList $ sort $ toList $ Servant.requestQueryString sreq + } + + let + hostAndPort :: ByteString + hostAndPort = case lookup (mk "Host") (Client.requestHeaders req) of + Just hp -> hp + Nothing -> + case (Client.secure req, Client.port req) of + (True, 443) -> Client.host req + (False, 80) -> Client.host req + (_, p) -> Client.host req <> ":" <> fromString (show p) + + return RequestPayload { rpMethod = Client.method req , rpContent = "" -- toBsBody $ Client.requestBody req , rpHeaders = @@ -130,24 +148,6 @@ servantRequestToPayload url sreq = Client.requestHeaders req , rpRawUrl = hostAndPort <> Client.path req <> Client.queryString req } - where - req :: Client.Request - req = - defaultMakeClientRequest - url - sreq - { Servant.requestQueryString = - fromList $ sort $ toList $ Servant.requestQueryString sreq - } - - hostAndPort :: ByteString - hostAndPort = case lookup (mk "Host") (Client.requestHeaders req) of - Just hp -> hp - Nothing -> - case (Client.secure req, Client.port req) of - (True, 443) -> Client.host req - (False, 80) -> Client.host req - (_, p) -> Client.host req <> ":" <> fromString (show p) -- toBsBody :: RequestBody -> ByteString -- toBsBody (RequestBodyBS bs) = bs @@ -171,9 +171,9 @@ signRequestHmac :: -- | Original request Servant.Request -> -- | Signed request - Servant.Request + IO Servant.Request signRequestHmac signer sk url req = do - let payload = servantRequestToPayload url req + payload <- servantRequestToPayload url req let signature = requestSignature signer sk payload let authHead = (authHeaderName, "HMAC " <> unSignature signature) - req{Servant.requestHeaders = authHead <| Servant.requestHeaders req} + return req{Servant.requestHeaders = authHead <| Servant.requestHeaders req} From 978d7ac55308adf2490e6b18ff72c938be1e415b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Thu, 7 Dec 2023 11:48:25 +0100 Subject: [PATCH 2/6] Update CI, don't drop servant-0.19 --- .github/workflows/haskell-ci.yml | 17 +++++++++-------- servant-hmac-auth.cabal | 12 ++++++------ src/Servant/Auth/Hmac/Client.hs | 11 +++++++---- stack-8.10.7.yaml | 10 ---------- stack-9.2.5.yaml | 1 - stack-9.2.8.yaml | 1 + stack-9.4.8.yaml | 1 + stack-9.6.3.yaml | 1 + 8 files changed, 25 insertions(+), 29 deletions(-) delete mode 100644 stack-8.10.7.yaml delete mode 100644 stack-9.2.5.yaml create mode 100644 stack-9.2.8.yaml create mode 100644 stack-9.4.8.yaml create mode 100644 stack-9.6.3.yaml diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index a62353f..c4523b7 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -14,12 +14,13 @@ jobs: matrix: os: - ubuntu-latest - cabal: [3.8] + cabal: + - '3.10.2.0' ghc: - - 8.10.7 - 9.0.2 - - 9.2.5 - - 9.4.4 + - 9.2.8 + - 9.4.8 + - 9.6.3 steps: - uses: actions/checkout@v3 if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/master' @@ -49,12 +50,12 @@ jobs: strategy: matrix: stack: - - 2.9.3 + - 2.13.1 stack-yaml: - - stack-8.10.7.yaml - stack-9.0.2.yaml - - stack-9.2.5.yaml - + - stack-9.2.8.yaml + - stack-9.4.8.yaml + - stack-9.6.3.yaml steps: - uses: actions/checkout@v3 if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/master' diff --git a/servant-hmac-auth.cabal b/servant-hmac-auth.cabal index 927ce35..b1a54f0 100644 --- a/servant-hmac-auth.cabal +++ b/servant-hmac-auth.cabal @@ -14,10 +14,10 @@ category: Web, Cryptography build-type: Simple extra-source-files: README.md , CHANGELOG.md -tested-with: GHC == 8.10.7 - GHC == 9.0.2 - GHC == 9.2.5 - GHC == 9.4.4 +tested-with: GHC == 9.0.2 + GHC == 9.2.8 + GHC == 9.4.8 + GHC == 9.6.3 source-repository head type: git @@ -76,7 +76,7 @@ library , memory >= 0.15 && < 0.19 , mtl ^>= 2.2.2 || ^>= 2.3 , servant ^>= 0.18 || ^>= 0.19 || ^>= 0.20 - , servant-client ^>= 0.20 + , servant-client ^>= 0.19 || ^>= 0.20 , servant-client-core ^>= 0.18 || ^>= 0.19 || ^>= 0.20 , servant-server ^>= 0.18 || ^>= 0.19 || ^>= 0.20 , transformers ^>= 0.5 || ^>= 0.6 @@ -95,7 +95,7 @@ test-suite servant-hmac-auth-test , hspec-golden ^>= 0.2 , http-client >= 0.6.4 && < 0.8 , http-types ^>= 0.12 - , servant-client ^>= 0.20 + , servant-client ^>= 0.19 || ^>= 0.20 , servant-server ^>= 0.18 || ^>= 0.19 || ^>= 0.20 , text , warp ^>= 3.3 diff --git a/src/Servant/Auth/Hmac/Client.hs b/src/Servant/Auth/Hmac/Client.hs index 4a0a345..1d57933 100644 --- a/src/Servant/Auth/Hmac/Client.hs +++ b/src/Servant/Auth/Hmac/Client.hs @@ -1,6 +1,7 @@ {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE InstanceSigs #-} +{-# LANGUAGE CPP #-} -- | Servant client authentication. module Servant.Auth.Hmac.Client ( @@ -120,10 +121,12 @@ hmacClient = Proxy @api `clientIn` Proxy @HmacClientM servantRequestToPayload :: BaseUrl -> Servant.Request -> IO RequestPayload servantRequestToPayload url sreq = do - req <- - defaultMakeClientRequest - url - sreq +#if MIN_VERSION_servant_client(0,20,0) + req <- -- servant-client 0.20: defaultMakeClientRequest :: BaseUrl -> Request -> IO Request +#else + let req = -- servant-client 0.12: defaultMakeClientRequest :: BaseUrl -> Request -> Request +#endif + defaultMakeClientRequest url sreq { Servant.requestQueryString = fromList $ sort $ toList $ Servant.requestQueryString sreq } diff --git a/stack-8.10.7.yaml b/stack-8.10.7.yaml deleted file mode 100644 index c3e0a0e..0000000 --- a/stack-8.10.7.yaml +++ /dev/null @@ -1,10 +0,0 @@ -resolver: lts-18.28 - -extra-deps: - - cryptonite-0.29@sha256:147724f6a8e4394fcbd51bf52aba7a8b92d3fc8f42055cd6ca9486655e2ab614,18312 - - hspec-golden-0.2.0.0@sha256:395816f942d9386ec7eddda938415d99364118841bff9053bac2457811be8acc,1854 - - memory-0.15.0@sha256:c8f08e04d68a4a8bdbf6eed1cbf57f26f1d59beadf986a3ac18c78bf8a07a439,5005 - - servant-0.18.3@sha256:0fbf8f9274bdfda6a778d6d7ec714c9f0abd17102af9bc002a93fe3ed284e8ca,5309 - - servant-client-0.18.3@sha256:570145df5209b245a141eec6841fbca6785cd88e073e85eecbeff4438ca34784,4602 - - servant-client-core-0.18.3@sha256:db2551c94cc17bef7682602082d6a16e79593cfc939f2d696d4ccee21b2b2091,3649 - - servant-server-0.18.3@sha256:8040e38682d936a2c87ad2a787cc65b3bad18c87e9f773cf7bcfc12ce76af96e,5508 diff --git a/stack-9.2.5.yaml b/stack-9.2.5.yaml deleted file mode 100644 index 570867c..0000000 --- a/stack-9.2.5.yaml +++ /dev/null @@ -1 +0,0 @@ -resolver: lts-20.8 diff --git a/stack-9.2.8.yaml b/stack-9.2.8.yaml new file mode 100644 index 0000000..fc9172f --- /dev/null +++ b/stack-9.2.8.yaml @@ -0,0 +1 @@ +resolver: lts-20.26 diff --git a/stack-9.4.8.yaml b/stack-9.4.8.yaml new file mode 100644 index 0000000..377dc6b --- /dev/null +++ b/stack-9.4.8.yaml @@ -0,0 +1 @@ +resolver: lts-21.23 diff --git a/stack-9.6.3.yaml b/stack-9.6.3.yaml new file mode 100644 index 0000000..bab180d --- /dev/null +++ b/stack-9.6.3.yaml @@ -0,0 +1 @@ +resolver: nightly-2023-12-07 From d70250f3ea041584c79b155deeeb413e6ccfe2ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Thu, 7 Dec 2023 12:20:12 +0100 Subject: [PATCH 3/6] Drop 0.18 from servant-* constraints, add changelog entry --- CHANGELOG.md | 4 ++++ servant-hmac-auth.cabal | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34d6412..f984dbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ `servant-hmac-auth` uses [PVP Versioning][1]. The change log is available [on GitHub][2]. +## 0.1.6 - TBD +* Bump dependency upper bounds to allow building with GHC `9.0`, `9.2`, `9.4` and `9.6`. +* Allow building with `servant-0.20` + ## 0.1.5 - Jan 27, 2023 * Bump dependency upper bounds, allow building with `GHC 9.0`, `9.2` and `9.4` diff --git a/servant-hmac-auth.cabal b/servant-hmac-auth.cabal index b1a54f0..c2a97bf 100644 --- a/servant-hmac-auth.cabal +++ b/servant-hmac-auth.cabal @@ -75,10 +75,10 @@ library , http-client >= 0.6.4 && < 0.8 , memory >= 0.15 && < 0.19 , mtl ^>= 2.2.2 || ^>= 2.3 - , servant ^>= 0.18 || ^>= 0.19 || ^>= 0.20 + , servant ^>= 0.19 || ^>= 0.20 , servant-client ^>= 0.19 || ^>= 0.20 - , servant-client-core ^>= 0.18 || ^>= 0.19 || ^>= 0.20 - , servant-server ^>= 0.18 || ^>= 0.19 || ^>= 0.20 + , servant-client-core ^>= 0.19 || ^>= 0.20 + , servant-server ^>= 0.19 || ^>= 0.20 , transformers ^>= 0.5 || ^>= 0.6 , wai ^>= 3.2.2.1 @@ -96,7 +96,7 @@ test-suite servant-hmac-auth-test , http-client >= 0.6.4 && < 0.8 , http-types ^>= 0.12 , servant-client ^>= 0.19 || ^>= 0.20 - , servant-server ^>= 0.18 || ^>= 0.19 || ^>= 0.20 + , servant-server ^>= 0.19 || ^>= 0.20 , text , warp ^>= 3.3 other-modules: Servant.Auth.Hmac.CryptoSpec From aa0b596a82a89f3bd6e46ef7b04005882c0f3c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Thu, 7 Dec 2023 13:05:26 +0100 Subject: [PATCH 4/6] Release 0.1.6 --- CHANGELOG.md | 2 +- servant-hmac-auth.cabal | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f984dbe..579c6ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ `servant-hmac-auth` uses [PVP Versioning][1]. The change log is available [on GitHub][2]. -## 0.1.6 - TBD +## 0.1.6 - Dec 7, 2023 * Bump dependency upper bounds to allow building with GHC `9.0`, `9.2`, `9.4` and `9.6`. * Allow building with `servant-0.20` diff --git a/servant-hmac-auth.cabal b/servant-hmac-auth.cabal index c2a97bf..fa6fc05 100644 --- a/servant-hmac-auth.cabal +++ b/servant-hmac-auth.cabal @@ -1,6 +1,6 @@ cabal-version: 2.4 name: servant-hmac-auth -version: 0.1.5 +version: 0.1.6 synopsis: Servant authentication with HMAC description: Servant authentication with HMAC. See README.md for usage example. homepage: https://github.com/holmusk/servant-hmac-auth From aac0be233101ab98ce6f8cc1da6db5cfe7f7a4ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Thu, 7 Dec 2023 13:10:13 +0100 Subject: [PATCH 5/6] Fix cabal check warning --- servant-hmac-auth.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/servant-hmac-auth.cabal b/servant-hmac-auth.cabal index fa6fc05..1de1b44 100644 --- a/servant-hmac-auth.cabal +++ b/servant-hmac-auth.cabal @@ -12,7 +12,7 @@ maintainer: tech@holmusk.com copyright: 2018 Holmusk category: Web, Cryptography build-type: Simple -extra-source-files: README.md +extra-doc-files: README.md , CHANGELOG.md tested-with: GHC == 9.0.2 GHC == 9.2.8 From 43f97fb430ea3995170bc57a08f9b54d1b6fde9f Mon Sep 17 00:00:00 2001 From: Jan Hrcek <2716069+jhrcek@users.noreply.github.com> Date: Thu, 7 Dec 2023 13:15:12 +0100 Subject: [PATCH 6/6] fix typo --- src/Servant/Auth/Hmac/Client.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Servant/Auth/Hmac/Client.hs b/src/Servant/Auth/Hmac/Client.hs index 1d57933..0a82162 100644 --- a/src/Servant/Auth/Hmac/Client.hs +++ b/src/Servant/Auth/Hmac/Client.hs @@ -124,7 +124,7 @@ servantRequestToPayload url sreq = do #if MIN_VERSION_servant_client(0,20,0) req <- -- servant-client 0.20: defaultMakeClientRequest :: BaseUrl -> Request -> IO Request #else - let req = -- servant-client 0.12: defaultMakeClientRequest :: BaseUrl -> Request -> Request + let req = -- servant-client 0.19: defaultMakeClientRequest :: BaseUrl -> Request -> Request #endif defaultMakeClientRequest url sreq { Servant.requestQueryString =