Skip to content

Commit

Permalink
Merge pull request #1095 from TristanCacqueray/proxy-api
Browse files Browse the repository at this point in the history
crawler: use a different proxy environment for the api
  • Loading branch information
mergify[bot] authored Dec 13, 2023
2 parents 7c60ac9 + 9ccd4b5 commit 659e4c3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.

### Added

- [crawler] Proxy can be configured with `http_proxy` and `https_proxy` environment.
- [crawler] Proxy can be configured with `HTTP_PROXY` and `HTTPS_PROXY` environment. To proxy http requests between crawlers and the api, use the `API_PROXY` environment.
- [crawler] A new `groups` sub-field in all Author fields (`on_author` and `author`) for `Change` and `Events`.
Groups memberships are reflected from the config file to the database.

Expand Down
2 changes: 1 addition & 1 deletion src/Lentille/Gerrit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ queryChanges env count queries startM = unsafeEff_ $ G.queryChanges count querie

getClient :: Text -> Maybe (Text, Secret) -> IO G.GerritClient
getClient url auth = do
manager <- mkManager
manager <- mkManager Nothing
pure $ G.getClientWithManager manager url (getGerritAuth <$> auth)

getGerritAuth :: (Text, Secret) -> (Text, Text)
Expand Down
14 changes: 8 additions & 6 deletions src/Monocle/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ lookupTlsVerify = do
_ -> Verify

-- | Create a HTTP manager
mkManager :: IO Manager
mkManager = mkManager' =<< lookupTlsVerify
mkManager :: Maybe Text -> IO Manager
mkManager proxyEnv = mkManager' proxyEnv =<< lookupTlsVerify

mkManager' :: TlsVerify -> IO Manager
mkManager' verify = do
mkManager' :: Maybe Text -> TlsVerify -> IO Manager
mkManager' proxyEnv verify = do
let opensslSettings = case verify of
Insecure -> OpenSSL.defaultOpenSSLSettings {OpenSSL.osslSettingsVerifyMode = VerifyNone}
Verify -> OpenSSL.defaultOpenSSLSettings
Expand All @@ -63,7 +63,9 @@ mkManager' verify = do
let settings = OpenSSL.opensslManagerSettings (pure ctx)

-- setup proxy
let proxy = Network.HTTP.Client.proxyEnvironment Nothing
let proxy = case proxyEnv of
Nothing -> Network.HTTP.Client.proxyEnvironment Nothing
Just proxyEnvName -> Network.HTTP.Client.proxyEnvironmentNamed proxyEnvName Nothing
newManager (Network.HTTP.Client.managerSetProxy proxy settings)

-- | Create the 'MonocleClient'
Expand All @@ -81,7 +83,7 @@ withClient url managerM callBack =
do
tokenM' <- liftIO $ lookupEnv "MONOCLE_ADMIN_TOKEN"
let tokenM = from <$> tokenM'
manager <- maybe (liftIO mkManager) pure managerM
manager <- maybe (liftIO (mkManager (Just "API_PROXY"))) pure managerM
callBack MonocleClient {..}
where
baseUrl = T.dropWhileEnd (== '/') url <> "/"
Expand Down
2 changes: 1 addition & 1 deletion src/Monocle/Effects.hs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ newtype instance StaticRep HttpEffect = HttpEffect HttpEnv
-- | 'runHttpEffect' simply add a Manager to the static rep env.
runHttpEffect :: IOE :> es => Eff (HttpEffect : es) a -> Eff es a
runHttpEffect action = do
manager <- liftIO Monocle.Client.mkManager
manager <- liftIO $ Monocle.Client.mkManager Nothing
runHttpEffectWithManager manager action

runHttpEffectWithManager :: IOE :> es => HTTP.Manager -> Eff (HttpEffect : es) a -> Eff es a
Expand Down

0 comments on commit 659e4c3

Please sign in to comment.