Skip to content

Commit d4351de

Browse files
committed
Fix test failures
1 parent e9d1505 commit d4351de

File tree

5 files changed

+168
-208
lines changed

5 files changed

+168
-208
lines changed

engine/schema/src/main/java/org/apache/cloudstack/kms/dao/KMSKeyDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ public interface KMSKeyDao extends GenericDao<KMSKeyVO, Long> {
3030
List<KMSKeyVO> listByZone(Long zoneId, KeyPurpose purpose, Boolean enabled);
3131

3232
long countByHsmProfileId(Long hsmProfileId);
33+
34+
KMSKeyVO findByNameAndAccountId(String name, long accountId);
3335
}

engine/schema/src/main/java/org/apache/cloudstack/kms/dao/KMSKeyDaoImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class KMSKeyDaoImpl extends GenericDaoBase<KMSKeyVO, Long> implements KMS
3333

3434
public KMSKeyDaoImpl() {
3535
allFieldSearch = createSearchBuilder();
36+
allFieldSearch.and("name", allFieldSearch.entity().getName(), SearchCriteria.Op.EQ);
3637
allFieldSearch.and("kekLabel", allFieldSearch.entity().getKekLabel(), SearchCriteria.Op.EQ);
3738
allFieldSearch.and("domainId", allFieldSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
3839
allFieldSearch.and("accountId", allFieldSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
@@ -71,4 +72,12 @@ public long countByHsmProfileId(Long hsmProfileId) {
7172
Integer count = getCount(sc);
7273
return count != null ? count : 0;
7374
}
75+
76+
@Override
77+
public KMSKeyVO findByNameAndAccountId(String name, long accountId) {
78+
SearchCriteria<KMSKeyVO> sc = allFieldSearch.create();
79+
sc.setParameters("name", name);
80+
sc.setParameters("accountId", accountId);
81+
return findOneBy(sc);
82+
}
7483
}

server/src/main/java/org/apache/cloudstack/kms/KMSManagerImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ KMSKey createUserKMSKey(Long accountId, Long domainId, Long zoneId,
392392
if (profile == null) {
393393
throw KMSException.invalidParameter("HSM Profile not found");
394394
}
395+
if (kmsKeyDao.findByNameAndAccountId(name, accountId) != null) {
396+
throw new InvalidParameterValueException("A KMS key with name " + name + " already exists in this account");
397+
}
395398

396399
KMSKeyVO kmsKey = new KMSKeyVO(name, description, "", purpose,
397400
accountId, domainId, zoneId, "AES/GCM/NoPadding", keyBits);

0 commit comments

Comments
 (0)