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 2020/08/19 20:11:59 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #10409: WIP: Add permission controls to new API.

mik-laj commented on a change in pull request #10409:
URL: https://github.com/apache/airflow/pull/10409#discussion_r473290872



##########
File path: airflow/api_connexion/security.py
##########
@@ -35,3 +35,23 @@ def decorated(*args, **kwargs):
         return function(*args, **kwargs)
 
     return cast(T, decorated)
+
+
+def requires_access(permissions: Sequence[Tuple[str, str]]) -> Callable[[T], T]:
+    """
+    Factory for decorator that checks current user's permissions against required permissions.
+    """
+
+    def requires_access_decorator(func: T):
+        @wraps(func)
+        def wrapped_function(*args, **kwargs):
+            appbuilder = current_app.appbuilder
+            for permission in permissions:
+                if not appbuilder.sm.has_access(*permission):
+                    return Response("Forbidden", 403)

Review comment:
       ```suggestion
                       raise PermissionDenied("Forbidden", 403)
   ```
   It returns a [Problem Details](https://tools.ietf.org/html/draft-ietf-appsawg-http-problem-00) error response




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