Azure / Azure/azure-sdk-for-python
Configuring a Global HTTPTransport Session For Enterprise Proxy
- 主要言語
- Python
- スター
- 5.6k
- フォーク
- 3.4k
- 平均マージ
- 2日 2時間
- マージ済み PR(30日)
- 213
説明
- **Package Name**: azure-storage-blob
- **Package Version**: 12.26.0
- **Operating System**: Microsoft Windows 11 Enterprise
- **Python Version**: Python 3.13.2
**Describe the bug**
Similar to the user from #33607, we are behind a transparent network level corporate proxy. So when our applications make requests, the Proxy's SSL Certificate needs to be verified. Of course, the Proxy SSL Certificate is in the Windows Trust Store. Unfortunately, as I understand it depending the Python distribution, Python will not implicitly leverage the system Trust Store on Windows. In order for a Windows Python runtime to always load the system trust store, a user must create a default SSL context and load the default certificates like so
```python
ssl_context = ssl.create_default_context()
ssl_context.load_default_certs()
```
Now, I need to get this SSL Context into a Requests session so that it will validate my Proxy's certificate. I can accomplish that with the below
```python
class CustomSSLAdapter(HTTPAdapter):
def init_poolmanager(self, connections, maxsize, block=False, **pool_kwargs):
self.poolmanager = PoolManager(
num_pools=connections,
maxsize=maxsize,
block=block,
ssl_context=ssl_context,
**pool_kwargs,
)
requests_session = requests.Session()
requests_session.mount("https://", CustomSSLAdapter())
```
Alright, so if inject this session in my transport I can finally use it in the client
```
transport = RequestsTransport(session=requests_session)
return BlobServiceClient(azure_storage_url, credential=azure_credentials, transport=transport)
```
It would be nice if there was an easy way to globally configure the entire Azure library to use this default transport!
Also, it wasn't easy to this out using the existing documentation. I assume configuring self signed certificates is probably pretty common, so maybe it would be nice to make the solution more apparent in the docs.
I hope this helps someone else!
コントリビューションガイド
調査の方向性
まず、issue に示されている RequestsTransport と BlobServiceClient の使用方法を確認し、次に Azure ライブラリ全体でトランスポート設定がどこで確立されているかを特定します。共有 HTTP セッションを構成するためのサポートされた方法を提供するか、Windows のトラストストア証明書を含む既存のクライアント単位のアプローチを明確に文書化できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend, cloud
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 35/100