From 84d307a8e696fb2f800b15fc477a31ffade312b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 6 Dec 2020 03:14:30 +0100 Subject: [PATCH] some fuckery --- src/resources.py | 109 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 90 insertions(+), 19 deletions(-) diff --git a/src/resources.py b/src/resources.py index c75f67a..1c9d74b 100644 --- a/src/resources.py +++ b/src/resources.py @@ -165,7 +165,11 @@ class UserParameterApi(Resource): :return: """ body = request.get_json() - user = VideonUser.query.filter_by(name=username).first_or_404() + try: + user = VideonUser.query.filter_by(name=username).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(404, "could not find user") try: userobj = self.userschema.load(body) except Exception as e: @@ -206,7 +210,11 @@ class CreateIngestResource(Resource): username = get_jwt_identity() # username = "jozska" - user = VideonUser.query.filter_by(name=username).first_or_404() + try: + user = VideonUser.query.filter_by(name=username).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(404, "could not find user") ingest.owner_id = user.id ingest.stream_key = str(uuid4()) try: @@ -254,7 +262,11 @@ class CreateRestreamResource(Resource): username = get_jwt_identity() # username = "jozska" - user = VideonUser.query.filter_by(name=username).first_or_404() + try: + user = VideonUser.query.filter_by(name=username).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(404, "could not find user") restream.owner_id = user.id restream.stream_key = str(uuid4()) if 'inputNeighbour' in restreamobj: @@ -301,7 +313,11 @@ class CreateEncodeResource(Resource): username = get_jwt_identity() # username = "jozska" - user = VideonUser.query.filter_by(name=username).first_or_404() + try: + user = VideonUser.query.filter_by(name=username).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(404, "could not find user") encoder.owner_id = user.id encoder.stream_key = str(uuid4()) if 'inputNeighbour' in encoderobj: @@ -349,8 +365,16 @@ class GetAllStreamResources(Resource): def get(self): username = get_jwt_identity() # username = "jozska" - user = VideonUser.query.filter_by(name=username).first_or_404() - streamreousrces = StreamResource.query.filter_by(owner_id=user.id).all() + try: + user = VideonUser.query.filter_by(name=username).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(404, "could not find user") + try: + streamreousrces = StreamResource.query.filter_by(owner_id=user.id).all() + except Exception as e: + current_app.logger.warning(e) + abort(422, "invalid arguments") return self.streamresourceschema.dump(streamreousrces), 200 @@ -366,8 +390,16 @@ class ManipulateStreamResource(Resource): """ username = get_jwt_identity() # username = "jozska" - user = VideonUser.query.filter_by(name=username).first_or_404() - streamreousrce = StreamResource.query.filter_by(id=UUID(resourceid), owner_id=user.id).first_or_404() + try: + user = VideonUser.query.filter_by(name=username).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(404, "could not find user") + try: + streamreousrce = StreamResource.query.filter_by(id=UUID(resourceid), owner_id=user.id).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(422, "invalid arguments") return self.streamresourceschema.dump(streamreousrce), 200 @jwt_required @@ -379,9 +411,16 @@ class ManipulateStreamResource(Resource): """ username = get_jwt_identity() # username = "jozska" - user = VideonUser.query.filter_by(name=username).first_or_404() - streamreousrce = StreamResource.query.filter_by(id=UUID(resourceid), owner_id=user.id).first_or_404() - + try: + user = VideonUser.query.filter_by(name=username).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(404, "could not find user") + try: + streamreousrce = StreamResource.query.filter_by(id=UUID(resourceid), owner_id=user.id).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(422, "invalid arguments") try: db.session.delete(streamreousrce) Kubectl(name=streamreousrce.id, resourcetype=streamreousrce.resource_type).delete_resource() @@ -412,8 +451,16 @@ class ModifyIngressResource(Resource): username = get_jwt_identity() # username = "jozska" - user = VideonUser.query.filter_by(name=username).first_or_404() - ingest = StreamResource.query.filter_by(id=resourceid, owner_id=user.id).first_or_404() + try: + user = VideonUser.query.filter_by(name=username).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(404, "could not find user") + try: + ingest = StreamResource.query.filter_by(id=resourceid, owner_id=user.id).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(422, "invalid arguments") ingest.x = ingestobj['x'] ingest.y = ingestobj['y'] @@ -473,8 +520,16 @@ class ModifyRestreamResource(Resource): username = get_jwt_identity() # username = "jozska" - user = VideonUser.query.filter_by(name=username).first_or_404() - restream = StreamResource.query.filter_by(id=resourceid, owner_id=user.id).first_or_404() + try: + user = VideonUser.query.filter_by(name=username).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(404, "could not find user") + try: + restream = StreamResource.query.filter_by(id=resourceid, owner_id=user.id).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(422, "invalid arguments") restream.x = restreamobj['x'] restream.y = restreamobj['y'] @@ -533,8 +588,16 @@ class ModifyEncodeResource(Resource): username = get_jwt_identity() # username = "jozska" - user = VideonUser.query.filter_by(name=username).first_or_404() - encode = StreamResource.query.filter_by(id=resourceid, owner_id=user.id).first_or_404() + try: + user = VideonUser.query.filter_by(name=username).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(404, "could not find user") + try: + encode = StreamResource.query.filter_by(id=resourceid, owner_id=user.id).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(422, "invalid arguments") encode.x = encodeobj['x'] encode.y = encodeobj['y'] @@ -606,8 +669,16 @@ class CoordModifyResource(Resource): username = get_jwt_identity() # username = "jozska" - user = VideonUser.query.filter_by(name=username).first_or_404() - resource = StreamResource.query.filter_by(id=resourceid, owner_id=user.id).first_or_404() + try: + user = VideonUser.query.filter_by(name=username).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(404, "could not find user") + try: + resource = StreamResource.query.filter_by(id=resourceid, owner_id=user.id).first_or_404() + except Exception as e: + current_app.logger.warning(e) + abort(422, "invalid arguments") resource.x = coordobj['x'] resource.y = coordobj['y']