mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-25 23:21:41 +03:00
* Added better type checking on Handler
* Fixed exception of ticket store exception * Added initial nitification for unamanged
This commit is contained in:
parent
4f3792ced5
commit
a475d45b7b
@ -43,8 +43,8 @@ from uds.core.managers import cryptoManager
|
||||
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
from django.http import HttpRequest # pylint: disable=ungrouped-imports
|
||||
|
||||
from uds.core.util.request import ExtendedHttpRequest
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
AUTH_TOKEN_HEADER = 'HTTP_X_AUTH_TOKEN'
|
||||
@ -97,19 +97,20 @@ class Handler:
|
||||
needs_admin: typing.ClassVar[bool] = False # By default, the methods will be accessible by anyone if nothing else indicated
|
||||
needs_staff: typing.ClassVar[bool] = False # By default, staff
|
||||
|
||||
_request: 'HttpRequest'
|
||||
_request: 'ExtendedHttpRequest' # It's a modified HttpRequest
|
||||
_path: str
|
||||
_operation: str
|
||||
_params: typing.Any # This is a deserliazied object from request. Can be anything as 'a' or {'a': 1} or ....
|
||||
_args: typing.Tuple[str, ...] # This are the "path" split by /, that is, the REST invocation arguments
|
||||
_kwargs: typing.Dict
|
||||
_headers: typing.Dict[str, str]
|
||||
_session: typing.Optional[SessionStore]
|
||||
_authToken: typing.Optional[str]
|
||||
_user: 'User'
|
||||
|
||||
|
||||
# method names: 'get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'
|
||||
def __init__(self, request: 'HttpRequest', path: str, operation: str, params: typing.Any, *args: str, **kwargs):
|
||||
def __init__(self, request: 'ExtendedHttpRequest', path: str, operation: str, params: typing.Any, *args: str, **kwargs):
|
||||
|
||||
logger.debug('Data: %s %s %s', self.__class__, self.needs_admin, self.authenticated)
|
||||
if (self.needs_admin or self.needs_staff) and not self.authenticated: # If needs_admin, must also be authenticated
|
||||
@ -261,18 +262,21 @@ class Handler:
|
||||
Get REST session related value for a key
|
||||
"""
|
||||
try:
|
||||
return self._session['REST'].get(key)
|
||||
if self._session:
|
||||
return self._session['REST'].get(key)
|
||||
return None
|
||||
except Exception:
|
||||
return None # _session['REST'] does not exists?
|
||||
return None
|
||||
|
||||
def setValue(self, key: str, value: typing.Any) -> None:
|
||||
"""
|
||||
Set a session key value
|
||||
"""
|
||||
try:
|
||||
self._session['REST'][key] = value
|
||||
self._session.accessed = True
|
||||
self._session.save()
|
||||
if self._session:
|
||||
self._session['REST'][key] = value
|
||||
self._session.accessed = True
|
||||
self._session.save()
|
||||
except Exception:
|
||||
logger.exception('Got an exception setting session value %s to %s', key, value)
|
||||
|
||||
|
@ -430,14 +430,7 @@ class Login(LoginLogout):
|
||||
logger.debug('Login Args: %s, Params: %s', self._args, self._params)
|
||||
|
||||
try:
|
||||
userService: typing.Optional[UserService] = self.getUserService()
|
||||
except Exception: # If unamanaged host, lest do a bit more work looking for a service with the provided parameters...
|
||||
if isManaged:
|
||||
raise
|
||||
userService = None # Skip later processing userService
|
||||
self.notifyService(login=True)
|
||||
|
||||
if userService:
|
||||
userService: UserService = self.getUserService()
|
||||
osManager: typing.Optional[osmanagers.OSManager] = userService.getOsManagerInstance()
|
||||
if not userService.in_use: # If already logged in, do not add a second login (windows does this i.e.)
|
||||
osmanagers.OSManager.loggedIn(userService, self._params.get('username') or '')
|
||||
@ -448,6 +441,11 @@ class Login(LoginLogout):
|
||||
|
||||
ip, hostname = userService.getConnectionSource()
|
||||
deadLine = userService.deployed_service.getDeadline()
|
||||
except Exception: # If unamanaged host, lest do a bit more work looking for a service with the provided parameters...
|
||||
if isManaged:
|
||||
raise
|
||||
self.notifyService(login=True)
|
||||
|
||||
|
||||
return ActorV3Action.actorResult({
|
||||
'ip': ip,
|
||||
@ -468,14 +466,7 @@ class Logout(LoginLogout):
|
||||
|
||||
logger.debug('Args: %s, Params: %s', self._args, self._params)
|
||||
try:
|
||||
userService: typing.Optional[UserService] = self.getUserService()
|
||||
except Exception: # If unamanaged host, lest do a bit more work looking for a service with the provided parameters...
|
||||
if isManaged:
|
||||
raise
|
||||
userService = None # Skip later processing userService
|
||||
self.notifyService(login=False) # Logout notification
|
||||
|
||||
if userService:
|
||||
userService: UserService = self.getUserService()
|
||||
osManager: typing.Optional[osmanagers.OSManager] = userService.getOsManagerInstance()
|
||||
if userService.in_use: # If already logged out, do not add a second logout (windows does this i.e.)
|
||||
osmanagers.OSManager.loggedOut(userService, self._params.get('username') or '')
|
||||
@ -485,6 +476,10 @@ class Logout(LoginLogout):
|
||||
userService.remove()
|
||||
else:
|
||||
userService.remove()
|
||||
except Exception: # If unamanaged host, lest do a bit more work looking for a service with the provided parameters...
|
||||
if isManaged:
|
||||
raise
|
||||
self.notifyService(login=False) # Logout notification
|
||||
|
||||
return ActorV3Action.actorResult('ok')
|
||||
|
||||
@ -521,7 +516,7 @@ class Ticket(ActorV3Action):
|
||||
|
||||
try:
|
||||
return ActorV3Action.actorResult(TicketStore.get(self._params['ticket'], invalidate=True))
|
||||
except TicketStore.DoesNotExists:
|
||||
except TicketStore.DoesNotExist:
|
||||
return ActorV3Action.actorResult(error='Invalid ticket')
|
||||
|
||||
|
||||
@ -568,8 +563,11 @@ class Unmanaged(ActorV3Action):
|
||||
'server_certificate': certificate,
|
||||
'password': password
|
||||
}
|
||||
# Store certificate, secret & port with service if validId
|
||||
if validId:
|
||||
# Notify service of it "just start" action
|
||||
service.notifyInitialization(validId)
|
||||
|
||||
# Store certificate, secret & port with service if validId
|
||||
service.storeIdInfo(validId, {
|
||||
'cert': certificate,
|
||||
'secret': self._params['secret'],
|
||||
|
Loading…
Reference in New Issue
Block a user