2323__maintainer__ = "mundialis GmbH & Co. KG"
2424
2525import json
26- import requests
2726
28- from cloudevents . http import CloudEvent
27+ import requests
2928from cloudevents .conversion import to_binary
29+ from cloudevents .http import CloudEvent
3030from flask import jsonify , make_response , request
3131from flask_restful_swagger_2 import Resource , swagger
3232
@@ -42,6 +42,7 @@ class Hook(Resource):
4242
4343 def get (self , source_name ):
4444 """Cloudevent get method: not allowed response."""
45+ _source_name = source_name
4546 res = jsonify (
4647 SimpleStatusCodeResponseModel (
4748 status = 405 ,
@@ -51,48 +52,53 @@ def get(self, source_name):
5152 return make_response (res , 405 )
5253
5354 def head (self , source_name ):
54- return make_response ('' , 200 )
55+ """Cloudevent head method: return empty response."""
56+ _source_name = source_name
57+ return make_response ("" , 200 )
5558
5659 @swagger .doc (hook .describe_hook_post_docs )
5760 def post (self , source_name ) -> SimpleStatusCodeResponseModel :
5861 """Translate actinia webhook call to cloudevent.
5962
6063 This method is called by HTTP POST actinia-core webhook
6164 """
62-
6365 # only actinia as source supported so far
64- if source_name != ' actinia' :
66+ if source_name != " actinia" :
6567 return make_response (
66- jsonify (SimpleStatusCodeResponseModel (
67- status = 400 ,
68- message = 'Bad Request: Source name does not match actinia'
69- )),
70- 400
68+ jsonify (
69+ SimpleStatusCodeResponseModel (
70+ status = 400 ,
71+ message = "Bad Request: Source name not 'actinia'" ,
72+ ),
73+ ),
74+ 400 ,
7175 )
7276
7377 postbody = request .get_json (force = True )
7478
7579 if type (postbody ) is dict :
7680 postbody = json .dumps (postbody )
77- elif type (postbody ) != ' str' :
81+ elif not isinstance (postbody , str ) :
7882 postbody = str (postbody )
7983
8084 resp = json .loads (postbody )
81- if ' resource_id' not in resp :
85+ if " resource_id" not in resp :
8286 return make_response (
83- jsonify (SimpleStatusCodeResponseModel (
84- status = 400 ,
85- message = 'Bad Request: No resource_id found in request'
86- )),
87- 400
87+ jsonify (
88+ SimpleStatusCodeResponseModel (
89+ status = 400 ,
90+ message = "Bad Request: No resource_id found in request" ,
91+ ),
92+ ),
93+ 400 ,
8894 )
8995
9096 # TODO: define when to send cloudevent
91- status = resp [' status' ]
92- if status == ' finished' :
97+ status = resp [" status" ]
98+ if status == " finished" :
9399 # TODO send cloudevent
94100 pass
95- terminate_status = [' finished' , ' error' , ' terminated' ]
101+ terminate_status = [" finished" , " error" , " terminated" ]
96102 if status in terminate_status :
97103 # TODO send cloudevent
98104 pass
0 commit comments