You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/07/25 19:45:29 UTC

[GitHub] [airflow] Taragolis commented on a diff in pull request #25256: Resolve and validate AWS Connection parameters in wrapper

Taragolis commented on code in PR #25256:
URL: https://github.com/apache/airflow/pull/25256#discussion_r929238315


##########
airflow/providers/amazon/aws/hooks/base_aws.py:
##########
@@ -151,38 +135,31 @@ def _create_session_with_assume_role(self, session_kwargs: Dict[str, Any]) -> bo
                 refresh_using=self._refresh_credentials,
                 method="sts-assume-role",
             )
+
         session = botocore.session.get_session()
         session._credentials = credentials
-
-        if self.basic_session is None:
-            raise RuntimeError("The basic session should be created here!")
-
         region_name = self.basic_session.region_name
         session.set_config_variable("region", region_name)
 
         return boto3.session.Session(botocore_session=session, **session_kwargs)
 
     def _refresh_credentials(self) -> Dict[str, Any]:
         self.log.debug('Refreshing credentials')
-        assume_role_method = self.extra_config.get('assume_role_method', 'assume_role')
-        sts_session = self.basic_session
-
-        if sts_session is None:
-            raise RuntimeError(
-                "Session should be initialized when refresh credentials with assume_role is used!"
-            )
+        assume_role_method = self.conn.assume_role_method
+        if assume_role_method not in ('assume_role', 'assume_role_with_saml'):
+            raise NotImplementedError(f'assume_role_method={assume_role_method} not expected')
 
-        sts_client = sts_session.client("sts", config=self.config)
+        sts_client = self.basic_session.client("sts", config=self.config)
 
         if assume_role_method == 'assume_role':
             sts_response = self._assume_role(sts_client=sts_client)
-        elif assume_role_method == 'assume_role_with_saml':
-            sts_response = self._assume_role_with_saml(sts_client=sts_client)
         else:
-            raise NotImplementedError(f'assume_role_method={assume_role_method} not expected')

Review Comment:
   I've just move this check before obtain the session. 
   
   https://github.com/apache/airflow/blob/79279cf38337c4e3250bbb0a8f6bd31328b5f43d/airflow/providers/amazon/aws/hooks/base_aws.py#L149-L157
   
   Seems like it not possible that this exception raised. Only if user tried to use this private method inside their own SessionFactory.
   



-- 
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-unsubscribe@airflow.apache.org

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