Commit ca3d7553 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Implement handling of credentials from the client

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