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.
This commit is contained in:
Joshua Boniface 2020-11-09 10:26:01 -05:00
parent b169620eee
commit e6bca5b6a9
1 changed files with 10 additions and 7 deletions

View File

@ -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/<p
# /storage/ceph/volume/<pool>/<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):