dhruv-pratap commented on code in PR #6019:
URL: https://github.com/apache/iceberg/pull/6019#discussion_r1000843624


##########
python/pyiceberg/catalog/rest.py:
##########
@@ -184,28 +190,40 @@ def __init__(
         """
         self.properties = properties
         self.uri = properties[URI]
+        self.session = requests.Session()
+        self._set_session_ssl_config()
 
         if credential := properties.get(CREDENTIAL):
             properties[TOKEN] = self._fetch_access_token(credential)
+
+        self._set_session_headers()
         super().__init__(name, **self._fetch_config(properties))
 
+    def _set_session_ssl_config(self):
+        """Sets the client side and server side SSL cert verification, if 
provided as properties."""
+        if ssl_config := self.properties.get(SSL):
+            if ssl_ca_bundle := ssl_config.get(CA_BUNDLE):
+                self.session.verify = ssl_ca_bundle
+            if ssl_client := ssl_config.get(CLIENT):
+                if all(k in ssl_client for k in (CERT, KEY)):
+                    self.session.cert = (ssl_client[CERT], ssl_client[KEY])
+                elif ssl_client_cert := ssl_client.get(CERT):
+                    self.session.cert = ssl_client_cert
+
     def _check_valid_namespace_identifier(self, identifier: Union[str, 
Identifier]) -> Identifier:
         """The identifier should have at least one element"""
         identifier_tuple = Catalog.identifier_to_tuple(identifier)
         if len(identifier_tuple) < 1:
             raise NoSuchNamespaceError(f"Empty namespace identifier: 
{identifier}")
         return identifier_tuple
 
-    @property
-    def headers(self) -> Properties:
-        headers = {
-            "Content-type": "application/json",
-            "X-Client-Version": ICEBERG_REST_SPEC_VERSION,
-            "User-Agent": f"PyIceberg/{__version__}",
-        }
+    def _set_session_headers(self):

Review Comment:
   > Thanks for working on this @dhruv-pratap! I like it a lot. Another 
approach we could also take is to have a function `_create_session() -> 
Session` that will set up the session. This would both set the SSL and the 
headers, and in the constructor, we would do:
   > 
   > ```
   > self.session = self._create_session()
   > ```
   > 
   > This way we have a single place where we set up the session, instead of 
two methods. WDYT?
   
   I did think about that initially, but the 
`self._fetch_access_token(credential)` REST call poses a kind-of 
chicken-and-egg problem. You need the session SSL config to be configured to 
make that REST call, and then the session's header has to be enriched with the 
Auth Token. Let me try to give it a shot to see what that looks like and send 
an amendment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to