Commit ca3d7553 authored by Lukas Burgey's avatar Lukas Burgey

Implement handling of credentials from the client

parent 179c1bb1
......@@ -219,7 +219,6 @@ def topic_endpoint(request):
if service_name == service.name:
return ALLOW
elif name == 'sites':
LOGGER.debug(routing_key)
if routing_key == user.site.name:
return ALLOW
else:
......
......@@ -58,7 +58,8 @@ class ResponseView(views.APIView):
authentication_classes = AUTHENTICATION_CLASSES
def post(self, request):
status = request.data['output']['status']
output = request.data['output']
status = output['status']
task_id = request.data['id']
LOGGER.debug('%s responded to task %s:\n%s', request.user, task_id, request.data)
......@@ -71,16 +72,21 @@ class ResponseView(views.APIView):
if task_item is not None:
if status == 'success':
task_item.done()
return Response({'ok': True})
task_item.success(
credentials=request.data.output.get('credentials', None),
)
return Response({})
elif status == 'fail':
task_item.failed()
return Response({'ok': True})
return Response({})
elif status == 'reject':
task_item.rejected(request.data['output']['questionnaire'])
return Response({'ok': True})
task_item.rejected(output['questionnaire'])
return Response({})
LOGGER.info('%s executed the obsolete task#%s', request.user, task_id)
return Response({'ok': False})
return Response(
data={'error': 'obsolete_task'},
status=500,
)
......@@ -839,6 +839,9 @@ class DeploymentTask(models.Model):
def questionnaire_default():
return {}
def credential_default():
return {}
# DeploymentTaskItem: knows:
# user, service, key, action, _and_ site
class DeploymentTaskItem(models.Model):
......@@ -877,6 +880,12 @@ class DeploymentTaskItem(models.Model):
blank=True,
)
credentials = JSONField(
default=credential_default,
null=True,
blank=True,
)
@property
def service(self):
return self.task.service
......@@ -890,14 +899,19 @@ class DeploymentTaskItem(models.Model):
return self.deployment.key
# the client acked the receipt and execution of the task for his site
def success(self):
def success(self, credentials=None):
task = self.task
self.credentials = credentials
self.save()
LOGGER.debug(self.msg('success'))
self.delete()
# TODO test: does not deleting the task item work?
# self.delete()
task.send_state_update()
task.try_finished()
# TODO test: does not deleting the task work?
#task.try_finished()
# the user changed the deployment
# chancel (delete) this task item
......@@ -963,7 +977,6 @@ class DeploymentTaskItem(models.Model):
return '[Depl. TaskItem:{}] {}'.format(self, msg)
#
# RECEIVERS
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment