Search in sources :

Example 6 with ApiDiscoveryResponse

use of org.apache.cloudstack.api.response.ApiDiscoveryResponse in project cloudstack by apache.

the class ApiDiscoveryServiceImpl method getCmdRequestMap.

private ApiDiscoveryResponse getCmdRequestMap(Class<?> cmdClass, APICommand apiCmdAnnotation) {
    String apiName = apiCmdAnnotation.name();
    ApiDiscoveryResponse response = new ApiDiscoveryResponse();
    response.setName(apiName);
    response.setDescription(apiCmdAnnotation.description());
    if (!apiCmdAnnotation.since().isEmpty()) {
        response.setSince(apiCmdAnnotation.since());
    }
    Set<Field> fields = ReflectUtil.getAllFieldsForClass(cmdClass, new Class<?>[] { BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class });
    boolean isAsync = ReflectUtil.isCmdClassAsync(cmdClass, new Class<?>[] { BaseAsyncCmd.class, BaseAsyncCreateCmd.class });
    response.setAsync(isAsync);
    for (Field field : fields) {
        Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
        if (parameterAnnotation != null && parameterAnnotation.expose() && parameterAnnotation.includeInApiDoc()) {
            ApiParameterResponse paramResponse = new ApiParameterResponse();
            paramResponse.setName(parameterAnnotation.name());
            paramResponse.setDescription(parameterAnnotation.description());
            paramResponse.setType(parameterAnnotation.type().toString().toLowerCase());
            paramResponse.setLength(parameterAnnotation.length());
            paramResponse.setRequired(parameterAnnotation.required());
            if (!parameterAnnotation.since().isEmpty()) {
                paramResponse.setSince(parameterAnnotation.since());
            }
            paramResponse.setRelated(parameterAnnotation.entityType()[0].getName());
            response.addParam(paramResponse);
        }
    }
    return response;
}
Also used : Field(java.lang.reflect.Field) ApiParameterResponse(org.apache.cloudstack.api.response.ApiParameterResponse) Parameter(org.apache.cloudstack.api.Parameter) ApiDiscoveryResponse(org.apache.cloudstack.api.response.ApiDiscoveryResponse)

Example 7 with ApiDiscoveryResponse

use of org.apache.cloudstack.api.response.ApiDiscoveryResponse in project cloudstack by apache.

the class ApiDiscoveryServiceImpl method listApis.

@Override
public ListResponse<? extends BaseResponse> listApis(User user, String name) {
    ListResponse<ApiDiscoveryResponse> response = new ListResponse<ApiDiscoveryResponse>();
    List<ApiDiscoveryResponse> responseList = new ArrayList<ApiDiscoveryResponse>();
    if (user == null)
        return null;
    if (name != null) {
        if (!s_apiNameDiscoveryResponseMap.containsKey(name))
            return null;
        for (APIChecker apiChecker : _apiAccessCheckers) {
            try {
                apiChecker.checkAccess(user, name);
            } catch (Exception ex) {
                s_logger.debug("API discovery access check failed for " + name + " with " + ex.getMessage());
                return null;
            }
        }
        responseList.add(s_apiNameDiscoveryResponseMap.get(name));
    } else {
        for (String apiName : s_apiNameDiscoveryResponseMap.keySet()) {
            boolean isAllowed = true;
            for (APIChecker apiChecker : _apiAccessCheckers) {
                try {
                    apiChecker.checkAccess(user, apiName);
                } catch (Exception ex) {
                    isAllowed = false;
                }
            }
            if (isAllowed)
                responseList.add(s_apiNameDiscoveryResponseMap.get(apiName));
        }
    }
    response.setResponses(responseList);
    return response;
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ApiDiscoveryResponse(org.apache.cloudstack.api.response.ApiDiscoveryResponse) APIChecker(org.apache.cloudstack.acl.APIChecker)

Aggregations

ApiDiscoveryResponse (org.apache.cloudstack.api.response.ApiDiscoveryResponse)7 ListResponse (org.apache.cloudstack.api.response.ListResponse)4 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ApiParameterResponse (org.apache.cloudstack.api.response.ApiParameterResponse)2 Test (org.junit.Test)2 User (com.cloud.user.User)1 PluggableService (com.cloud.utils.component.PluggableService)1 HashMap (java.util.HashMap)1 List (java.util.List)1 APIChecker (org.apache.cloudstack.acl.APIChecker)1 APICommand (org.apache.cloudstack.api.APICommand)1 Parameter (org.apache.cloudstack.api.Parameter)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 ApiResponseResponse (org.apache.cloudstack.api.response.ApiResponseResponse)1