mirror of
https://github.com/dkmstr/openuds.git
synced 2025-11-10 08:24:12 +03:00
Refactoring for mypy complains... most of them are weird :S
This commit is contained in:
@@ -107,22 +107,22 @@ async def request_pools(session: aiohttp.ClientSession) -> list[collections.abc.
|
||||
async def request_ticket(
|
||||
session: aiohttp.ClientSession,
|
||||
username: str,
|
||||
authSmallName: str,
|
||||
auth_label: str,
|
||||
groups: typing.Union[list[str], str],
|
||||
servicePool: str,
|
||||
realName: typing.Optional[str] = None,
|
||||
servicepool: str,
|
||||
real_name: typing.Optional[str] = None,
|
||||
transport: typing.Optional[str] = None,
|
||||
force: bool = False
|
||||
) -> collections.abc.MutableMapping[str, typing.Any]:
|
||||
data = {
|
||||
'username': username,
|
||||
'authSmallName': authSmallName,
|
||||
'authSmallName': auth_label,
|
||||
'groups': groups,
|
||||
'servicePool': servicePool,
|
||||
'servicePool': servicepool,
|
||||
'force': 'true' if force else 'false'
|
||||
}
|
||||
if realName:
|
||||
data['realname'] = realName
|
||||
if real_name:
|
||||
data['realname'] = real_name
|
||||
if transport:
|
||||
data['transport'] = transport
|
||||
response = await session.put(
|
||||
@@ -145,10 +145,10 @@ async def main():
|
||||
ticket = await request_ticket(
|
||||
session=session,
|
||||
username='adolfo',
|
||||
authSmallName='172.27.0.1:8000',
|
||||
auth_label='172.27.0.1:8000',
|
||||
groups=['adolfo', 'dkmaster'],
|
||||
servicePool='6201b357-c4cd-5463-891e-71441a25faee',
|
||||
realName='Adolfo Gómez',
|
||||
servicepool='6201b357-c4cd-5463-891e-71441a25faee',
|
||||
real_name='Adolfo Gómez',
|
||||
force=True
|
||||
)
|
||||
print(ticket)
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
Author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
import typing
|
||||
import collections.abc
|
||||
import requests
|
||||
import argparse
|
||||
import socket
|
||||
@@ -52,7 +51,7 @@ class LogoutException(RESTException):
|
||||
pass
|
||||
|
||||
|
||||
def registerWithBroker(
|
||||
def register_with_broker(
|
||||
auth_uuid: str,
|
||||
username: str,
|
||||
password: str,
|
||||
@@ -151,7 +150,7 @@ def main():
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
token = registerWithBroker(
|
||||
token = register_with_broker(
|
||||
auth_uuid=args.auth_uuid,
|
||||
username=args.username,
|
||||
password=args.password,
|
||||
|
||||
@@ -806,7 +806,7 @@ class Unmanaged(ActorV3Action):
|
||||
# Retrieve real service from token alias
|
||||
dbservice = ServiceTokenAlias.objects.get(alias=token).service
|
||||
else:
|
||||
dbservice: Service = Service.objects.get(token=token)
|
||||
dbservice = Service.objects.get(token=token)
|
||||
service: 'services.Service' = dbservice.get_instance()
|
||||
except Exception:
|
||||
logger.exception('Unmanaged host request: %s', self._params)
|
||||
|
||||
@@ -195,9 +195,9 @@ class AssignedService(DetailHandler):
|
||||
def get_logs(self, parent: 'Model', item: str) -> list[typing.Any]:
|
||||
parent = ensure.is_instance(parent, models.ServicePool)
|
||||
try:
|
||||
userService: models.UserService = parent.assigned_user_services().get(uuid=process_uuid(item))
|
||||
logger.debug('Getting logs for %s', userService)
|
||||
return log.get_logs(userService)
|
||||
user_service: models.UserService = parent.assigned_user_services().get(uuid=process_uuid(item))
|
||||
logger.debug('Getting logs for %s', user_service)
|
||||
return log.get_logs(user_service)
|
||||
except Exception as e:
|
||||
raise self.invalid_item_response() from e
|
||||
|
||||
@@ -206,9 +206,9 @@ class AssignedService(DetailHandler):
|
||||
parent = ensure.is_instance(parent, models.ServicePool)
|
||||
try:
|
||||
if cache:
|
||||
userservice: models.UserService = parent.cached_users_services().get(uuid=process_uuid(item))
|
||||
userservice = parent.cached_users_services().get(uuid=process_uuid(item))
|
||||
else:
|
||||
userservice: models.UserService = parent.assigned_user_services().get(uuid=process_uuid(item))
|
||||
userservice = parent.assigned_user_services().get(uuid=process_uuid(item))
|
||||
except Exception as e:
|
||||
logger.exception('delete_item')
|
||||
raise self.invalid_item_response() from e
|
||||
|
||||
@@ -201,7 +201,7 @@ class RadiusAuth(auths.Authenticator):
|
||||
def test(env: 'environment.Environment', data: 'types.core.ValuesType') -> 'types.core.TestResult':
|
||||
"""Test the connection to the server ."""
|
||||
try:
|
||||
auth = RadiusAuth(env, data) # type: ignore
|
||||
auth = RadiusAuth(env, data)
|
||||
return auth.test_connection()
|
||||
except Exception as e:
|
||||
logger.error("Exception found testing Radius auth %s: %s", e.__class__, e)
|
||||
|
||||
@@ -451,7 +451,7 @@ class RegexLdap(auths.Authenticator):
|
||||
@staticmethod
|
||||
def test(env: 'environment.Environment', data: 'types.core.ValuesType') -> 'types.core.TestResult':
|
||||
try:
|
||||
auth = RegexLdap(env, data) # type: ignore # Regexldap does not use "dbAuth", so it's safe...
|
||||
auth = RegexLdap(env, data)
|
||||
return auth.test_connection()
|
||||
except Exception as e:
|
||||
logger.error('Exception found testing Simple LDAP auth %s: %s', e.__class__, e)
|
||||
|
||||
@@ -469,7 +469,7 @@ class SimpleLDAPAuthenticator(auths.Authenticator):
|
||||
@staticmethod
|
||||
def test(env: 'environment.Environment', data: 'types.core.ValuesType') -> 'types.core.TestResult':
|
||||
try:
|
||||
auth = SimpleLDAPAuthenticator(env, data) # type: ignore
|
||||
auth = SimpleLDAPAuthenticator(env, data)
|
||||
return auth.test_connection()
|
||||
except Exception as e:
|
||||
logger.error("Exception found testing Simple LDAP auth: %s", e)
|
||||
|
||||
@@ -99,6 +99,7 @@ class Image(UUIDModel):
|
||||
|
||||
@staticmethod
|
||||
def prepare_for_db(data: bytes) -> tuple[int, int, bytes]:
|
||||
image: PIL.Image.Image
|
||||
try:
|
||||
stream = io.BytesIO(data)
|
||||
image = PIL.Image.open(stream)
|
||||
|
||||
@@ -68,6 +68,7 @@ class StatsCountersAccum(models.Model):
|
||||
raise ValueError('No previous interval for HOUR')
|
||||
case self.DAY:
|
||||
return StatsCountersAccum.IntervalType.HOUR
|
||||
raise ValueError('Invalid interval type')
|
||||
|
||||
def is_base_interval(self) -> bool:
|
||||
"""Returns if this is the base interval"""
|
||||
|
||||
@@ -44,7 +44,7 @@ from .linux_osmanager import LinuxOsManager
|
||||
from .linux_randompass_osmanager import LinuxRandomPassManager
|
||||
from .linux_ad_osmanager import LinuxOsADManager
|
||||
|
||||
_mypath = os.path.dirname(__spec__.origin) # type: ignore[name-defined] # mypy incorrectly report __spec__ as not beind defined
|
||||
_mypath: typing.Final[str] = os.path.dirname(__spec__.origin) # type: ignore[type-var, assignment] # mypy has some problem with dirname??
|
||||
# Old version, using spec is better, but we can use __package__ as well
|
||||
#_mypath = os.path.dirname(typing.cast(str, sys.modules[__package__].__file__)) # pyright: ignore
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
Author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
# pyright: reportUnusedImport=false
|
||||
import typing
|
||||
import os.path
|
||||
|
||||
from django.utils.translation import gettext_noop as _
|
||||
@@ -42,9 +43,9 @@ from .windows import WindowsOsManager
|
||||
from .windows_domain import WinDomainOsManager
|
||||
from .windows_random import WinRandomPassManager
|
||||
|
||||
_mypath = os.path.dirname(__spec__.origin) # type: ignore[name-defined] # mypy incorrectly report __spec__ as not beind defined
|
||||
_mypath: typing.Final[str] = os.path.dirname(__spec__.origin) # type: ignore[type-var, assignment] # mypy has some problem with dirname??
|
||||
# Old version, using spec is better, but we can use __package__ as well
|
||||
#_mypath = os.path.dirname(typing.cast(str, sys.modules[__package__].__file__)) # pyright: ignore
|
||||
# _mypath = os.path.dirname(typing.cast(str, sys.modules[__package__].__file__)) # pyright: ignore
|
||||
|
||||
|
||||
managers.downloads_manager().register(
|
||||
|
||||
Reference in New Issue
Block a user