Resource tags: CS-15661 - don't accept NULL or empty key value when create resource tag

This commit is contained in:
Alena Prokharchyk 2012-07-23 10:50:21 -07:00
parent 65551cff82
commit 7bef9a961d
2 changed files with 10 additions and 3 deletions

View File

@ -33,6 +33,7 @@ import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.server.ResourceTag;
import com.cloud.server.ResourceTag.TaggedResourceType;

View File

@ -233,7 +233,7 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
Transaction txn = Transaction.currentTxn();
txn.start();
for (String tag : tags.keySet()) {
for (String key : tags.keySet()) {
for (String resourceId : resourceIds) {
Long id = getResourceId(resourceId, resourceType);
String resourceUuid = getUuid(resourceId, resourceType);
@ -254,10 +254,16 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
_accountMgr.checkAccess(caller, _domainMgr.getDomain(domainId));
} else {
throw new PermissionDeniedException("Account " + caller + " doesn't have permissions to create tags" +
" for resource " + tag);
" for resource " + key);
}
String value = tags.get(key);
if (value == null || value.isEmpty()) {
throw new InvalidParameterValueException("Value for the key " + key + " is either null or empty");
}
ResourceTagVO resourceTag = new ResourceTagVO(tag, tags.get(tag), accountDomainPair.first(),
ResourceTagVO resourceTag = new ResourceTagVO(key, value, accountDomainPair.first(),
accountDomainPair.second(),
id, resourceType, customer, resourceUuid);
resourceTag = _resourceTagDao.persist(resourceTag);