Skip to content

Commit b36a019

Browse files
committed
fixups and some ui changes
1 parent 11e35c1 commit b36a019

File tree

28 files changed

+1511
-753
lines changed

28 files changed

+1511
-753
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ public class ApiConstants {
863863
public static final String SORT_BY = "sortby";
864864
public static final String CHANGE_CIDR = "changecidr";
865865
public static final String HSM_PROFILE = "hsmprofile";
866+
public static final String HSM_PROFILE_ID = "hsmprofileid";
866867
public static final String PURPOSE = "purpose";
867868
public static final String KMS_KEY_ID = "kmskeyid";
868869
public static final String KMS_KEY_VERSION = "kmskeyversion";

api/src/main/java/org/apache/cloudstack/api/command/admin/kms/MigrateVolumesToKMSCmd.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.cloudstack.api.ServerApiException;
2828
import org.apache.cloudstack.api.response.AsyncJobResponse;
2929
import org.apache.cloudstack.api.response.DomainResponse;
30+
import org.apache.cloudstack.api.response.KMSKeyResponse;
3031
import org.apache.cloudstack.api.response.ZoneResponse;
3132
import org.apache.cloudstack.framework.kms.KMSException;
3233
import org.apache.cloudstack.kms.KMSManager;
@@ -68,6 +69,13 @@ public class MigrateVolumesToKMSCmd extends BaseAsyncCmd {
6869
description = "Domain ID")
6970
private Long domainId;
7071

72+
@Parameter(name = ApiConstants.ID,
73+
required = true,
74+
type = CommandType.UUID,
75+
entityType = KMSKeyResponse.class,
76+
description = "KMS Key ID to use for migrating volumes")
77+
private Long kmsKeyId;
78+
7179
/////////////////////////////////////////////////////
7280
/////////////////// Accessors ///////////////////////
7381
/////////////////////////////////////////////////////
@@ -84,6 +92,10 @@ public Long getDomainId() {
8492
return domainId;
8593
}
8694

95+
public Long getKmsKeyId() {
96+
return kmsKeyId;
97+
}
98+
8799
/////////////////////////////////////////////////////
88100
/////////////// API Implementation///////////////////
89101
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/command/admin/kms/RotateKMSKeyCmd.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.cloudstack.api.Parameter;
2727
import org.apache.cloudstack.api.ServerApiException;
2828
import org.apache.cloudstack.api.response.AsyncJobResponse;
29+
import org.apache.cloudstack.api.response.HSMProfileResponse;
2930
import org.apache.cloudstack.api.response.KMSKeyResponse;
3031
import org.apache.cloudstack.framework.kms.KMSException;
3132
import org.apache.cloudstack.kms.KMSManager;
@@ -45,10 +46,6 @@ public class RotateKMSKeyCmd extends BaseAsyncCmd {
4546
@Inject
4647
private KMSManager kmsManager;
4748

48-
/////////////////////////////////////////////////////
49-
//////////////// API parameters /////////////////////
50-
/////////////////////////////////////////////////////
51-
5249
@Parameter(name = ApiConstants.ID,
5350
required = true,
5451
type = CommandType.UUID,
@@ -61,15 +58,12 @@ public class RotateKMSKeyCmd extends BaseAsyncCmd {
6158
description = "Key size for new KEK (default: same as current)")
6259
private Integer keyBits;
6360

64-
@Parameter(name = ApiConstants.HSM_PROFILE,
65-
type = CommandType.STRING,
66-
description = "The target HSM profile name for the new KEK version. If provided, migrates the key to this HSM.")
61+
@Parameter(name = ApiConstants.HSM_PROFILE_ID,
62+
type = CommandType.UUID,
63+
entityType = HSMProfileResponse.class,
64+
description = "The target HSM profile ID for the new KEK version. If provided, migrates the key to this HSM.")
6765
private String hsmProfile;
6866

69-
/////////////////////////////////////////////////////
70-
/////////////////// Accessors ///////////////////////
71-
/////////////////////////////////////////////////////
72-
7367
public Long getId() {
7468
return id;
7569
}
@@ -82,10 +76,6 @@ public String getHsmProfile() {
8276
return hsmProfile;
8377
}
8478

85-
/////////////////////////////////////////////////////
86-
/////////////// API Implementation///////////////////
87-
/////////////////////////////////////////////////////
88-
8979
@Override
9080
public void execute() {
9181
try {

api/src/main/java/org/apache/cloudstack/api/command/user/kms/CreateKMSKeyCmd.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.cloudstack.api.ServerApiException;
3232
import org.apache.cloudstack.api.command.user.UserCmd;
3333
import org.apache.cloudstack.api.response.DomainResponse;
34+
import org.apache.cloudstack.api.response.HSMProfileResponse;
3435
import org.apache.cloudstack.api.response.KMSKeyResponse;
3536
import org.apache.cloudstack.api.response.ZoneResponse;
3637
import org.apache.cloudstack.context.CallContext;
@@ -51,10 +52,6 @@ public class CreateKMSKeyCmd extends BaseCmd implements UserCmd {
5152
@Inject
5253
private KMSManager kmsManager;
5354

54-
/////////////////////////////////////////////////////
55-
//////////////// API parameters /////////////////////
56-
/////////////////////////////////////////////////////
57-
5855
@Parameter(name = ApiConstants.NAME,
5956
required = true,
6057
type = CommandType.STRING,
@@ -95,14 +92,12 @@ public class CreateKMSKeyCmd extends BaseCmd implements UserCmd {
9592
description = "Key size in bits: 128, 192, or 256 (default: 256)")
9693
private Integer keyBits;
9794

98-
@Parameter(name = ApiConstants.HSM_PROFILE,
99-
type = CommandType.STRING,
100-
description = "Name of HSM profile to create key in")
101-
private String hsmProfile;
102-
103-
/////////////////////////////////////////////////////
104-
/////////////////// Accessors ///////////////////////
105-
/////////////////////////////////////////////////////
95+
@Parameter(name = ApiConstants.HSM_PROFILE_ID,
96+
type = CommandType.UUID,
97+
entityType = HSMProfileResponse.class,
98+
required = true,
99+
description = "ID of HSM profile to create key in")
100+
private Long hsmProfileId;
106101

107102
public String getName() {
108103
return name;
@@ -132,14 +127,10 @@ public Integer getKeyBits() {
132127
return keyBits != null ? keyBits : 256; // Default to 256 bits
133128
}
134129

135-
public String getHsmProfile() {
136-
return hsmProfile;
130+
public Long getHsmProfileId() {
131+
return hsmProfileId;
137132
}
138133

139-
/////////////////////////////////////////////////////
140-
/////////////// API Implementation///////////////////
141-
/////////////////////////////////////////////////////
142-
143134
@Override
144135
public void execute() throws ResourceAllocationException {
145136
try {

api/src/main/java/org/apache/cloudstack/api/command/user/kms/DeleteKMSKeyCmd.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,17 @@ public class DeleteKMSKeyCmd extends BaseAsyncCmd implements UserCmd {
4949
@Inject
5050
private KMSManager kmsManager;
5151

52-
/////////////////////////////////////////////////////
53-
//////////////// API parameters /////////////////////
54-
/////////////////////////////////////////////////////
55-
5652
@Parameter(name = ApiConstants.ID,
5753
required = true,
5854
type = CommandType.UUID,
5955
entityType = KMSKeyResponse.class,
6056
description = "The UUID of the KMS key to delete")
6157
private Long id;
6258

63-
/////////////////////////////////////////////////////
64-
/////////////////// Accessors ///////////////////////
65-
/////////////////////////////////////////////////////
66-
6759
public Long getId() {
6860
return id;
6961
}
7062

71-
/////////////////////////////////////////////////////
72-
/////////////// API Implementation///////////////////
73-
/////////////////////////////////////////////////////
74-
7563
@Override
7664
public void execute() {
7765
try {

api/src/main/java/org/apache/cloudstack/api/command/user/kms/ListKMSKeysCmd.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ public class ListKMSKeysCmd extends BaseListAccountResourcesCmd implements UserC
4747
@Inject
4848
private KMSManager kmsManager;
4949

50-
/////////////////////////////////////////////////////
51-
//////////////// API parameters /////////////////////
52-
/////////////////////////////////////////////////////
53-
5450
@Parameter(name = ApiConstants.ID,
5551
type = CommandType.UUID,
5652
entityType = KMSKeyResponse.class,
@@ -73,10 +69,6 @@ public class ListKMSKeysCmd extends BaseListAccountResourcesCmd implements UserC
7369
description = "Filter by state: Enabled, Disabled")
7470
private String state;
7571

76-
/////////////////////////////////////////////////////
77-
/////////////////// Accessors ///////////////////////
78-
/////////////////////////////////////////////////////
79-
8072
public Long getId() {
8173
return id;
8274
}

api/src/main/java/org/apache/cloudstack/api/command/user/kms/UpdateKMSKeyCmd.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ public class UpdateKMSKeyCmd extends BaseAsyncCmd implements UserCmd {
4848
@Inject
4949
private KMSManager kmsManager;
5050

51-
/////////////////////////////////////////////////////
52-
//////////////// API parameters /////////////////////
53-
/////////////////////////////////////////////////////
54-
5551
@Parameter(name = ApiConstants.ID,
5652
required = true,
5753
type = CommandType.UUID,
@@ -74,10 +70,6 @@ public class UpdateKMSKeyCmd extends BaseAsyncCmd implements UserCmd {
7470
description = "New state: Enabled or Disabled")
7571
private String state;
7672

77-
/////////////////////////////////////////////////////
78-
/////////////////// Accessors ///////////////////////
79-
/////////////////////////////////////////////////////
80-
8173
public Long getId() {
8274
return id;
8375
}
@@ -94,10 +86,6 @@ public String getState() {
9486
return state;
9587
}
9688

97-
/////////////////////////////////////////////////////
98-
/////////////// API Implementation///////////////////
99-
/////////////////////////////////////////////////////
100-
10189
@Override
10290
public void execute() {
10391
try {

api/src/main/java/org/apache/cloudstack/api/command/user/kms/hsm/AddHSMProfileCmd.java

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,72 +17,75 @@
1717

1818
package org.apache.cloudstack.api.command.user.kms.hsm;
1919

20-
import java.util.Map;
21-
22-
import javax.inject.Inject;
23-
20+
import com.cloud.exception.ConcurrentOperationException;
21+
import com.cloud.exception.InsufficientCapacityException;
22+
import com.cloud.exception.NetworkRuleConflictException;
23+
import com.cloud.exception.ResourceAllocationException;
24+
import com.cloud.exception.ResourceUnavailableException;
2425
import org.apache.cloudstack.api.APICommand;
2526
import org.apache.cloudstack.api.ApiConstants;
2627
import org.apache.cloudstack.api.ApiErrorCode;
2728
import org.apache.cloudstack.api.BaseCmd;
2829
import org.apache.cloudstack.api.Parameter;
2930
import org.apache.cloudstack.api.ServerApiException;
31+
import org.apache.cloudstack.api.response.AccountResponse;
3032
import org.apache.cloudstack.api.response.DomainResponse;
3133
import org.apache.cloudstack.api.response.HSMProfileResponse;
3234
import org.apache.cloudstack.api.response.ZoneResponse;
3335
import org.apache.cloudstack.context.CallContext;
3436
import org.apache.cloudstack.framework.kms.KMSException;
3537
import org.apache.cloudstack.kms.HSMProfile;
3638
import org.apache.cloudstack.kms.KMSManager;
39+
import org.apache.commons.collections.MapUtils;
40+
import org.apache.commons.lang.StringUtils;
3741

38-
import com.cloud.exception.ConcurrentOperationException;
39-
import com.cloud.exception.InsufficientCapacityException;
40-
import com.cloud.exception.NetworkRuleConflictException;
41-
import com.cloud.exception.ResourceAllocationException;
42-
import com.cloud.exception.ResourceUnavailableException;
43-
import com.cloud.user.Account;
42+
import javax.inject.Inject;
43+
import java.util.Collection;
44+
import java.util.HashMap;
45+
import java.util.Map;
4446

4547
@APICommand(name = "addHSMProfile", description = "Adds a new HSM profile", responseObject = HSMProfileResponse.class,
46-
requestHasSensitiveInfo = true, responseHasSensitiveInfo = true, since = "4.21.0")
48+
requestHasSensitiveInfo = true, responseHasSensitiveInfo = true, since = "4.23.0")
4749
public class AddHSMProfileCmd extends BaseCmd {
4850

4951
@Inject
5052
private KMSManager kmsManager;
5153

52-
////////////////////////////////////////////////=====
53-
// API parameters
54-
////////////////////////////////////////////////=====
55-
56-
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the HSM profile")
54+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true,
55+
description = "the name of the HSM profile")
5756
private String name;
5857

59-
@Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, required = true, description = "the protocol of the HSM profile (PKCS11, KMIP, etc.)")
58+
@Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING,
59+
description = "the protocol of the HSM profile (PKCS11, KMIP, etc.). Default is 'pkcs11'")
6060
private String protocol;
6161

62-
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, description = "the zone ID where the HSM profile is available. If null, global scope (for admin only)")
62+
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class,
63+
description = "the zone ID where the HSM profile is available. If null, global scope (for admin only)")
6364
private Long zoneId;
6465

65-
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "the domain ID where the HSM profile is available")
66+
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class,
67+
description = "the domain ID where the HSM profile is available")
6668
private Long domainId;
6769

68-
@Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "the account ID of the HSM profile owner. If null, admin-provided (available to all accounts)")
70+
@Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class,
71+
description = "the account ID of the HSM profile owner. If null, admin-provided (available to all "
72+
+ "accounts)")
6973
private Long accountId;
7074

7175
@Parameter(name = ApiConstants.VENDOR_NAME, type = CommandType.STRING, description = "the vendor name of the HSM")
7276
private String vendorName;
7377

74-
@Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, required = true, description = "HSM configuration details (protocol specific)")
78+
@Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, description = "HSM configuration details (protocol specific)")
7579
private Map<String, String> details;
7680

77-
////////////////////////////////////////////////=====
78-
// Accessors
79-
////////////////////////////////////////////////=====
80-
8181
public String getName() {
8282
return name;
8383
}
8484

8585
public String getProtocol() {
86+
if (StringUtils.isBlank(protocol)) {
87+
return "pkcs11";
88+
}
8689
return protocol;
8790
}
8891

@@ -103,15 +106,22 @@ public String getVendorName() {
103106
}
104107

105108
public Map<String, String> getDetails() {
106-
return details;
109+
Map<String, String> detailsMap = new HashMap<>();
110+
if (MapUtils.isNotEmpty(details)) {
111+
Collection<?> props = details.values();
112+
for (Object prop : props) {
113+
HashMap<String, String> detail = (HashMap<String, String>) prop;
114+
for (Map.Entry<String, String> entry: detail.entrySet()) {
115+
detailsMap.put(entry.getKey(),entry.getValue());
116+
}
117+
}
118+
}
119+
return detailsMap;
107120
}
108121

109-
////////////////////////////////////////////////=====
110-
// Implementation
111-
////////////////////////////////////////////////=====
112-
113122
@Override
114-
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
123+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException,
124+
ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
115125
try {
116126
// Default to caller account if not admin and accountId not specified
117127
// But wait, the plan says: "No accountId parameter means account_id = NULL (admin-provided)"

api/src/main/java/org/apache/cloudstack/api/command/user/kms/hsm/DeleteHSMProfileCmd.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,19 @@
3939
import com.cloud.exception.ResourceUnavailableException;
4040

4141
@APICommand(name = "deleteHSMProfile", description = "Deletes an HSM profile", responseObject = SuccessResponse.class,
42-
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.21.0")
42+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.23.0")
4343
public class DeleteHSMProfileCmd extends BaseCmd {
4444

4545
@Inject
4646
private KMSManager kmsManager;
4747

48-
////////////////////////////////////////////////=====
49-
// API parameters
50-
////////////////////////////////////////////////=====
51-
5248
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = HSMProfileResponse.class, required = true, description = "the ID of the HSM profile")
5349
private Long id;
5450

55-
////////////////////////////////////////////////=====
56-
// Accessors
57-
////////////////////////////////////////////////=====
58-
5951
public Long getId() {
6052
return id;
6153
}
6254

63-
////////////////////////////////////////////////=====
64-
// Implementation
65-
////////////////////////////////////////////////=====
66-
6755
@Override
6856
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
6957
try {

0 commit comments

Comments
 (0)