-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(terraform): add option to add proxy to request (#6916)
* add proxy to request * add proxy to request * add envs, in the proxy_url we need to add the GcpIdentityProvider * . * . * .
- Loading branch information
1 parent
8d170ad
commit 3d39c27
Showing
3 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
from typing import Any | ||
|
||
import requests | ||
|
||
|
||
class ProxyClient: | ||
def __init__(self) -> None: | ||
self.proxy_ca_path = os.getenv('PROXY_CA_PATH', None) | ||
if self.proxy_ca_path is None: | ||
raise Exception("[ProxyClient] CA certificate path is missing") | ||
|
||
def get_session(self) -> requests.Session: | ||
if not os.getenv('PROXY_URL', None): | ||
raise Exception('Please provide "PROXY_URL" env var') | ||
proxy_url = os.getenv('PROXY_URL') | ||
session = requests.Session() | ||
proxies = { | ||
"http": proxy_url, | ||
"https": proxy_url, | ||
} | ||
session.proxies.update(proxies) # type: ignore | ||
return session | ||
|
||
def send_request(self, request: requests.Request) -> requests.Response: | ||
session = self.get_session() | ||
prepared_request = session.prepare_request(request) | ||
return session.send(prepared_request, verify=self.proxy_ca_path) | ||
|
||
|
||
def call_http_request_with_proxy(request: requests.Request) -> Any: | ||
proxy_client = ProxyClient() | ||
return proxy_client.send_request(request=request) |