Make categories optional parameter
Change-Id: I5960de1b7e01db491046b89f08fd95324d24551d Closes-Bug: #1311033
This commit is contained in:
@@ -249,8 +249,6 @@ Allowed operations:
|
|||||||
{ "op": "replace", "path": "/name", "value": "New name" }
|
{ "op": "replace", "path": "/name", "value": "New name" }
|
||||||
]
|
]
|
||||||
|
|
||||||
Note, that replacing categories with empty list is not allowed as well as the removing last category.
|
|
||||||
|
|
||||||
**Request 200 (application/murano-packages-json-patch)**
|
**Request 200 (application/murano-packages-json-patch)**
|
||||||
|
|
||||||
::
|
::
|
||||||
@@ -292,10 +290,6 @@ Note, that replacing categories with empty list is not allowed as well as the re
|
|||||||
* An attempt to perform operation that is not allowed on the specified path
|
* An attempt to perform operation that is not allowed on the specified path
|
||||||
* An attempt to update non-public package by user whose tenant is not an owner of this package
|
* An attempt to update non-public package by user whose tenant is not an owner of this package
|
||||||
|
|
||||||
**Response 400**
|
|
||||||
|
|
||||||
* An attempt to replace categories with empty list or remove last category
|
|
||||||
|
|
||||||
**Response 404**
|
**Response 404**
|
||||||
|
|
||||||
* An attempt to update package that doesn't exist
|
* An attempt to update package that doesn't exist
|
||||||
|
@@ -91,12 +91,13 @@ def _validate_body(body):
|
|||||||
raise exc.HTTPBadRequest('Uploading file is too large.'
|
raise exc.HTTPBadRequest('Uploading file is too large.'
|
||||||
' The limit is {0} Mb'.format(mb_limit))
|
' The limit is {0} Mb'.format(mb_limit))
|
||||||
|
|
||||||
if len(body.keys()) != 2:
|
if len(body.keys()) > 2:
|
||||||
msg = _("'multipart/form-data' request body should contain "
|
msg = _("'multipart/form-data' request body should contain "
|
||||||
"2 parts: json string and zip archive. Current body consist "
|
"1 or 2 parts: json string and zip archive. Current body "
|
||||||
"of {0} part(s)").format(len(body.keys()))
|
"consists of {0} part(s)").format(len(body.keys()))
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise exc.HTTPBadRequest(msg)
|
raise exc.HTTPBadRequest(msg)
|
||||||
|
|
||||||
file_obj = None
|
file_obj = None
|
||||||
package_meta = None
|
package_meta = None
|
||||||
for part in body.values():
|
for part in body.values():
|
||||||
@@ -110,10 +111,6 @@ def _validate_body(body):
|
|||||||
msg = _('There is no file package with application description')
|
msg = _('There is no file package with application description')
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise exc.HTTPBadRequest(msg)
|
raise exc.HTTPBadRequest(msg)
|
||||||
if package_meta is None:
|
|
||||||
msg = _('There is no json with meta information about package')
|
|
||||||
LOG.error(msg)
|
|
||||||
raise exc.HTTPBadRequest(msg)
|
|
||||||
return file_obj, package_meta
|
return file_obj, package_meta
|
||||||
|
|
||||||
|
|
||||||
@@ -128,6 +125,7 @@ class Controller(object):
|
|||||||
{ "op": "add", "path": "/tags", "value": [ "foo", "bar" ] }
|
{ "op": "add", "path": "/tags", "value": [ "foo", "bar" ] }
|
||||||
{ "op": "add", "path": "/categories", "value": [ "foo", "bar" ] }
|
{ "op": "add", "path": "/categories", "value": [ "foo", "bar" ] }
|
||||||
{ "op": "remove", "path": "/tags" }
|
{ "op": "remove", "path": "/tags" }
|
||||||
|
{ "op": "remove", "path": "/categories" }
|
||||||
{ "op": "replace", "path": "/tags", "value": ["foo", "bar"] }
|
{ "op": "replace", "path": "/tags", "value": ["foo", "bar"] }
|
||||||
{ "op": "replace", "path": "/is_public", "value": true }
|
{ "op": "replace", "path": "/is_public", "value": true }
|
||||||
{ "op": "replace", "path": "/description",
|
{ "op": "replace", "path": "/description",
|
||||||
@@ -185,11 +183,14 @@ class Controller(object):
|
|||||||
"""
|
"""
|
||||||
_check_content_type(req, 'multipart/form-data')
|
_check_content_type(req, 'multipart/form-data')
|
||||||
file_obj, package_meta = _validate_body(body)
|
file_obj, package_meta = _validate_body(body)
|
||||||
try:
|
if package_meta:
|
||||||
jsonschema.validate(package_meta, schemas.PKG_UPLOAD_SCHEMA)
|
try:
|
||||||
except jsonschema.ValidationError as e:
|
jsonschema.validate(package_meta, schemas.PKG_UPLOAD_SCHEMA)
|
||||||
LOG.exception(e)
|
except jsonschema.ValidationError as e:
|
||||||
raise exc.HTTPBadRequest(explanation=e.message)
|
LOG.exception(e)
|
||||||
|
raise exc.HTTPBadRequest(explanation=e.message)
|
||||||
|
else:
|
||||||
|
package_meta = {}
|
||||||
|
|
||||||
with tempfile.NamedTemporaryFile(delete=False) as tempf:
|
with tempfile.NamedTemporaryFile(delete=False) as tempf:
|
||||||
LOG.debug("Storing package archive in a temporary file")
|
LOG.debug("Storing package archive in a temporary file")
|
||||||
|
@@ -37,7 +37,7 @@ PKG_UPLOAD_SCHEMA = {
|
|||||||
},
|
},
|
||||||
"categories": {
|
"categories": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"minItems": 1,
|
"minItems": 0,
|
||||||
"items": {"type": "string"},
|
"items": {"type": "string"},
|
||||||
"uniqueItems": True
|
"uniqueItems": True
|
||||||
},
|
},
|
||||||
@@ -46,7 +46,6 @@ PKG_UPLOAD_SCHEMA = {
|
|||||||
"is_public": {"type": "boolean"},
|
"is_public": {"type": "boolean"},
|
||||||
"enabled": {"type": "boolean"}
|
"enabled": {"type": "boolean"}
|
||||||
},
|
},
|
||||||
"required": ["categories"],
|
|
||||||
"additionalProperties": False
|
"additionalProperties": False
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +61,6 @@ PKG_UPDATE_SCHEMA = {
|
|||||||
},
|
},
|
||||||
"categories": {
|
"categories": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"minItems": 1,
|
|
||||||
"items": {"type": "string"},
|
"items": {"type": "string"},
|
||||||
"uniqueItems": True
|
"uniqueItems": True
|
||||||
},
|
},
|
||||||
|
@@ -197,10 +197,6 @@ def _do_remove(package, change):
|
|||||||
"does not exist.").format(value, path)
|
"does not exist.").format(value, path)
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise exc.HTTPNotFound(msg)
|
raise exc.HTTPNotFound(msg)
|
||||||
if path == 'categories' and len(current_values) == 1:
|
|
||||||
msg = _("At least one category should be assigned to the package")
|
|
||||||
LOG.error(msg)
|
|
||||||
raise exc.HTTPBadRequest(msg)
|
|
||||||
item_to_remove = find(current_values, lambda i: i.name == value)
|
item_to_remove = find(current_values, lambda i: i.name == value)
|
||||||
current_values.remove(item_to_remove)
|
current_values.remove(item_to_remove)
|
||||||
return package
|
return package
|
||||||
|
Reference in New Issue
Block a user