You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/03/08 14:44:11 UTC

[GitHub] [airflow] ephraimbuddy commented on a change in pull request #14664: Add readonly REST API endpoint for roles and permissions

ephraimbuddy commented on a change in pull request #14664:
URL: https://github.com/apache/airflow/pull/14664#discussion_r589473251



##########
File path: airflow/api_connexion/endpoints/role_and_permission_endpoint.py
##########
@@ -0,0 +1,91 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from flask import current_app
+from flask_appbuilder.security.sqla.models import (
+    Permission,
+    PermissionView,
+    Role,
+    User,
+    ViewMenu,
+    assoc_permissionview_role,
+    assoc_user_role,
+)
+from sqlalchemy import and_, func
+
+from airflow.api_connexion.exceptions import NotFound
+from airflow.api_connexion.schemas.role_and_permission_schema import (
+    ActionCollection,
+    RoleCollection,
+    action_collection_schema,
+    role_collection_item_schema,
+    role_collection_schema,
+)
+
+
+def get_role(role_name):
+    """Get role"""
+    ab_security_manager = current_app.appbuilder.sm
+    role = ab_security_manager.find_role(name=role_name)
+    if not role:
+        raise NotFound(title="Role not found", detail=f"The Role with name `{role_name}` was not found")
+    return role_collection_item_schema.dump(role)
+
+
+def get_roles(usernames=None, action_resource_ids=None, role_name=None, limit=None, offset=None):

Review comment:
       @mik-laj , I'm not sure the kind of filtering this endpoint will need. Please review and suggest. Thanks




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org