@APICommand(name = "addBaremetalPxeKickStartServer", description = "add a baremetal pxe server", responseObject = BaremetalPxeKickStartResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddBaremetalKickStartPxeCmd extends AddBaremetalPxeCmd { @Parameter(name = ApiConstants.TFTP_DIR, type = CommandType.STRING, required = true, description = "Tftp root directory of PXE server") private String tftpDir; public String getTftpDir() { return tftpDir; } public void setTftpDir(String tftpDir) { this.tftpDir = tftpDir; } }
@Override public String getCommandName() { return getClass().getAnnotation(APICommand.class).name(); }
apiCmdAnnotation = cmdClass.getSuperclass().getAnnotation(APICommand.class); if (apiCmdAnnotation == null || !apiCmdAnnotation.includeInApiDoc() || apiCmdAnnotation.name().isEmpty()) { continue; String apiName = apiCmdAnnotation.name(); if (s_logger.isTraceEnabled()) { s_logger.trace("Found api: " + apiName); Class<? extends BaseResponse> responseClass = apiCmdAnnotation.responseObject(); String responseName = responseClass.getName(); if (!responseName.contains("SuccessResponse")) {
if (impl.includeInApiDoc()) { String commandDescription = impl.description(); if (commandDescription != null && !commandDescription.isEmpty()) { apiCommand.setDescription(commandDescription); String commandUsage = impl.usage(); if (commandUsage != null && !commandUsage.isEmpty()) { apiCommand.setUsage(commandUsage); if (!impl.since().isEmpty()) { apiCommand.setSinceVersion(impl.since()); Class<?> responseClas = impl.responseObject(); Field[] responseFields = responseClas.getDeclaredFields(); response = setResponseFields(responseFields, responseClas);
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; }
@Override public boolean start() { for (PluggableService service : services) { for (Class<?> clz : service.getCommands()) { APICommand command = clz.getAnnotation(APICommand.class); for (RoleType role : command.authorized()) { Set<String> commands = annotationRoleBasedApisMap.get(role); if (!commands.contains(command.name())) commands.add(command.name()); } if (!commandNames.contains(command.name())) { commandNames.add(command.name()); } } } return super.start(); }
@Override public boolean start() { for (PluggableService service : services) { for (Class<?> clz : service.getCommands()) { APICommand command = clz.getAnnotation(APICommand.class); for (RoleType role : command.authorized()) { addApiToRoleBasedAnnotationsMap(role, command.name()); } } } return super.start(); }
@APICommand(name = "listTemplatePermissions", description = "List template visibility and all accounts that have permissions to view this template.", responseObject = TemplatePermissionsResponse.class, responseView = ResponseView.Full, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTemplatePermissionsCmdByAdmin extends ListTemplatePermissionsCmd { @Override public void execute() { executeWithView(ResponseView.Full); } }
@Override public String getCommandName() { return getClass().getAnnotation(APICommand.class).name(); }
@APICommand(name = "listIsoPermissions", description = "List iso visibility and all accounts that have permissions to view this iso.", responseObject = TemplatePermissionsResponse.class, responseView = ResponseView.Full, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListIsoPermissionsCmdByAdmin extends ListIsoPermissionsCmd { @Override public void execute() { executeWithView(ResponseView.Full); } }
private static synchronized void addAuthenticator(Class<?> authenticator, APICommand command) { s_authenticators.put(command.name().toLowerCase(), authenticator); }
@APICommand(name = "copyIso", description = "Copies an ISO from one zone to another.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CopyIsoCmd extends CopyTemplateCmd { public static final Logger s_logger = Logger.getLogger(CopyIsoCmd.class.getName()); private static final String s_name = "copyisoresponse"; }
/** * Gets the CommandName based on the class annotations: the value from {@link APICommand#name()} * * @return the value from {@link APICommand#name()} */ public String getActualCommandName() { String cmdName = null; if (this.getClass().getAnnotation(APICommand.class) != null) { cmdName = this.getClass().getAnnotation(APICommand.class).name(); } else { cmdName = this.getClass().getName(); } return cmdName; }
@APICommand(name = "listAccounts", description = "Lists accounts and provides detailed account information for listed accounts", responseObject = AccountResponse.class, responseView = ResponseView.Full, entityType = {Account.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class ListAccountsCmdByAdmin extends ListAccountsCmd { }
private void doAccessChecks(BaseCmd cmd, Map<Object, AccessType> entitiesToAccess) { Account caller = CallContext.current().getCallingAccount(); APICommand commandAnnotation = cmd.getClass().getAnnotation(APICommand.class); String apiName = commandAnnotation != null ? commandAnnotation.name() : null; if (!entitiesToAccess.isEmpty()) { for (Object entity : entitiesToAccess.keySet()) { if (entity instanceof ControlledEntity) { _accountMgr.checkAccess(caller, entitiesToAccess.get(entity), false, apiName, (ControlledEntity) entity); } else if (entity instanceof InfrastructureEntity) { //FIXME: Move this code in adapter, remove code from Account manager } } } }
@APICommand(name = "listTemplates", description = "List all public, private, and privileged templates.", responseObject = TemplateResponse.class, entityType = {VirtualMachineTemplate.class}, responseView = ResponseView.Full, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTemplatesCmdByAdmin extends ListTemplatesCmd { }
@Override public boolean start() { initAuthenticator(); for (Class<?> authenticator: getCommands()) { APICommand command = authenticator.getAnnotation(APICommand.class); if (command != null && !command.name().isEmpty() && APIAuthenticator.class.isAssignableFrom(authenticator)) { addAuthenticator(authenticator, command); } } return true; }
@APICommand(name = "listVolumes", description = "Lists all volumes.", responseObject = VolumeResponse.class, responseView = ResponseView.Full, entityType = { Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVolumesCmdByAdmin extends ListVolumesCmd { }
continue; String apiName = cmdClass.getAnnotation(APICommand.class).name(); if (s_apiNameCmdClassMap.containsKey(apiName)) {
@APICommand(name = "listDomains", description = "Lists domains and provides detailed information for listed domains", responseObject = DomainResponse.class, responseView = ResponseView.Full, entityType = {Domain.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDomainsCmdByAdmin extends ListDomainsCmd { }