Skip to content

Commit bc60b84

Browse files
committed
lint
1 parent acbfe7b commit bc60b84

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

.flake8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ per-file-ignores =
1010
./tests/cloudevent_receiver_server.py: E501
1111
# remove when implemented:
1212
./src/actinia_cloudevent_plugin/api/cloudevent.py: E501
13-
./src/actinia_cloudevent_plugin/core/processing.py: F841, E501
13+
./src/actinia_cloudevent_plugin/api/hook.py: F841
14+
./src/actinia_cloudevent_plugin/core/cloudevents.py: F841, E501

src/actinia_cloudevent_plugin/api/hook.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
__maintainer__ = "mundialis GmbH & Co. KG"
2424

2525
import json
26-
import requests
2726

28-
from cloudevents.http import CloudEvent
27+
import requests
2928
from cloudevents.conversion import to_binary
29+
from cloudevents.http import CloudEvent
3030
from flask import jsonify, make_response, request
3131
from 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

src/actinia_cloudevent_plugin/apidocs/hook.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
# "summary" is taken from the description of the get method
3232
"tags": ["cloudevent"],
3333
"description": (
34-
"Receives webhook with status update e.g. from actinia-core, transforms to cloudevent and sends it to configurable endpoint."
34+
"Receives webhook with status update e.g. from actinia-core,"
35+
" transforms to cloudevent and sends it to configurable endpoint."
3536
),
3637
"responses": {
3738
"200": {

0 commit comments

Comments
 (0)