Skip to content

Commit

Permalink
Bump werkzeug from 2.0.3 to 2.2.3 (#414)
Browse files Browse the repository at this point in the history
* Bump werkzeug from 2.0.3 to 2.2.3

Bumps [werkzeug](https://github.com/pallets/werkzeug) from 2.0.3 to 2.2.3.
- [Release notes](https://github.com/pallets/werkzeug/releases)
- [Changelog](https://github.com/pallets/werkzeug/blob/main/CHANGES.rst)
- [Commits](pallets/werkzeug@2.0.3...2.2.3)

---
updated-dependencies:
- dependency-name: werkzeug
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* replace deprecated werkzeug usage

* fix one test

* fix another test

* fix webhook-server-broken

* test fix

* cleanup

* lint+black

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Carmen <[email protected]>
Co-authored-by: anikaweinmann <[email protected]>
  • Loading branch information
3 people authored Jun 14, 2023
1 parent fcdb4de commit 7d56a56
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 103 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ actinia-user = "actinia_core.cli.actinia_user:main"
actinia-worker = "actinia_core.cli.rq_custom_worker:main"
actinia-server = "actinia_core.cli.actinia_server:main"
webhook-server = "actinia_core.cli.webhook_server:main"
webhook-server-broken = "actinia_core.cli.webhook_server_broken:main"
# still support deprecated command
rq_custom_worker = "actinia_core.cli.rq_custom_worker:main"

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ geopandas
rasterio==1.3.4
pystac==0.5.6
PyJWT
werkzeug==2.0.3
werkzeug==2.3.6
# required for running i.sentinel.download from GCS:
pandas
sentinelsat
Expand Down
87 changes: 0 additions & 87 deletions scripts/webhook-server-broken

This file was deleted.

41 changes: 28 additions & 13 deletions src/actinia_core/cli/webhook_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
Dummy server to response HTTP code 200 to a POST call from an actinia webhook
"""
import argparse
from pprint import pprint
import psutil
from flask import Flask, make_response, jsonify, request, json
from multiprocessing import Process
from werkzeug.exceptions import BadRequest

from pprint import pprint

__license__ = "GPLv3"
__author__ = "Soeren Gebbert, Anika Weinmann"
__copyright__ = (
"Copyright 2016-2023, Sören Gebbert and mundialis GmbH & Co. KG"
)
__author__ = "Soeren Gebbert, Anika Weinmann, Carmen Tawalika"
__copyright__ = "Copyright 2016-2023, mundialis GmbH & Co. KG"
__maintainer__ = "mundialis GmbH & Co. KG"


Expand All @@ -42,28 +44,41 @@

@flask_app.route("/webhook/finished", methods=["GET", "POST"])
def finished():
if request.get_json():
try:
pprint(json.loads(request.get_json()))
except BadRequest:
pass
except TypeError:
pass
return make_response(jsonify("OK"), 200)


@flask_app.route("/webhook/update", methods=["GET", "POST"])
def update():
if request.get_json():
try:
pprint(json.loads(request.get_json()))
except BadRequest:
pass
except TypeError:
pass
return make_response(jsonify("OK"), 200)


def shutdown_server():
func = request.environ.get("werkzeug.server.shutdown")
if func is None:
raise RuntimeError("Not running with the Werkzeug Server")
func()
def shutdown_server(port):
for proc in psutil.process_iter():
if (
proc.name() == "webhook-server"
and proc.as_dict()["connections"]
and proc.as_dict()["connections"][0].laddr.port == port
):
proc.kill()


@flask_app.route("/shutdown", methods=["GET"])
def shutdown():
shutdown_server()
port = request.server[1]
sp = Process(target=shutdown_server, args=(port,))
sp.start()
return make_response(jsonify("Server shutting down..."), 200)


Expand Down
119 changes: 119 additions & 0 deletions src/actinia_core/cli/webhook_server_broken.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!flask/bin/python
# -*- coding: utf-8 -*-
#######
# actinia-core - an open source REST API for scalable, distributed, high
# performance processing of geographical data that uses GRASS GIS for
# computational tasks. For details, see https://actinia.mundialis.de/
#
# Copyright (c) 2016-2018 Soeren Gebbert and mundialis GmbH & Co. KG
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#######

"""
Dummy server to response HTTP code 200 to a POST call from an actinia webhook
"""
import argparse
import psutil
from flask import Flask, make_response, jsonify, request, json
from multiprocessing import Process
from werkzeug.exceptions import BadRequest

from pprint import pprint

__license__ = "GPLv3"
__author__ = "Soeren Gebbert, Anika Weinmann, Carmen Tawalika"
__copyright__ = "Copyright 2016-2023, mundialis GmbH & Co. KG"
__maintainer__ = "mundialis GmbH & Co. KG"


flask_app = Flask(__name__)


@flask_app.route("/webhook/finished", methods=["GET", "POST"])
def finished():
port = request.server[1]
try:
pprint(json.loads(request.get_json()))
except BadRequest:
pass
except TypeError:
pass
sp = Process(target=shutdown_server, args=(port,))
sp.start()
return make_response(jsonify("Server shutting down..."), 200)


@flask_app.route("/webhook/update", methods=["GET", "POST"])
def update():
try:
pprint(json.loads(request.get_json()))
except BadRequest:
pass
except TypeError:
pass
return make_response(jsonify("OK"), 200)


def shutdown_server(port):
for proc in psutil.process_iter():
if (
proc.name() == "webhook-server-"
and proc.as_dict()["connections"]
and proc.as_dict()["connections"][0].laddr.port == port
):
proc.kill()


@flask_app.route("/shutdown", methods=["GET"])
def shutdown():
port = request.server[1]
sp = Process(target=shutdown_server, args=(port,))
sp.start()
return make_response(jsonify("Server shutting down..."), 200)


def main():

parser = argparse.ArgumentParser(
description="Start a webhook server that exposes GET/POST endpoints "
"which returns HTTP code 200 if called. The endpoints are: "
" - /webhook/finished for finished callbacks "
" - /webhook/update for status update callbacks"
)

parser.add_argument(
"--host",
type=str,
required=False,
default="0.0.0.0",
help="The IP address that should be used for the webhook server",
)

parser.add_argument(
"--port",
type=int,
required=False,
default=5005,
help="The port that should be used for the webhook server",
)

args = parser.parse_args()

flask_app.run(host=args.host, port=args.port)


if __name__ == "__main__":
main()
5 changes: 5 additions & 0 deletions src/actinia_core/rest/raster_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,22 @@ def get(self, location_name, mapset_name):
"red",
required=True,
type=str,
location="args",
help="The name of the raster layer associated with the color red",
)
parser.add_argument(
"green",
required=True,
type=str,
location="args",
help="The name of the raster layer associated with the color "
"green",
)
parser.add_argument(
"blue",
required=True,
type=str,
location="args",
help="The name of the raster layer associated with the color blue",
)

Expand Down Expand Up @@ -239,12 +242,14 @@ def get(self, location_name, mapset_name):
"shade",
required=True,
type=str,
location="args",
help="The name of the raster layer associated with shading",
)
parser.add_argument(
"color",
required=True,
type=str,
location="args",
help="The name of the raster layer associated with color",
)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def startBrokenWebhook(sleeptime=10):
code (500 - 599).
"""
inputlist = [
"python3",
"/src/actinia_core/scripts/webhook-server-broken",
"webhook-server-broken",
"--host",
"0.0.0.0",
"--port",
Expand Down Expand Up @@ -126,6 +125,7 @@ def poll_job(self, resp_data):
# poll an actinia job
rv_user_id = resp_data["user_id"]
rv_resource_id = resp_data["resource_id"]
time.sleep(10)
rv2 = self.server.get(
URL_PREFIX + "/resources/%s/%s" % (rv_user_id, rv_resource_id),
headers=self.admin_auth_header,
Expand Down

0 comments on commit 7d56a56

Please sign in to comment.