in userbeacon/views.py [0:0]
def put(self, request):
"""
the main endpoint. Expects an empty PUT request with valid bearer-token authentication
If we get this far, then the authentication class has already validated the token and
populated the request.user object
:return: either a 200 django response or a 500 indicating a VS error. No client feedback is given if the user
is actually created or not, for that see the logs
"""
from .vscommunicator import VSCommunicator, HttpError, HttpTimeoutError
if request is None:
logger.error("No request data? Something is badly wrong.")
return Response({"status":"server_error","detail":"no request data"}, status=500)
logger.info("Received beacon for login of {0}".format(request.user))
if not isinstance(request.user, User):
logger.warning("the provided user is not a User object, something weird is going on")
return Response({"status":"ok"})
comm = VSCommunicator()
user_create_required = True
try:
comm.do_get("/API/user/{0}".format(self.request.user.username))
logger.info("User {0} already exists in Vidispine".format(self.request.user.username))
#if we get here, then we got a 200 response and the user exists, happy times.
user_create_required = False
except HttpTimeoutError as e:
logger.error("Vidispine seems down! Timed out checking user: {0}".format(e))
return Response({"status":"error","detail":"Could not communicate with Vidispine"},status=500)
except HttpError as e:
if e.response_code==404:
#user does not exist, so we should create it
logger.info("User {0} does not exist in Vidispine, creating".format(self.request.user.username))
user_create_required = True
else:
logger.error("Could not communicate with Vidispine: {0}".format(e))
logger.error("Error response was {0}".format(e.response_body))
return Response({"status":"error","detail":"Could not communicate with Vidispine"},status=500)
if user_create_required:
try:
self.create_vs_user(self.request.user, comm)
except HttpTimeoutError as e:
logger.error("Vidispine seems down! Timed out checking user: {0}".format(e))
return Response({"status":"error","detail":"Could not communicate with Vidispine"},status=500)
except HttpError as e:
logger.error("Could not communicate with Vidispine: {0}".format(e))
logger.error("Error response was {0}".format(e.response_body))
return Response({"status":"error","detail":"Could not communicate with Vidispine"},status=500)
except json.decoder.JSONDecodeError: #does not matter if the body fails to parse, we are not interested (spec says it is empty)
pass
try:
self.set_import_acl(self.request.user.username, comm)
except HttpTimeoutError as e:
logger.error("Vidispine seems down! Timed out checking user: {0}".format(e))
return Response({"status":"error","detail":"Could not communicate with Vidispine"},status=500)
except HttpError as e:
logger.error("Could not communicate with Vidispine: {0}".format(e))
logger.error("Error response was {0}".format(e.response_body))
return Response({"status":"error","detail":"Could not communicate with Vidispine"},status=500)
except json.decoder.JSONDecodeError: #does not matter if the body fails to parse, we are not interested (spec says it is empty)
pass
return Response({"status":"ok"})