Skip to content

Commit c719b7f

Browse files
committed
api,server: apis return their http request type
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 5cac4f6 commit c719b7f

File tree

14 files changed

+75
-29
lines changed

14 files changed

+75
-29
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,6 @@
5050
RoleType[] authorized() default {};
5151

5252
Class<?>[] entityType() default {};
53+
54+
String httpMethod() default "";
5355
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ public class ApiConstants {
273273
public static final String HOST = "host";
274274
public static final String HOST_CONTROL_STATE = "hostcontrolstate";
275275
public static final String HOSTS_MAP = "hostsmap";
276+
public static final String HTTP_REQUEST_TYPE = "httprequesttype";
276277
public static final String HYPERVISOR = "hypervisor";
277278
public static final String INLINE = "inline";
278279
public static final String INSTANCE = "instance";

api/src/main/java/org/apache/cloudstack/api/command/admin/offering/IsAccountAllowedToCreateOfferingsWithTagsCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import org.apache.cloudstack.api.response.IsAccountAllowedToCreateOfferingsWithTagsResponse;
2727

2828
@APICommand(name = "isAccountAllowedToCreateOfferingsWithTags", description = "Return true if the specified account is allowed to create offerings with tags.",
29-
responseObject = IsAccountAllowedToCreateOfferingsWithTagsResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
29+
responseObject = IsAccountAllowedToCreateOfferingsWithTagsResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
30+
httpMethod = "GET")
3031
public class IsAccountAllowedToCreateOfferingsWithTagsCmd extends BaseCmd {
3132

3233
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "Account UUID", required = true)

plugins/api/discovery/src/main/java/org/apache/cloudstack/api/response/ApiDiscoveryResponse.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public class ApiDiscoveryResponse extends BaseResponse {
5959
@Param(description = "response field type")
6060
private String type;
6161

62+
@SerializedName(ApiConstants.HTTP_REQUEST_TYPE)
63+
@Param(description = "Preferred HTTP request type for the API", since = "4.22.0")
64+
private String httpRequestType;
65+
6266
public ApiDiscoveryResponse() {
6367
params = new HashSet<ApiParameterResponse>();
6468
apiResponse = new HashSet<ApiResponseResponse>();
@@ -74,6 +78,7 @@ public ApiDiscoveryResponse(ApiDiscoveryResponse another) {
7478
this.params = new HashSet<>(another.getParams());
7579
this.apiResponse = new HashSet<>(another.getApiResponse());
7680
this.type = another.getType();
81+
this.httpRequestType = another.getHttpRequestType();
7782
this.setObjectName(another.getObjectName());
7883
}
7984

@@ -140,4 +145,12 @@ public Set<ApiResponseResponse> getApiResponse() {
140145
public String getType() {
141146
return type;
142147
}
148+
149+
public String getHttpRequestType() {
150+
return httpRequestType;
151+
}
152+
153+
public void setHttpRequestType(String httpRequestType) {
154+
this.httpRequestType = httpRequestType;
155+
}
143156
}

plugins/api/discovery/src/main/java/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.reflections.ReflectionUtils;
5151
import org.springframework.stereotype.Component;
5252

53+
import com.cloud.api.ApiServlet;
5354
import com.cloud.exception.PermissionDeniedException;
5455
import com.cloud.serializer.Param;
5556
import com.cloud.user.Account;
@@ -197,6 +198,12 @@ private ApiDiscoveryResponse getCmdRequestMap(Class<?> cmdClass, APICommand apiC
197198
if (!apiCmdAnnotation.since().isEmpty()) {
198199
response.setSince(apiCmdAnnotation.since());
199200
}
201+
String httpRequestType = apiCmdAnnotation.httpMethod();
202+
if (StringUtils.isBlank(httpRequestType)) {
203+
httpRequestType = ApiServlet.GET_REQUEST_COMMANDS.matcher(apiName.toLowerCase()).matches() ?
204+
"GET" : "POST";
205+
}
206+
response.setHttpRequestType(httpRequestType);
200207

201208
Set<Field> fields = ReflectUtil.getAllFieldsForClass(cmdClass, new Class<?>[] {BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class});
202209

plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaBalanceCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
3636
import org.apache.cloudstack.api.response.QuotaStatementItemResponse;
3737

38-
@APICommand(name = "quotaBalance", responseObject = QuotaStatementItemResponse.class, description = "Create a quota balance statement", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
38+
@APICommand(name = "quotaBalance", responseObject = QuotaStatementItemResponse.class, description = "Create a quota balance statement", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
39+
httpMethod = "GET")
3940
public class QuotaBalanceCmd extends BaseCmd {
4041

4142

plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEnabledCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
import javax.inject.Inject;
2828

29-
@APICommand(name = "quotaIsEnabled", responseObject = QuotaEnabledResponse.class, description = "Return true if the plugin is enabled", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
29+
@APICommand(name = "quotaIsEnabled", responseObject = QuotaEnabledResponse.class, description = "Return true if the plugin is enabled", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
30+
httpMethod = "GET")
3031
public class QuotaEnabledCmd extends BaseCmd {
3132

3233

plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaStatementCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535

3636
import com.cloud.user.Account;
3737

38-
@APICommand(name = "quotaStatement", responseObject = QuotaStatementItemResponse.class, description = "Create a quota statement", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
38+
@APICommand(name = "quotaStatement", responseObject = QuotaStatementItemResponse.class, description = "Create a quota statement", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
39+
httpMethod = "GET")
3940
public class QuotaStatementCmd extends BaseCmd {
4041

4142

plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaSummaryCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333

3434
import javax.inject.Inject;
3535

36-
@APICommand(name = "quotaSummary", responseObject = QuotaSummaryResponse.class, description = "Lists balance and quota usage for all accounts", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
36+
@APICommand(name = "quotaSummary", responseObject = QuotaSummaryResponse.class, description = "Lists balance and quota usage for all accounts", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
37+
httpMethod = "GET")
3738
public class QuotaSummaryCmd extends BaseListCmd {
3839

3940
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = false, description = "Optional, Account Id for which statement needs to be generated")

plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffListCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
import java.util.Date;
3939
import java.util.List;
4040

41-
@APICommand(name = "quotaTariffList", responseObject = QuotaTariffResponse.class, description = "Lists all quota tariff plans", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
41+
@APICommand(name = "quotaTariffList", responseObject = QuotaTariffResponse.class, description = "Lists all quota tariff plans", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
42+
httpMethod = "GET")
4243
public class QuotaTariffListCmd extends BaseListCmd {
4344

4445
@Inject

0 commit comments

Comments
 (0)