From afcf6d8e021e0ff274e06829fd734d7e12a25989 Mon Sep 17 00:00:00 2001 From: Hugo Gomes Date: Thu, 21 Dec 2023 12:54:22 +0000 Subject: [PATCH] feat: add src/netius/auth --- src/netius/auth/address.pyi | 12 ++++++++++++ src/netius/auth/allow.pyi | 10 ++++++++++ src/netius/auth/base.pyi | 26 +++++++++++++++++++------- src/netius/auth/deny.pyi | 10 ++++++++++ src/netius/auth/dummy.pyi | 12 ++++++++++++ src/netius/auth/memory.pyi | 17 +++++++++++++++++ src/netius/auth/passwd.pyi | 12 ++++++++++++ src/netius/auth/simple.pyi | 10 ++++++++++ 8 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 src/netius/auth/address.pyi create mode 100644 src/netius/auth/allow.pyi create mode 100644 src/netius/auth/deny.pyi create mode 100644 src/netius/auth/dummy.pyi create mode 100644 src/netius/auth/memory.pyi create mode 100644 src/netius/auth/passwd.pyi create mode 100644 src/netius/auth/simple.pyi diff --git a/src/netius/auth/address.pyi b/src/netius/auth/address.pyi new file mode 100644 index 00000000..28165250 --- /dev/null +++ b/src/netius/auth/address.pyi @@ -0,0 +1,12 @@ +import netius.auth.base +import netius.auth.base as base + +from typing import Literal + +class AddressAuth(netius.auth.base.Auth): + def __init__(self, allowed: list = ..., *args, **kwargs) -> None: ... + @classmethod + def auth(cls, allowed: list = ..., *args, **kwargs) -> bool: ... + @classmethod + def is_simple(cls) -> Literal[True]: ... + def auth_i(self, *args, **kwargs): ... diff --git a/src/netius/auth/allow.pyi b/src/netius/auth/allow.pyi new file mode 100644 index 00000000..35c50d8d --- /dev/null +++ b/src/netius/auth/allow.pyi @@ -0,0 +1,10 @@ +import netius.auth.base +import netius.auth.base as base + +from typing import Literal + +class AllowAuth(netius.auth.base.Auth): + @classmethod + def auth(cls, *args, **kwargs) -> Literal[True]: ... + @classmethod + def is_simple(cls) -> Literal[True]: ... diff --git a/src/netius/auth/base.pyi b/src/netius/auth/base.pyi index 2581cdc7..21fdd9ad 100644 --- a/src/netius/auth/base.pyi +++ b/src/netius/auth/base.pyi @@ -1,13 +1,25 @@ -from typing import Literal +import netius as netius -HashType = Literal["plain", "md5", "sha1", "sha256", "sha512"] +from typing import Any, Literal, NoReturn, PathLike, Unbound -class Auth(object): +class Auth: + def __init__(self, *args, **kwargs) -> None: ... + @classmethod + def auth(cls, *args, **kwargs) -> NoReturn: ... + @classmethod + def meta(cls, *args, **kwargs) -> dict: ... + @classmethod + def auth_assert(cls, *args, **kwargs) -> None: ... @classmethod def verify(cls, encoded: str, decoded: str) -> bool: ... - @classmethod - def generate(cls, password: str, type: HashType = "sha256", salt: str = "netius") -> str: ... - + def generate(cls, password: str, type: str = ..., salt: str = ...) -> str: ... + @classmethod + def unpack(cls, password) -> tuple[Any | Literal["plain"], bytes | Any | str | None, Any | None, Unbound | Any | None]: ... + @classmethod + def get_file(cls, path: PathLike[str], cache: bool = ..., encoding: str | None = ...) -> (Any | str | bytes): ... @classmethod - def unpack(cls, password: str) -> tuple[HashType, str, str, str]: ... + def is_simple(cls) -> Literal[False]: ... + def auth_i(self, *args, **kwargs) -> NoReturn: ... + def auth_assert_i(self, *args, **kwargs) -> None: ... + def is_simple_i(self) -> Literal[False]: ... diff --git a/src/netius/auth/deny.pyi b/src/netius/auth/deny.pyi new file mode 100644 index 00000000..daf93966 --- /dev/null +++ b/src/netius/auth/deny.pyi @@ -0,0 +1,10 @@ +import netius.auth.base +import netius.auth.base as base + +from typing import Literal + +class DenyAuth(netius.auth.base.Auth): + @classmethod + def auth(cls, *args, **kwargs) -> Literal[False]: ... + @classmethod + def is_simple(cls) -> Literal[True]: ... diff --git a/src/netius/auth/dummy.pyi b/src/netius/auth/dummy.pyi new file mode 100644 index 00000000..d84fba13 --- /dev/null +++ b/src/netius/auth/dummy.pyi @@ -0,0 +1,12 @@ +import netius.auth.base +import netius.auth.base as base + +from typing import Literal + +class DummyAuth(netius.auth.base.Auth): + def __init__(self, value: bool = ..., *args, **kwargs) -> None: ... + @classmethod + def auth(cls, value: bool = ..., *args, **kwargs) -> bool: ... + @classmethod + def is_simple(cls) -> Literal[True]: ... + def auth_i(self, *args, **kwargs) -> bool: ... diff --git a/src/netius/auth/memory.pyi b/src/netius/auth/memory.pyi new file mode 100644 index 00000000..16819b92 --- /dev/null +++ b/src/netius/auth/memory.pyi @@ -0,0 +1,17 @@ +import netius as netius +import netius.auth.base +import netius.auth.base as base + +from typing import Dict + +class MemoryAuth(netius.auth.base.Auth): + def __init__(self, registry: Dict | None = ..., *args, **kwargs) -> None: ... + @classmethod + def auth(cls, username: str, password: str, registry: dict | None = ..., *args, **kwargs) -> bool: ... + @classmethod + def meta(cls, username: str, registry: Dict | None = ..., *args, **kwargs) -> Dict: ... + @classmethod + def get_registry(cls): ... + @classmethod + def load_registry(cls): ... + def auth_i(self, username: str, password: str, *args, **kwargs) -> bool: ... diff --git a/src/netius/auth/passwd.pyi b/src/netius/auth/passwd.pyi new file mode 100644 index 00000000..a87f15e5 --- /dev/null +++ b/src/netius/auth/passwd.pyi @@ -0,0 +1,12 @@ +import netius.auth.base +import netius.auth.base as base + +from typing import PathLike, Any, Dict + +class PasswdAuth(netius.auth.base.Auth): + def __init__(self, path: PathLike[str] | None = ..., *args, **kwargs) -> None: ... + @classmethod + def auth(cls, username: str, password: str, path: str = ..., *args, **kwargs) -> bool: ... + @classmethod + def get_passwd(cls, path: PathLike[str], cache: bool = ...) -> (Any | Dict): ... + def auth_i(self, username: str, password: str, *args, **kwargs) -> bool: ... diff --git a/src/netius/auth/simple.pyi b/src/netius/auth/simple.pyi new file mode 100644 index 00000000..b3692450 --- /dev/null +++ b/src/netius/auth/simple.pyi @@ -0,0 +1,10 @@ +import netius.auth.base +import netius.auth.base as base + +from typing import Tuple + +class SimpleAuth(netius.auth.base.Auth): + def __init__(self, username: str | None = ..., password: str | None = ..., *args, **kwargs) -> None: ... + @classmethod + def auth(cls, username: str, password: str, target: Tuple[str:str] | None = ..., *args, **kwargs) -> bool: ... + def auth_i(self, username:str , password: str, *args, **kwargs) -> bool: ...