m1racoli commented on code in PR #36849:
URL: https://github.com/apache/airflow/pull/36849#discussion_r1458846533


##########
airflow/providers/google/common/hooks/base_google.py:
##########
@@ -623,6 +628,51 @@ def test_connection(self):
         return status, message
 
 
+class CredentialsToken(Token):
+    """A token implementation which makes Google credentials objects 
accessible to [gcloud-aio](https://talkiq.github.io/gcloud-aio/) clients.
+
+    This class allows us to create token instances from credentials objects 
and thus supports a variety of use cases for Google
+    credentials in Airflow (i.e. impersonation chain). By relying on a 
existing credentials object we leverage functionality provided by the 
GoogleBaseHook
+    for generating credentials objects.
+    """
+
+    def __init__(
+        self,
+        credentials: Credentials,
+        *,
+        project: str | None = None,
+        session: ClientSession | None = None,
+    ) -> None:
+        super().__init__(session=cast(Session, session))
+        self.credentials = credentials
+        self.project = project
+
+    @classmethod
+    async def from_hook(
+        cls,
+        hook: GoogleBaseHook,
+        *,
+        session: ClientSession | None = None,
+    ) -> CredentialsToken:
+        credentials, project = hook.get_credentials_and_project_id()
+        return cls(
+            credentials=credentials,
+            project=project,
+            session=session,
+        )
+
+    async def get_project(self) -> str | None:
+        return self.project

Review Comment:
   I want to add, even if we pass the project to the clients, if the project is 
`None` then the clients rely on the project provided by the token instance, 
which itself relies on the hook's `get_credentials_and_project_id`. Which 
should be the desired outcome.



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to