Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support add_auth, digest acl #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions aiozk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ async def exists(self, path, watch=False):
return False
return True

async def add_auth(self, scheme, auth):
"""
@scheme: world auth digest ip
@auth: according by @scheme
@return: True/False
"""
try:
await self.send(protocol.AuthRequest(type=0, scheme=scheme, auth=auth))
except Exception:
return False
return True

async def create(
self,
path,
Expand Down
13 changes: 13 additions & 0 deletions aiozk/protocol/acl.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import hashlib
from base64 import b64encode
from .request import Request
from .response import Response
from .part import Part
from .stat import Stat
from .primitives import UString, Int, Vector


def make_digest_acl_credential(username, password):
"""Create a SHA1 digest credential"""
credential = username.encode('utf-8') + b":" + password.encode('utf-8')
cred_hash = b64encode(hashlib.sha1(credential).digest()).strip()
return username + ":" + cred_hash.decode('utf-8')


class ID(Part):
"""
"""
Expand Down Expand Up @@ -69,6 +78,10 @@ def set_perms(self, read, write, create, delete, admin):
read=True, write=True, create=True, delete=True, admin=True
)

DIGEST_ACCESS = lambda username, password: ACL.make(
scheme="digest", id=make_digest_acl_credential(username, password),
read=True, write=True, create=True, delete=True, admin=True
)

class GetACLRequest(Request):
"""
Expand Down