diff --git a/haskell/monocle.cabal b/haskell/monocle.cabal index 4d9001ddd..61691368e 100644 --- a/haskell/monocle.cabal +++ b/haskell/monocle.cabal @@ -97,6 +97,7 @@ common codegen library import: common-options, codegen build-depends: base < 5 + , HsOpenSSL >= 0.11 , MonadRandom , aeson , aeson-casing @@ -124,6 +125,7 @@ library , hashtables >= 1.2 , http-client >= 0.6 , http-client-tls >= 0.3 + , http-client-openssl >= 0.3 , http-mock >= 0.1 , http-types >=0.12 , json-syntax >= 0.2 diff --git a/haskell/src/CLI.hs b/haskell/src/CLI.hs index 2074609fe..872bf8e2f 100644 --- a/haskell/src/CLI.hs +++ b/haskell/src/CLI.hs @@ -78,7 +78,7 @@ usage = getInt txt = fromMaybe (error . from $ "Invalid number: " <> txt) $ readMaybe txt main :: IO () -main = join $ execParser opts +main = withOpenSSL $ join $ execParser opts where opts = info diff --git a/haskell/src/Monocle/Client.hs b/haskell/src/Monocle/Client.hs index 994f09470..00789d2da 100644 --- a/haskell/src/Monocle/Client.hs +++ b/haskell/src/Monocle/Client.hs @@ -15,7 +15,6 @@ where import qualified Data.Text as T import Monocle.Prelude -import qualified Network.Connection as Connection import Network.HTTP.Client ( Manager, RequestBody (..), @@ -27,7 +26,8 @@ import Network.HTTP.Client requestHeaders, responseBody, ) -import qualified Network.HTTP.Client.TLS as HTTP +import qualified Network.HTTP.Client.OpenSSL as OpenSSL +import OpenSSL.Session (VerificationMode (VerifyNone)) import Proto3.Suite.JSONPB (FromJSONPB (..), ToJSONPB (..)) import qualified Proto3.Suite.JSONPB as JSONPB @@ -42,12 +42,11 @@ data MonocleClient = MonocleClient mkManager :: IO Manager mkManager = do disableTlsM <- lookupEnv "TLS_NO_VERIFY" - let managerSettings = case disableTlsM of - Just _ -> - let tlsSettings = Connection.TLSSettingsSimple True False False - in HTTP.mkManagerSettings tlsSettings Nothing - Nothing -> HTTP.tlsManagerSettings - newManager managerSettings + let opensslSettings = case disableTlsM of + Just _ -> OpenSSL.defaultOpenSSLSettings {OpenSSL.osslSettingsVerifyMode = VerifyNone} + Nothing -> OpenSSL.defaultOpenSSLSettings + ctx <- OpenSSL.defaultMakeContext opensslSettings + newManager $ OpenSSL.opensslManagerSettings (pure ctx) -- | Create the 'MonocleClient' withClient :: diff --git a/haskell/src/Monocle/Prelude.hs b/haskell/src/Monocle/Prelude.hs index 5fe67c955..12593a5a0 100644 --- a/haskell/src/Monocle/Prelude.hs +++ b/haskell/src/Monocle/Prelude.hs @@ -139,6 +139,9 @@ module Monocle.Prelude encodePrettyWithSpace, (.=), + -- * http-client-openssl + withOpenSSL, + -- * bloodhound BH.MonadBH, BH.DocId, @@ -199,6 +202,7 @@ import GHC.Float (double2Float) import GHC.Generics (C, D, K1, M1, R, Rep, S, Selector, U1, selName, (:*:), (:+:)) import qualified Google.Protobuf.Timestamp import Language.Haskell.TH.Quote (QuasiQuoter) +import Network.HTTP.Client.OpenSSL (withOpenSSL) import Prometheus (Info (..), counter, incCounter, withLabel) import qualified Prometheus import Proto3.Suite (Enumerated (..)) diff --git a/haskell/src/Monocle/Test/Spec.hs b/haskell/src/Monocle/Test/Spec.hs index 43e7411e0..668e2bba3 100644 --- a/haskell/src/Monocle/Test/Spec.hs +++ b/haskell/src/Monocle/Test/Spec.hs @@ -19,7 +19,7 @@ import Test.Tasty import Test.Tasty.HUnit main :: IO () -main = do +main = withOpenSSL $ do setEnv "API_KEY" "secret" setEnv "CRAWLERS_API_KEY" "secret" integrationTests <- do diff --git a/haskell/test/Spec.hs b/haskell/test/Spec.hs index d56205a1c..3fbe835df 100644 --- a/haskell/test/Spec.hs +++ b/haskell/test/Spec.hs @@ -1,7 +1,7 @@ module Main (main) where +import Monocle.Prelude import qualified Monocle.Test.Spec -import Prelude (IO) main :: IO () -main = Monocle.Test.Spec.main +main = withOpenSSL $ Monocle.Test.Spec.main