forked from shaba/openuds
added status checker to web API
This commit is contained in:
parent
2a2a2b2ad0
commit
87c2ea8add
@ -104,7 +104,9 @@ urlpatterns = [
|
||||
re_path(r'^uds/webapi/img/transport/(?P<idTrans>[a-zA-Z0-9:-]+)$', uds.web.views.transportIcon, name='webapi.transportIcon'),
|
||||
re_path(r'^uds/webapi/img/gallery/(?P<idImage>[a-zA-Z0-9-]+)$', uds.web.views.image, name='webapi.galleryImage'),
|
||||
|
||||
# Enabler and Status action are first processed, and if not match, execute the generic "action" handler
|
||||
re_path(r'^uds/webapi/action/(?P<idService>.+)/enable/(?P<idTransport>[a-zA-Z0-9:-]+)$', uds.web.views.userServiceEnabler, name='webapi.enabler'),
|
||||
re_path(r'^uds/webapi/action/(?P<idService>.+)/status/(?P<idTransport>[a-zA-Z0-9:-]+)$', uds.web.views.userServiceStatus, name='webapi.status'),
|
||||
|
||||
re_path(r'^uds/webapi/action/(?P<idService>.+)/(?P<actionString>[a-zA-Z0-9:-]+)$', uds.web.views.action, name='webapi.action'),
|
||||
|
||||
|
@ -153,6 +153,7 @@ def udsJs(request: 'ExtendedHttpRequest') -> str:
|
||||
'customAuth': reverse('uds.web.views.customAuth', kwargs={'idAuth': ''}),
|
||||
'services': reverse('webapi.services'),
|
||||
'enabler': reverse('webapi.enabler', kwargs={'idService': 'param1', 'idTransport': 'param2'}),
|
||||
'status': reverse('webapi.status', kwargs={'idService': 'param1', 'idTransport': 'param2'}),
|
||||
'action': reverse('webapi.action', kwargs={'idService': 'param1', 'actionString': 'param2'}),
|
||||
'galleryImage': reverse('webapi.galleryImage', kwargs={'idImage': 'param1'}),
|
||||
'transportIcon': reverse('webapi.transportIcon', kwargs={'idTrans': 'param1'}),
|
||||
|
@ -33,7 +33,7 @@ import logging
|
||||
|
||||
# from .login import login, logout
|
||||
from uds.web.util.errors import error
|
||||
from .service import transportOwnLink, transportIcon, userServiceEnabler, serviceImage, action
|
||||
from .service import transportOwnLink, transportIcon, userServiceEnabler, userServiceStatus, serviceImage, action
|
||||
from .auth import authCallback, authCallback_stage2, authInfo, ticketAuth, customAuth
|
||||
from .download import download
|
||||
from .images import image
|
||||
|
@ -107,7 +107,7 @@ def logout(request: ExtendedHttpRequestWithUser) -> HttpResponse:
|
||||
return auth.webLogout(request, logoutUrl)
|
||||
|
||||
|
||||
def js(request: HttpRequest) -> HttpResponse:
|
||||
def js(request: ExtendedHttpRequest) -> HttpResponse:
|
||||
return HttpResponse(content=configjs.udsJs(request), content_type='application/javascript')
|
||||
|
||||
|
||||
|
@ -103,7 +103,9 @@ def transportIcon(request: 'ExtendedHttpRequest', idTrans: str) -> HttpResponse:
|
||||
transport: Transport
|
||||
if idTrans[:6] == 'LABEL:':
|
||||
# Get First label
|
||||
transport = Transport.objects.filter(label=idTrans[6:]).order_by('priority')[0]
|
||||
transport = Transport.objects.filter(label=idTrans[6:]).order_by(
|
||||
'priority'
|
||||
)[0]
|
||||
else:
|
||||
transport = Transport.objects.get(uuid=processUuid(idTrans))
|
||||
return HttpResponse(transport.getInstance().icon(), content_type='image/png')
|
||||
@ -190,6 +192,38 @@ def closer(request: 'ExtendedHttpRequest') -> HttpResponse:
|
||||
return HttpResponse('<html><body onload="window.close()"></body></html>')
|
||||
|
||||
|
||||
@webLoginRequired(admin=False)
|
||||
@never_cache
|
||||
def userServiceStatus(
|
||||
request: 'ExtendedHttpRequestWithUser', idService: str, idTransport: str
|
||||
) -> HttpResponse:
|
||||
'''
|
||||
Returns 'running' if not ready, or 'ready' if ready (as json)
|
||||
'''
|
||||
ip: typing.Union[str, None, bool]
|
||||
try:
|
||||
(
|
||||
ip,
|
||||
userService,
|
||||
userServiceInstance,
|
||||
transport,
|
||||
transportInstance,
|
||||
) = userServiceManager().getService(
|
||||
request.user, request.os, request.ip, idService, idTransport, doTest=True
|
||||
)
|
||||
# logger.debug('Res: %s %s %s %s %s', ip, userService, userServiceInstance, transport, transportInstance)
|
||||
except ServiceNotReadyError:
|
||||
ip = None
|
||||
except Exception as e:
|
||||
ip = False
|
||||
|
||||
status = 'running' if ip is None else 'error' if ip is False else 'ready'
|
||||
|
||||
return HttpResponse(
|
||||
json.dumps({'status': status}), content_type='application/json'
|
||||
)
|
||||
|
||||
|
||||
@webLoginRequired(admin=False)
|
||||
@never_cache
|
||||
def action(
|
||||
|
Loading…
Reference in New Issue
Block a user