Advanced on v2 api for actor 3.0

This commit is contained in:
Adolfo Gómez García 2019-12-01 13:32:17 +01:00
parent 371cc3d14b
commit d53d092483
2 changed files with 31 additions and 6 deletions

View File

@ -111,7 +111,16 @@ class CommonService:
if self._cfg.own_token and self._interfaces: if self._cfg.own_token and self._interfaces:
srvInterface = self.serviceInterfaceInfo() srvInterface = self.serviceInterfaceInfo()
if srvInterface: if srvInterface:
# Rery while RESTConnectionError (that is, cannot connect)
while self._isAlive:
try:
self._api.ready(self._cfg.own_token, self._secret, srvInterface.ip) self._api.ready(self._cfg.own_token, self._secret, srvInterface.ip)
except rest.RESTConnectionError:
self.doWait(5000)
continue
# Success or any error that is not recoverable (retunerd by UDS). if Error, service will be cleaned in a while.
break
else: else:
logger.error('Could not locate IP address!!!. (Not registered with UDS)') logger.error('Could not locate IP address!!!. (Not registered with UDS)')

View File

@ -38,11 +38,13 @@ from uds.models import (
getSqlDatetimeAsUnix, getSqlDatetimeAsUnix,
getSqlDatetime, getSqlDatetime,
ActorToken, ActorToken,
UserService UserService,
TicketStore
) )
#from uds.core import VERSION #from uds.core import VERSION
from uds.core.managers import userServiceManager from uds.core.managers import userServiceManager
from uds.core.util import log
from uds.core.util.state import State from uds.core.util.state import State
from uds.core.util.cache import Cache from uds.core.util.cache import Cache
from uds.core.util.config import GlobalConfig from uds.core.util.config import GlobalConfig
@ -111,9 +113,8 @@ class ActorV2Action(Handler):
except BlockAccess: except BlockAccess:
# For blocking attacks # For blocking attacks
incFailedIp(self._request.ip) # pylint: disable=protected-access incFailedIp(self._request.ip) # pylint: disable=protected-access
except Exception: except Exception as e:
logger.exception('Posting') logger.exception('Posting %s: %s', self.__class__, e)
pass
raise AccessDenied('Access denied') raise AccessDenied('Access denied')
@ -294,6 +295,12 @@ class ActorV2Logout(ActorV2Action):
def action(self) -> typing.MutableMapping[str, typing.Any]: def action(self) -> typing.MutableMapping[str, typing.Any]:
logger.debug('Args: %s, Params: %s', self._args, self._params) logger.debug('Args: %s, Params: %s', self._args, self._params)
userService = self.getUserService()
osManager = userService.getOsManagerInstance()
if osManager:
osManager.loggedOut(userService, self._params.get('username') or '')
osManager.processUnused(userService)
return ActorV2Action.actorResult('ok') return ActorV2Action.actorResult('ok')
class ActorV2Log(ActorV2Action): class ActorV2Log(ActorV2Action):
@ -304,6 +311,9 @@ class ActorV2Log(ActorV2Action):
def action(self) -> typing.MutableMapping[str, typing.Any]: def action(self) -> typing.MutableMapping[str, typing.Any]:
logger.debug('Args: %s, Params: %s', self._args, self._params) logger.debug('Args: %s, Params: %s', self._args, self._params)
userService = self.getUserService()
log.doLog(userService, int(self._params['level'])* 1000, self._params['message'], log.ACTOR)
return ActorV2Action.actorResult('ok') return ActorV2Action.actorResult('ok')
class ActorV2Ticket(ActorV2Action): class ActorV2Ticket(ActorV2Action):
@ -314,12 +324,17 @@ class ActorV2Ticket(ActorV2Action):
def action(self) -> typing.MutableMapping[str, typing.Any]: def action(self) -> typing.MutableMapping[str, typing.Any]:
logger.debug('Args: %s, Params: %s', self._args, self._params) logger.debug('Args: %s, Params: %s', self._args, self._params)
return ActorV2Action.actorResult('ok')
try:
return ActorV2Action.actorResult(TicketStore.get(self._params['ticket'], invalidate=True))
except TicketStore.DoesNotExist:
raise BlockAccess() # If too many blocks...
class ActorV2Notify(ActorV2Action): class ActorV2Notify(ActorV2Action):
name = 'notify' name = 'notify'
def post(self) -> typing.MutableMapping[str, typing.Any]: def post(self) -> typing.MutableMapping[str, typing.Any]:
# Raplaces original post (non existent here)
raise AccessDenied('Access denied') raise AccessDenied('Access denied')
def get(self) -> typing.MutableMapping[str, typing.Any]: def get(self) -> typing.MutableMapping[str, typing.Any]:
@ -329,6 +344,7 @@ class ActorV2Notify(ActorV2Action):
raise RequestError('Invalid parameters') raise RequestError('Invalid parameters')
try: try:
# Check block manually
checkBlockedIp(self._request.ip) # pylint: disable=protected-access checkBlockedIp(self._request.ip) # pylint: disable=protected-access
userService = UserService.objects.get(uuid=self._params['token']) userService = UserService.objects.get(uuid=self._params['token'])
# TODO: finish this # TODO: finish this