ApiXmlDocWriter: remove hardcoded login and logout apis Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/e30ee733 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/e30ee733 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/e30ee733 Branch: refs/heads/auth-refactor Commit: e30ee7337ab480345933af27420749b2266fd454 Parents: 38fd5dc Author: Rohit Yadav <rohit.ya...@shapeblue.com> Authored: Tue Aug 12 07:33:40 2014 +0200 Committer: Rohit Yadav <rohit.ya...@shapeblue.com> Committed: Tue Aug 12 09:19:43 2014 +0200 ---------------------------------------------------------------------- .../src/com/cloud/api/doc/ApiXmlDocWriter.java | 186 ++++--------------- 1 file changed, 39 insertions(+), 147 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e30ee733/server/src/com/cloud/api/doc/ApiXmlDocWriter.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java index 6824185..11ea57a 100644 --- a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java +++ b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java @@ -16,6 +16,29 @@ // under the License. package com.cloud.api.doc; +import com.cloud.alert.AlertManager; +import com.cloud.serializer.Param; +import com.cloud.utils.IteratorUtil; +import com.cloud.utils.ReflectUtil; +import com.google.gson.annotations.SerializedName; +import com.thoughtworks.xstream.XStream; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.BaseAsyncCreateCmd; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.AsyncJobResponse; +import org.apache.cloudstack.api.response.HostResponse; +import org.apache.cloudstack.api.response.IPAddressResponse; +import org.apache.cloudstack.api.response.SecurityGroupResponse; +import org.apache.cloudstack.api.response.SnapshotResponse; +import org.apache.cloudstack.api.response.StoragePoolResponse; +import org.apache.cloudstack.api.response.TemplateResponse; +import org.apache.cloudstack.api.response.UserVmResponse; +import org.apache.cloudstack.api.response.VolumeResponse; +import org.apache.log4j.Logger; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -41,32 +64,6 @@ import java.util.TreeMap; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; -import org.apache.log4j.Logger; - -import com.google.gson.annotations.SerializedName; -import com.thoughtworks.xstream.XStream; - -import org.apache.cloudstack.api.APICommand; -import org.apache.cloudstack.api.BaseAsyncCmd; -import org.apache.cloudstack.api.BaseAsyncCreateCmd; -import org.apache.cloudstack.api.BaseCmd; -import org.apache.cloudstack.api.BaseResponse; -import org.apache.cloudstack.api.Parameter; -import org.apache.cloudstack.api.response.AsyncJobResponse; -import org.apache.cloudstack.api.response.HostResponse; -import org.apache.cloudstack.api.response.IPAddressResponse; -import org.apache.cloudstack.api.response.SecurityGroupResponse; -import org.apache.cloudstack.api.response.SnapshotResponse; -import org.apache.cloudstack.api.response.StoragePoolResponse; -import org.apache.cloudstack.api.response.TemplateResponse; -import org.apache.cloudstack.api.response.UserVmResponse; -import org.apache.cloudstack.api.response.VolumeResponse; - -import com.cloud.alert.AlertManager; -import com.cloud.serializer.Param; -import com.cloud.utils.IteratorUtil; -import com.cloud.utils.ReflectUtil; - public class ApiXmlDocWriter { public static final Logger s_logger = Logger.getLogger(ApiXmlDocWriter.class.getName()); @@ -183,15 +180,6 @@ public class ApiXmlDocWriter { } } - // Login and logout commands are hardcoded - s_allApiCommands.put("login", "login"); - s_domainAdminApiCommands.put("login", "login"); - s_regularUserApiCommands.put("login", "login"); - - s_allApiCommands.put("logout", "logout"); - s_domainAdminApiCommands.put("logout", "logout"); - s_regularUserApiCommands.put("logout", "logout"); - s_allApiCommandsSorted.putAll(s_allApiCommands); s_domainAdminApiCommandsSorted.putAll(s_domainAdminApiCommands); s_regularUserApiCommandsSorted.putAll(s_regularUserApiCommands); @@ -223,66 +211,28 @@ public class ApiXmlDocWriter { String key = (String)it.next(); // Write admin commands - if (key.equals("login")) { - writeLoginCommand(out); - writeLoginCommand(rootAdmin); - writeLoginCommand(domainAdmin); - writeLoginCommand(regularUser); - - ObjectOutputStream singleRootAdminCommandOs = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + "login" + ".xml"), "command"); - writeLoginCommand(singleRootAdminCommandOs); - singleRootAdminCommandOs.close(); + writeCommand(out, key); + writeCommand(rootAdmin, key); - ObjectOutputStream singleDomainAdminCommandOs = xs.createObjectOutputStream(new FileWriter(domainAdminDirName + "/" + "login" + ".xml"), "command"); - writeLoginCommand(singleDomainAdminCommandOs); - singleDomainAdminCommandOs.close(); - - ObjectOutputStream singleRegularUserCommandOs = xs.createObjectOutputStream(new FileWriter(regularUserDirName + "/" + "login" + ".xml"), "command"); - writeLoginCommand(singleRegularUserCommandOs); - singleRegularUserCommandOs.close(); - - } else if (key.equals("logout")) { - writeLogoutCommand(out); - writeLogoutCommand(rootAdmin); - writeLogoutCommand(domainAdmin); - writeLogoutCommand(regularUser); - - ObjectOutputStream singleRootAdminCommandOs = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + "logout" + ".xml"), "command"); - writeLogoutCommand(singleRootAdminCommandOs); + // Write single commands to separate xml files + if (!key.equals("login")) { + ObjectOutputStream singleRootAdminCommandOs = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + key + ".xml"), "command"); + writeCommand(singleRootAdminCommandOs, key); singleRootAdminCommandOs.close(); + } - ObjectOutputStream singleDomainAdminCommandOs = xs.createObjectOutputStream(new FileWriter(domainAdminDirName + "/" + "logout" + ".xml"), "command"); - writeLogoutCommand(singleDomainAdminCommandOs); + if (s_domainAdminApiCommands.containsKey(key)) { + writeCommand(domainAdmin, key); + ObjectOutputStream singleDomainAdminCommandOs = xs.createObjectOutputStream(new FileWriter(domainAdminDirName + "/" + key + ".xml"), "command"); + writeCommand(singleDomainAdminCommandOs, key); singleDomainAdminCommandOs.close(); + } - ObjectOutputStream singleRegularUserCommandOs = xs.createObjectOutputStream(new FileWriter(regularUserDirName + "/" + "logout" + ".xml"), "command"); - writeLogoutCommand(singleRegularUserCommandOs); + if (s_regularUserApiCommands.containsKey(key)) { + writeCommand(regularUser, key); + ObjectOutputStream singleRegularUserCommandOs = xs.createObjectOutputStream(new FileWriter(regularUserDirName + "/" + key + ".xml"), "command"); + writeCommand(singleRegularUserCommandOs, key); singleRegularUserCommandOs.close(); - - } else { - writeCommand(out, key); - writeCommand(rootAdmin, key); - - // Write single commands to separate xml files - if (!key.equals("login")) { - ObjectOutputStream singleRootAdminCommandOs = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + key + ".xml"), "command"); - writeCommand(singleRootAdminCommandOs, key); - singleRootAdminCommandOs.close(); - } - - if (s_domainAdminApiCommands.containsKey(key)) { - writeCommand(domainAdmin, key); - ObjectOutputStream singleDomainAdminCommandOs = xs.createObjectOutputStream(new FileWriter(domainAdminDirName + "/" + key + ".xml"), "command"); - writeCommand(singleDomainAdminCommandOs, key); - singleDomainAdminCommandOs.close(); - } - - if (s_regularUserApiCommands.containsKey(key)) { - writeCommand(regularUser, key); - ObjectOutputStream singleRegularUserCommandOs = xs.createObjectOutputStream(new FileWriter(regularUserDirName + "/" + key + ".xml"), "command"); - writeCommand(singleRegularUserCommandOs, key); - singleRegularUserCommandOs.close(); - } } } @@ -393,64 +343,6 @@ public class ApiXmlDocWriter { } } - private static void writeLoginCommand(ObjectOutputStream out) throws ClassNotFoundException, IOException { - ArrayList<Argument> request = new ArrayList<Argument>(); - ArrayList<Argument> response = new ArrayList<Argument>(); - - // Create a new command, set name and description - Command apiCommand = new Command(); - apiCommand.setName("login"); - apiCommand.setDescription("Logs a user into the CloudStack. A successful login attempt will generate a JSESSIONID cookie value that can be passed in subsequent Query command calls until the \"logout\" command has been issued or the session has expired."); - - // Generate request - request.add(new Argument("username", "Username", true)); - request.add(new Argument( - "password", - "Hashed password (Default is MD5). If you wish to use any other hashing algorithm, you would need to write a custom authentication adapter See Docs section.", - true)); - request.add(new Argument("domain", - "path of the domain that the user belongs to. Example: domain=/com/cloud/internal. If no domain is passed in, the ROOT domain is assumed.", false)); - request.add(new Argument("domainId", - "id of the domain that the user belongs to. If both domain and domainId are passed in, \"domainId\" parameter takes precendence", false)); - apiCommand.setRequest(request); - - // Generate response - response.add(new Argument("username", "Username")); - response.add(new Argument("userid", "User id")); - response.add(new Argument("password", "Password")); - response.add(new Argument("domainid", "domain ID that the user belongs to")); - response.add(new Argument("timeout", "the time period before the session has expired")); - response.add(new Argument("account", "the account name the user belongs to")); - response.add(new Argument("firstname", "first name of the user")); - response.add(new Argument("lastname", "last name of the user")); - response.add(new Argument("type", "the account type (admin, domain-admin, read-only-admin, user)")); - response.add(new Argument("timezone", "user time zone")); - response.add(new Argument("timezoneoffset", "user time zone offset from UTC 00:00")); - response.add(new Argument("sessionkey", "Session key that can be passed in subsequent Query command calls")); - apiCommand.setResponse(response); - - out.writeObject(apiCommand); - } - - private static void writeLogoutCommand(ObjectOutputStream out) throws ClassNotFoundException, IOException { - ArrayList<Argument> request = new ArrayList<Argument>(); - ArrayList<Argument> response = new ArrayList<Argument>(); - - // Create a new command, set name and description - Command apiCommand = new Command(); - apiCommand.setName("logout"); - apiCommand.setDescription("Logs out the user"); - - // Generate request - no request parameters - apiCommand.setRequest(request); - - // Generate response - response.add(new Argument("description", "success if the logout action succeeded")); - apiCommand.setResponse(response); - - out.writeObject(apiCommand); - } - private static ArrayList<Argument> setRequestFields(Set<Field> fields) { ArrayList<Argument> arguments = new ArrayList<Argument>(); Set<Argument> requiredArguments = new HashSet<Argument>();