Skip to content

Commit

Permalink
[crawler] Use openssl for graphql client
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanCacqueray committed Feb 13, 2022
1 parent cb9be15 commit 19cf1c9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions haskell/monocle.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ common codegen
library
import: common-options, codegen
build-depends: base < 5
, HsOpenSSL >= 0.11
, MonadRandom
, aeson
, aeson-casing
Expand All @@ -108,7 +109,6 @@ library
, bugzilla-redhat >= 0.3.2
, byteslice >= 0.2
, bytestring >= 0.10
, connection
, containers >= 0.6
, dhall >= 1.39
, dhall-yaml >= 1.2
Expand All @@ -123,7 +123,7 @@ library
, gitrev >= 1.3.1
, 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
Expand Down
2 changes: 1 addition & 1 deletion haskell/src/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions haskell/src/Monocle/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..),
Expand All @@ -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

Expand All @@ -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 ::
Expand Down
4 changes: 4 additions & 0 deletions haskell/src/Monocle/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ module Monocle.Prelude
encodePrettyWithSpace,
(.=),

-- * http-client-openssl
withOpenSSL,

-- * bloodhound
BH.MonadBH,
BH.DocId,
Expand Down Expand Up @@ -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 (..))
Expand Down
2 changes: 1 addition & 1 deletion haskell/src/Monocle/Test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions haskell/test/Spec.hs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 19cf1c9

Please sign in to comment.