From e6bca5b6a97aa380013c1e40bf69c1a38671368f Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 9 Nov 2020 10:26:01 -0500 Subject: [PATCH] Add override args for RequestParser Properly fixes the issue with OVA upload bodies by allowing the restriction of the 'location' directive when parsing specific request args. Thus the 'form' location can be included by default but removed for those parsers that have a file body. --- api-daemon/pvcapid/flaskapi.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/api-daemon/pvcapid/flaskapi.py b/api-daemon/pvcapid/flaskapi.py index 6d617027..1d1b6328 100755 --- a/api-daemon/pvcapid/flaskapi.py +++ b/api-daemon/pvcapid/flaskapi.py @@ -157,13 +157,16 @@ class RequestParser(object): parser = reqparse.RequestParser() # Parse and add each argument for reqarg in self.reqargs: + location = reqarg.get('location', None) + if location is None: + location = ['args', 'form'] parser.add_argument( reqarg.get('name', None), required=reqarg.get('required', False), action=reqarg.get('action', None), choices=reqarg.get('choices', ()), help=reqarg.get('helptext', None), - location=['args'] + location=location ) reqargs = parser.parse_args() kwargs['reqargs'] = reqargs @@ -3803,7 +3806,7 @@ api.add_resource(API_Storage_Ceph_Volume_Element_Clone, '/storage/ceph/volume/

//upload class API_Storage_Ceph_Volume_Element_Upload(Resource): @RequestParser([ - {'name': 'image_format', 'required': True, 'helpmsg': "A source image format must be specified."} + {'name': 'image_format', 'required': True, 'location': ['args'], 'helpmsg': "A source image format must be specified."} ]) @Authenticator def post(self, pool, volume, reqargs): @@ -5846,9 +5849,9 @@ class API_Provisioner_OVA_Root(Resource): ) @RequestParser([ - {'name': 'pool', 'required': True, 'helpmsg': "A storage pool must be specified."}, - {'name': 'name', 'required': True, 'helpmsg': "A VM name must be specified."}, - {'name': 'ova_size', 'required': True, 'helpmsg': "An OVA size must be specified."}, + {'name': 'pool', 'required': True, 'location': ['args'], 'helpmsg': "A storage pool must be specified."}, + {'name': 'name', 'required': True, 'location': ['args'], 'helpmsg': "A VM name must be specified."}, + {'name': 'ova_size', 'required': True, 'location': ['args'], 'helpmsg': "An OVA size must be specified."}, ]) @Authenticator def post(self, reqargs): @@ -5923,8 +5926,8 @@ class API_Provisioner_OVA_Element(Resource): ) @RequestParser([ - {'name': 'pool', 'required': True, 'helpmsg': "A storage pool must be specified."}, - {'name': 'ova_size', 'required': True, 'helpmsg': "An OVA size must be specified."}, + {'name': 'pool', 'required': True, 'location': ['args'], 'helpmsg': "A storage pool must be specified."}, + {'name': 'ova_size', 'required': True, 'location': ['args'], 'helpmsg': "An OVA size must be specified."}, ]) @Authenticator def post(self, ova, reqargs):