Coverage for /pythoncovmergedfiles/medio/medio/src/airflow/airflow/security/permissions.py: 91%
53 statements
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +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_DAG = "DAGs"
26RESOURCE_DAG_PREFIX = "DAG:"
27RESOURCE_LOGIN = "Logins"
28RESOURCE_DOCS_MENU = "Docs"
29RESOURCE_DOCS = "Documentation"
30RESOURCE_CONFIG = "Configurations"
31RESOURCE_CONNECTION = "Connections"
32RESOURCE_DAG_DEPENDENCIES = "DAG Dependencies"
33RESOURCE_DAG_CODE = "DAG Code"
34RESOURCE_DAG_RUN = "DAG Runs"
35RESOURCE_IMPORT_ERROR = "ImportError"
36RESOURCE_DAG_WARNING = "DAG Warnings"
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_POOL = "Pools"
43RESOURCE_PLUGIN = "Plugins"
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"
57RESOURCE_DATASET = "Datasets"
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}"