-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Get interface to work using ApiHandler * Break apart into model file as well * Simplify
- Loading branch information
Showing
6 changed files
with
139 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""User group API. | ||
Figure out what access rights an account has. | ||
""" | ||
|
||
from dataclasses import dataclass | ||
|
||
from typing_extensions import Self | ||
|
||
from .api import ApiRequest, ApiResponse | ||
from .pwdgrp_cgi import User, UserGroupsT | ||
|
||
|
||
@dataclass | ||
class GetUserGroupRequest(ApiRequest): | ||
"""Request object for listing users.""" | ||
|
||
method = "get" | ||
path = "/axis-cgi/usergroup.cgi" | ||
content_type = "text/plain" | ||
|
||
|
||
@dataclass | ||
class GetUserGroupResponse(ApiResponse[dict[str, User]]): | ||
"""Response object for listing ports.""" | ||
|
||
@classmethod | ||
def decode(cls, bytes_data: bytes) -> Self: | ||
"""Prepare API description dictionary.""" | ||
data: list[str] = bytes_data.decode().splitlines() | ||
|
||
if len(data) == 0: | ||
return cls(data={}) | ||
|
||
group_list = [] | ||
if len(data) == 2: | ||
group_list = data[1].split() | ||
|
||
user: UserGroupsT = { | ||
"user": data[0], | ||
"admin": "admin" in group_list, | ||
"operator": "operator" in group_list, | ||
"viewer": "viewer" in group_list, | ||
"ptz": "ptz" in group_list, | ||
} | ||
return cls(data={"0": User.decode(user)}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.