https://opendal.apache.org/ logo
Python binding layer API
# general
b
Hi all! just exploring
opendal
a little bit (mostly the Python bindings), really interesting project! Was a bit confused about the API docs https://opendal.apache.org/docs/python/opendal.html which contains some APIs that I couldn't find on the latest release, such as
Operator.layer()
. My guess is that the API docs point to
main
branch instead of the latest release available on PyPI?
seems like it's the case, looking forward to the next release then 🙂
x
Yes, the api is not released yet.
b
Thank you! I was looking into layers because I wanted to know if it's the most appropriate way to add some authorization middleware based on a custom application/business logic.
x
Can you describe more detail about the authorization middleware? I feel like layer is not a good place for it since you will need to implement layer for all APIs.
b
I'm not sure what the
Layer
API would look like in Python, but I was thinking about having some custom access control layer. Here's a very quick draft of how I'm seeing it.
Copy code
python
from typing import Dict, List, Callable, Literal, Optional

import opendal
from opendal.layers import Layer

class AccessRule:
    def __init__(self, allowed_operations: List[Literal["read", "write"]], condition: Optional[Callable] = None): ...

class AccessControlLayer(Layer):
    def __init__(self, user_permissions: Dict[str, AccessRule]): ...

access_rules = {
    "user1": AccessRule(["read", "write"]),
    "user2": AccessRule(["read"], condition=lambda user, op, path: path.startswith("/public/"))
}
acl_layer = AccessControlLayer(access_rules)
op = opendal.Operator("fs", root="/data").layer(acl_layer)
after making this draft, I tend to agree with you that it's probably not the best place for it.