vincbeck commented on PR #35000:
URL: https://github.com/apache/airflow/pull/35000#issuecomment-1768750213

   > I wonder if we can refactor the giant if-elif chain into a dispatching 
dict. Something like…
   > 
   > ```python
   > @cache
   > def _get_auth_manager_map() -> dict[str, Callable[[str, BaseUser | None]]]:
   >     manager = get_auth_manager()
   >     actions = get_method_from_fab_action_map()
   >     return {
   >         RESOURCE_AUDIT_LOG: lambda action, user: manager.is_authorized_dag(
   >             method=actions[action], 
access_entity=DagAccessEntity.AUDIT_LOG, user=user,
   >         ),
   >         RESOURCE_CLUSTER_ACTIVITY: lambda action, user: 
manager.is_authorized_view(
   >             access_view=AccessView.CLUSTER_ACTIVITY, user=user,
   >         ),
   >         ...
   >     }
   > 
   > class AirflowSecirutyManagerV2(...):
   >     def _get_auth_manager_is_authorized_method(
   >         self, fab_action_name: str, fab_resource_name: str, user
   >     ) -> Callable[[str, BaseUser | None]] | None:
   >         return _get_auth_manager_map().get(fab_resource_name)
   > ```
   > 
   > This could be easier to read (?) and also margianlly faster.
   
   Agree, nice suggestion! Let me do that


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

Reply via email to