Coverage for /pythoncovmergedfiles/medio/medio/src/airflow/airflow/security/permissions.py: 90%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

52 statements  

1# Licensed to the Apache Software Foundation (ASF) under one 

2# or more contributor license agreements. See the NOTICE file 

3# distributed with this work for additional information 

4# regarding copyright ownership. The ASF licenses this file 

5# to you under the Apache License, Version 2.0 (the 

6# "License"); you may not use this file except in compliance 

7# with the License. You may obtain a copy of the License at 

8# 

9# http://www.apache.org/licenses/LICENSE-2.0 

10# 

11# Unless required by applicable law or agreed to in writing, 

12# software distributed under the License is distributed on an 

13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 

14# KIND, either express or implied. See the License for the 

15# specific language governing permissions and limitations 

16# under the License. 

17from __future__ import annotations 

18 

19# Resource Constants 

20RESOURCE_ACTION = "Permissions" 

21RESOURCE_ADMIN_MENU = "Admin" 

22RESOURCE_AUDIT_LOG = "Audit Logs" 

23RESOURCE_BROWSE_MENU = "Browse" 

24RESOURCE_CONFIG = "Configurations" 

25RESOURCE_CONNECTION = "Connections" 

26RESOURCE_DAG = "DAGs" 

27RESOURCE_DAG_CODE = "DAG Code" 

28RESOURCE_DAG_DEPENDENCIES = "DAG Dependencies" 

29RESOURCE_DAG_PREFIX = "DAG:" 

30RESOURCE_DAG_RUN = "DAG Runs" 

31RESOURCE_DAG_WARNING = "DAG Warnings" 

32RESOURCE_CLUSTER_ACTIVITY = "Cluster Activity" 

33RESOURCE_DATASET = "Datasets" 

34RESOURCE_DOCS = "Documentation" 

35RESOURCE_DOCS_MENU = "Docs" 

36RESOURCE_IMPORT_ERROR = "ImportError" 

37RESOURCE_JOB = "Jobs" 

38RESOURCE_MY_PASSWORD = "My Password" 

39RESOURCE_MY_PROFILE = "My Profile" 

40RESOURCE_PASSWORD = "Passwords" 

41RESOURCE_PERMISSION = "Permission Views" # Refers to a Perm <-> View mapping, not an MVC View. 

42RESOURCE_PLUGIN = "Plugins" 

43RESOURCE_POOL = "Pools" 

44RESOURCE_PROVIDER = "Providers" 

45RESOURCE_RESOURCE = "View Menus" 

46RESOURCE_ROLE = "Roles" 

47RESOURCE_SLA_MISS = "SLA Misses" 

48RESOURCE_TASK_INSTANCE = "Task Instances" 

49RESOURCE_TASK_LOG = "Task Logs" 

50RESOURCE_TASK_RESCHEDULE = "Task Reschedules" 

51RESOURCE_TRIGGER = "Triggers" 

52RESOURCE_USER = "Users" 

53RESOURCE_USER_STATS_CHART = "User Stats Chart" 

54RESOURCE_VARIABLE = "Variables" 

55RESOURCE_WEBSITE = "Website" 

56RESOURCE_XCOM = "XComs" 

57 

58# Action Constants 

59ACTION_CAN_CREATE = "can_create" 

60ACTION_CAN_READ = "can_read" 

61ACTION_CAN_EDIT = "can_edit" 

62ACTION_CAN_DELETE = "can_delete" 

63ACTION_CAN_ACCESS_MENU = "menu_access" 

64DEPRECATED_ACTION_CAN_DAG_READ = "can_dag_read" 

65DEPRECATED_ACTION_CAN_DAG_EDIT = "can_dag_edit" 

66 

67DAG_ACTIONS = {ACTION_CAN_READ, ACTION_CAN_EDIT, ACTION_CAN_DELETE} 

68 

69 

70def resource_name_for_dag(root_dag_id: str) -> str: 

71 """Return the resource name for a DAG id. 

72 

73 Note that since a sub-DAG should follow the permission of its 

74 parent DAG, you should pass ``DagModel.root_dag_id`` to this function, 

75 for a subdag. A normal dag should pass the ``DagModel.dag_id``. 

76 """ 

77 if root_dag_id == RESOURCE_DAG: 

78 return root_dag_id 

79 if root_dag_id.startswith(RESOURCE_DAG_PREFIX): 

80 return root_dag_id 

81 return f"{RESOURCE_DAG_PREFIX}{root_dag_id}"