ApiDiscovery: Fix listApis interface, fix getProperties

In case of api discovery, it does not make sense to create a separate properties file
If this plugin is enabled in components.xml, a user should be able to discover
all the apis accessible to their role.

listApis based on role type of caller user

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
This commit is contained in:
Rohit Yadav 2013-01-10 15:47:59 -08:00
parent c4e890c55d
commit 0b1c2a5981
3 changed files with 15 additions and 5 deletions

View File

@ -16,6 +16,9 @@
// under the License. // under the License.
package org.apache.cloudstack.api.command.user.discovery; package org.apache.cloudstack.api.command.user.discovery;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.BaseListCmd;
@ -39,7 +42,9 @@ public class ListApisCmd extends BaseListCmd {
@Override @Override
public void execute() throws ServerApiException { public void execute() throws ServerApiException {
if (_apiDiscoveryService != null) { if (_apiDiscoveryService != null) {
ListResponse<ApiDiscoveryResponse> response = (ListResponse<ApiDiscoveryResponse>) _apiDiscoveryService.listApis(); Account caller = UserContext.current().getCaller();
RoleType roleType = _accountService.getRoleType(UserContext.current().getCaller());
ListResponse<ApiDiscoveryResponse> response = (ListResponse<ApiDiscoveryResponse>) _apiDiscoveryService.listApis(roleType);
if (response == null) { if (response == null) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Api Discovery plugin was unable to find and process any apis"); throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Api Discovery plugin was unable to find and process any apis");
} }

View File

@ -17,9 +17,10 @@
package org.apache.cloudstack.discovery; package org.apache.cloudstack.discovery;
import com.cloud.utils.component.PluggableService; import com.cloud.utils.component.PluggableService;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.BaseResponse; import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ListResponse;
public interface ApiDiscoveryService extends PluggableService { public interface ApiDiscoveryService extends PluggableService {
ListResponse<? extends BaseResponse> listApis(); ListResponse<? extends BaseResponse> listApis(RoleType roleType);
} }

View File

@ -16,7 +16,9 @@
// under the License. // under the License.
package org.apache.cloudstack.discovery; package org.apache.cloudstack.discovery;
import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.ReflectUtil; import com.cloud.utils.ReflectUtil;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseAsyncCmd;
@ -108,12 +110,14 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService {
} }
@Override @Override
public ListResponse<? extends BaseResponse> listApis() { public ListResponse<? extends BaseResponse> listApis(RoleType roleType) {
return _discoveryResponse; return _discoveryResponse;
} }
@Override @Override
public String[] getPropertiesFiles() { public Map<String, String> getProperties() {
return new String[] { "api-discovery_commands.properties" }; Map<String, String> apiDiscoveryPropertyMap = new HashMap<String, String>();
apiDiscoveryPropertyMap.put("listApis", "15");
return apiDiscoveryPropertyMap;
} }
} }