Coverage for /pythoncovmergedfiles/medio/medio/src/airflow/airflow/security/permissions.py: 91%
54 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
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
19# Resource Constants
20RESOURCE_ACTION = "Permissions"
21RESOURCE_ADMIN_MENU = "Admin"
22RESOURCE_AIRFLOW = "Airflow"
23RESOURCE_AUDIT_LOG = "Audit Logs"
24RESOURCE_BROWSE_MENU = "Browse"
25RESOURCE_CONFIG = "Configurations"
26RESOURCE_CONNECTION = "Connections"
27RESOURCE_DAG = "DAGs"
28RESOURCE_DAG_CODE = "DAG Code"
29RESOURCE_DAG_DEPENDENCIES = "DAG Dependencies"
30RESOURCE_DAG_PREFIX = "DAG:"
31RESOURCE_DAG_RUN = "DAG Runs"
32RESOURCE_DAG_WARNING = "DAG Warnings"
33RESOURCE_CLUSTER_ACTIVITY = "Cluster Activity"
34RESOURCE_DATASET = "Datasets"
35RESOURCE_DOCS = "Documentation"
36RESOURCE_DOCS_MENU = "Docs"
37RESOURCE_IMPORT_ERROR = "ImportError"
38RESOURCE_JOB = "Jobs"
39RESOURCE_LOGIN = "Logins"
40RESOURCE_MY_PASSWORD = "My Password"
41RESOURCE_MY_PROFILE = "My Profile"
42RESOURCE_PASSWORD = "Passwords"
43RESOURCE_PERMISSION = "Permission Views" # Refers to a Perm <-> View mapping, not an MVC View.
44RESOURCE_PLUGIN = "Plugins"
45RESOURCE_POOL = "Pools"
46RESOURCE_PROVIDER = "Providers"
47RESOURCE_RESOURCE = "View Menus"
48RESOURCE_ROLE = "Roles"
49RESOURCE_SLA_MISS = "SLA Misses"
50RESOURCE_TASK_INSTANCE = "Task Instances"
51RESOURCE_TASK_LOG = "Task Logs"
52RESOURCE_TASK_RESCHEDULE = "Task Reschedules"
53RESOURCE_TRIGGER = "Triggers"
54RESOURCE_USER = "Users"
55RESOURCE_USER_STATS_CHART = "User Stats Chart"
56RESOURCE_VARIABLE = "Variables"
57RESOURCE_WEBSITE = "Website"
58RESOURCE_XCOM = "XComs"
60# Action Constants
61ACTION_CAN_CREATE = "can_create"
62ACTION_CAN_READ = "can_read"
63ACTION_CAN_EDIT = "can_edit"
64ACTION_CAN_DELETE = "can_delete"
65ACTION_CAN_ACCESS_MENU = "menu_access"
66DEPRECATED_ACTION_CAN_DAG_READ = "can_dag_read"
67DEPRECATED_ACTION_CAN_DAG_EDIT = "can_dag_edit"
69DAG_ACTIONS = {ACTION_CAN_READ, ACTION_CAN_EDIT, ACTION_CAN_DELETE}
72def resource_name_for_dag(root_dag_id: str) -> str:
73 """Returns the resource name for a DAG id.
75 Note that since a sub-DAG should follow the permission of its
76 parent DAG, you should pass ``DagModel.root_dag_id`` to this function,
77 for a subdag. A normal dag should pass the ``DagModel.dag_id``.
78 """
79 if root_dag_id == RESOURCE_DAG:
80 return root_dag_id
81 if root_dag_id.startswith(RESOURCE_DAG_PREFIX):
82 return root_dag_id
83 return f"{RESOURCE_DAG_PREFIX}{root_dag_id}"