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

First release #1

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

First release #1

wants to merge 11 commits into from

Conversation

KraPete
Copy link
Collaborator

@KraPete KraPete commented Jan 14, 2025

Сервис аутентификации и управления пользователями для Homeui

@KraPete KraPete requested a review from a team January 14, 2025 07:42
LICENSE Outdated
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022-2023 Wiren Board
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Copyright (c) 2022-2023 Wiren Board
Copyright (c) 2025 Wiren Board

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поменял

self.process_request({"users": delete_user_handler})


def main():
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может порт и базу аргументами?

from setuptools import setup


def get_version():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

понадежнее бы что-нибудь

предлагаю - или регексп
re.match(r"wb-homeui-auth \((?P<version>.*)\)", "wb-homeui-auth (1.0.0) stable; urgency=medium").group("version")

или вообще - subprocess и дебиан-тулзы
dpkg-parsechangelog --show-field Version

я за регексп

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сделал re, как Вова хотел

try:
decoded = jwt.decode(cookie, keys_storage.get_key(), algorithms=["HS256"])
return decoded.get("id")
except Exception:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

логгировать хотя бы?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Убрал обработку ошибки, теперь это падает в ответ 500 Internal Server Error

return ["Set-Cookie", f"id={user_id}; HttpOnly; SameSite=Lax;"]


def get_cookie_params_dict(params: str) -> dict:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вроде есть какаят стандартная парсилка куков

https://stackoverflow.com/questions/32281041/converting-cookie-string-into-python-dict

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я знаю, но раньше это всё запускалось отдельным скриптом через fcgiwrap, не хотел тащить зависимости, чтоб время загрузки скрипта уменьшить. Сейчас не важно, переделал на SimpleCookie

keys_storage: KeysStorage = None


def get_required_user_type(request: BaseHTTPRequestHandler) -> UserType:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

мб return UserType(request.headers.get("Required-User-Type", UserType.ADMIN) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я хотел, чтоб при неправильном типе пользователя тоже был админ, но чё-то сейчас подумал, что не надо. Пусть лучше будет 500 Internal Server Error

length = int(request.headers.get("Content-Length"))
form = json.loads(request.rfile.read(length).decode("utf-8"))
validate_login_request(form)
except Exception as e:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

логи?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Все ответы, которые не 200, идут через http.server.send_error, который по умолчанию в лог падает

USER = "user"

@dataclass
class User:
Copy link

@vdromanov vdromanov Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

как идея: можно здесь сделать все None по дефолту и убрать кучу проверок на is None выше

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тогда надо проверять содержимое User. Не, не хочу

@KraPete KraPete requested a review from vdromanov January 16, 2025 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants