Copilot commented on code in PR #2072:
URL: https://github.com/apache/iceberg-python/pull/2072#discussion_r2232138598


##########
pyproject.toml:
##########
@@ -317,6 +322,7 @@ rest-sigv4 = ["boto3"]
 hf = ["huggingface-hub"]
 pyiceberg-core = ["pyiceberg-core"]
 datafusion = ["datafusion"]
+gcp-auth=["google-auth"]

Review Comment:
   Missing space around the equals sign. Should be `gcp-auth = ["google-auth"]` 
to match the formatting of other entries.
   ```suggestion
   gcp-auth = ["google-auth"]
   ```



##########
pyiceberg/catalog/rest/auth.py:
##########
@@ -119,6 +120,35 @@ def auth_header(self) -> str:
         return f"Bearer {self._token}"
 
 
+class GoogleAuthManager(AuthManager):
+    """An auth manager that is responsible for handling Google credentials."""
+
+    def __init__(self, credentials_path: Optional[str] = None, scopes: 
Optional[List[str]] = None):
+        """
+        Initialize GoogleAuthManager.
+
+        Args:
+            credentials_path: Optional path to Google credentials JSON file.
+            scopes: Optional list of OAuth2 scopes.
+        """
+        try:
+            import google.auth
+            import google.auth.transport.requests
+        except ImportError as e:
+            raise ImportError("Google Auth libraries not found. Please install 
'google-auth'.") from e
+
+        if credentials_path:
+            self.credentials, _ = 
google.auth.load_credentials_from_file(credentials_path, scopes=scopes)
+        else:
+            logging.info("Using Google Default Application Credentials")

Review Comment:
   The logging statement uses the root logger without configuring a specific 
logger for this module. Consider using `logger = logging.getLogger(__name__)` 
at the module level and `logger.info()` instead for better logging practices.
   ```suggestion
               logger.info("Using Google Default Application Credentials")
   ```



##########
pyiceberg/catalog/rest/auth.py:
##########
@@ -119,6 +120,35 @@ def auth_header(self) -> str:
         return f"Bearer {self._token}"
 
 
+class GoogleAuthManager(AuthManager):
+    """An auth manager that is responsible for handling Google credentials."""
+
+    def __init__(self, credentials_path: Optional[str] = None, scopes: 
Optional[List[str]] = None):
+        """
+        Initialize GoogleAuthManager.
+
+        Args:
+            credentials_path: Optional path to Google credentials JSON file.
+            scopes: Optional list of OAuth2 scopes.
+        """
+        try:
+            import google.auth
+            import google.auth.transport.requests
+        except ImportError as e:
+            raise ImportError("Google Auth libraries not found. Please install 
'google-auth'.") from e
+
+        if credentials_path:
+            self.credentials, _ = 
google.auth.load_credentials_from_file(credentials_path, scopes=scopes)
+        else:
+            logging.info("Using Google Default Application Credentials")
+            self.credentials, _ = google.auth.default(scopes=scopes)
+        self._auth_request = google.auth.transport.requests.Request()
+
+    def auth_header(self) -> Optional[str]:

Review Comment:
   The return type annotation is `Optional[str]` but the method always returns 
a string (never None). This is inconsistent with the base class 
`AuthManager.auth_header()` which can return None. Consider changing the return 
type to `str` or handle potential cases where credentials might not be 
available.
   ```suggestion
       def auth_header(self) -> str:
   ```



-- 
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