fab.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing,
  13. # software distributed under the License is distributed on an
  14. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. # KIND, either express or implied. See the License for the
  16. # specific language governing permissions and limitations
  17. # under the License.
  18. from __future__ import annotations
  19. from typing import TYPE_CHECKING
  20. from airflow.security.permissions import (
  21. ACTION_CAN_ACCESS_MENU,
  22. ACTION_CAN_CREATE,
  23. ACTION_CAN_DELETE,
  24. ACTION_CAN_EDIT,
  25. ACTION_CAN_READ,
  26. )
  27. if TYPE_CHECKING:
  28. from airflow.auth.managers.base_auth_manager import ResourceMethod
  29. # Convert methods to FAB action name
  30. _MAP_METHOD_NAME_TO_FAB_ACTION_NAME: dict[ResourceMethod, str] = {
  31. "POST": ACTION_CAN_CREATE,
  32. "GET": ACTION_CAN_READ,
  33. "PUT": ACTION_CAN_EDIT,
  34. "DELETE": ACTION_CAN_DELETE,
  35. "MENU": ACTION_CAN_ACCESS_MENU,
  36. }
  37. def get_fab_action_from_method_map():
  38. """Return the map associating a method to a FAB action."""
  39. return _MAP_METHOD_NAME_TO_FAB_ACTION_NAME
  40. def get_method_from_fab_action_map():
  41. """Return the map associating a FAB action to a method."""
  42. return {
  43. **{v: k for k, v in _MAP_METHOD_NAME_TO_FAB_ACTION_NAME.items()},
  44. }