Skip to content

Commit 0bdefe0

Browse files
committed
Added login/logout command generation to xml api doc generator
1 parent 82692ba commit 0bdefe0

2 files changed

Lines changed: 147 additions & 27 deletions

File tree

‎server/src/com/cloud/api/doc/ApiXmlDocWriter.java‎

Lines changed: 136 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ public static void main (String[] args) {
123123
}
124124
}
125125

126+
//Login and logout commands are hardcoded
127+
all_api_commands.put("login", "login");
128+
domain_admin_api_commands.put("login", "login");
129+
regular_user_api_commands.put("login", "login");
130+
131+
all_api_commands.put("logout", "logout");
132+
domain_admin_api_commands.put("logout", "logout");
133+
regular_user_api_commands.put("logout", "logout");
134+
135+
126136
all_api_commands_sorted.putAll(all_api_commands);
127137
domain_admin_api_commands_sorted.putAll(domain_admin_api_commands);
128138
regular_user_api_commands_sorted.putAll(regular_user_api_commands);
@@ -154,42 +164,87 @@ public static void main (String[] args) {
154164
String key = (String)it.next();
155165

156166
//Write admin commands
157-
writeCommand(out, key);
158-
writeCommand(rootAdmin, key);
159-
160-
//Write single commands to separate xml files
161-
ObjectOutputStream singleRootAdminCommandOs = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + key + ".xml"), "command");
162-
writeCommand(singleRootAdminCommandOs, key);
163-
singleRootAdminCommandOs.close();
164-
165-
if (domain_admin_api_commands.containsKey(key)){
166-
writeCommand(domainAdmin, key);
167-
ObjectOutputStream singleDomainAdminCommandOs = xs.createObjectOutputStream(new FileWriter(domainAdminDirName + "/" + key + ".xml"), "command");
168-
writeCommand(singleDomainAdminCommandOs, key);
167+
if (key.equals("login")) {
168+
writeLoginCommand(out);
169+
writeLoginCommand(rootAdmin);
170+
171+
ObjectOutputStream singleRootAdminCommandOs = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + "login" + ".xml"), "command");
172+
writeLoginCommand(singleRootAdminCommandOs);
173+
singleRootAdminCommandOs.close();
174+
175+
ObjectOutputStream singleDomainAdminCommandOs = xs.createObjectOutputStream(new FileWriter(domainAdminDirName + "/" + "login" + ".xml"), "command");
176+
writeLoginCommand(singleDomainAdminCommandOs);
169177
singleDomainAdminCommandOs.close();
170-
}
171-
172-
if (regular_user_api_commands.containsKey(key)){
173-
writeCommand(regularUser, key);
174-
ObjectOutputStream singleRegularUserCommandOs = xs.createObjectOutputStream(new FileWriter(regularUserDirName + "/" + key + ".xml"), "command");
175-
writeCommand(singleRegularUserCommandOs, key);
176-
singleRegularUserCommandOs.close();
178+
179+
ObjectOutputStream singleRegularUserCommandOs = xs.createObjectOutputStream(new FileWriter(regularUserDirName + "/" + "login" + ".xml"), "command");
180+
writeLoginCommand(singleRegularUserCommandOs);
181+
182+
} else if (key.equals("logout")) {
183+
writeLogoutCommand(out);
184+
writeLogoutCommand(rootAdmin);
185+
186+
ObjectOutputStream singleRootAdminCommandOs = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + "logout" + ".xml"), "command");
187+
writeLogoutCommand(singleRootAdminCommandOs);
188+
singleRootAdminCommandOs.close();
189+
190+
ObjectOutputStream singleDomainAdminCommandOs = xs.createObjectOutputStream(new FileWriter(domainAdminDirName + "/" + "logout" + ".xml"), "command");
191+
writeLogoutCommand(singleDomainAdminCommandOs);
192+
singleDomainAdminCommandOs.close();
193+
194+
ObjectOutputStream singleRegularUserCommandOs = xs.createObjectOutputStream(new FileWriter(regularUserDirName + "/" + "logout" + ".xml"), "command");
195+
writeLogoutCommand(singleRegularUserCommandOs);
196+
singleRegularUserCommandOs.close();
197+
198+
} else {
199+
writeCommand(out, key);
200+
writeCommand(rootAdmin, key);
201+
202+
//Write single commands to separate xml files
203+
if (!key.equals("login")) {
204+
ObjectOutputStream singleRootAdminCommandOs = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + key + ".xml"), "command");
205+
writeCommand(singleRootAdminCommandOs, key);
206+
singleRootAdminCommandOs.close();
207+
}
208+
209+
if (domain_admin_api_commands.containsKey(key)){
210+
writeCommand(domainAdmin, key);
211+
ObjectOutputStream singleDomainAdminCommandOs = xs.createObjectOutputStream(new FileWriter(domainAdminDirName + "/" + key + ".xml"), "command");
212+
writeCommand(singleDomainAdminCommandOs, key);
213+
singleDomainAdminCommandOs.close();
214+
}
215+
216+
if (regular_user_api_commands.containsKey(key)){
217+
writeCommand(regularUser, key);
218+
ObjectOutputStream singleRegularUserCommandOs = xs.createObjectOutputStream(new FileWriter(regularUserDirName + "/" + key + ".xml"), "command");
219+
writeCommand(singleRegularUserCommandOs, key);
220+
singleRegularUserCommandOs.close();
221+
}
177222
}
178223
}
179224

180225
//Write sorted commands
181226
it = all_api_commands_sorted.keySet().iterator();
182227
while (it.hasNext()) {
183228
String key = (String)it.next();
184-
writeCommand(rootAdminSorted, key);
185-
186-
187-
if (domain_admin_api_commands.containsKey(key)){
188-
writeCommand(outDomainAdminSorted, key);
189-
}
190229

191-
if (regular_user_api_commands.containsKey(key)){
192-
writeCommand(regularUserSorted, key);
230+
if (key.equals("login")) {
231+
writeLoginCommand(rootAdminSorted);
232+
writeLoginCommand(outDomainAdminSorted);
233+
writeLoginCommand(regularUserSorted);
234+
} else if (key.equals("logout")) {
235+
writeLogoutCommand(rootAdminSorted);
236+
writeLogoutCommand(outDomainAdminSorted);
237+
writeLogoutCommand(regularUserSorted);
238+
} else {
239+
writeCommand(rootAdminSorted, key);
240+
241+
if (domain_admin_api_commands.containsKey(key)){
242+
writeCommand(outDomainAdminSorted, key);
243+
}
244+
245+
if (regular_user_api_commands.containsKey(key)){
246+
writeCommand(regularUserSorted, key);
247+
}
193248
}
194249
}
195250

@@ -265,6 +320,60 @@ private static void writeCommand(ObjectOutputStream out, String command) throws
265320
out.writeObject(apiCommand);
266321
}
267322

323+
private static void writeLoginCommand(ObjectOutputStream out) throws ClassNotFoundException, IOException{
324+
ArrayList<Argument> request = new ArrayList<Argument>();
325+
ArrayList<Argument> response = new ArrayList<Argument>();
326+
327+
//Create a new command, set name and description
328+
Command apiCommand = new Command();
329+
apiCommand.setName("login");
330+
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.");
331+
332+
//Generate request
333+
request.add(new Argument("username", "Username", true));
334+
request.add(new Argument("password", "Password", true));
335+
request.add(new Argument("domainid", "domain ID that the user belongs to. If no domain ID is passed in, the ROOT domain is assumed.", false));
336+
apiCommand.setRequest(request);
337+
338+
//Generate response
339+
response.add(new Argument("username", "Username"));
340+
response.add(new Argument("userid", "User id"));
341+
response.add(new Argument("password", "Password"));
342+
response.add(new Argument("domainid", "domain ID that the user belongs to. If no domain ID is passed in, the ROOT domain is assumed."));
343+
response.add(new Argument("timeout", "the time period before the session has expired"));
344+
response.add(new Argument("account", "the account name the user belongs to"));
345+
response.add(new Argument("firstname", "first name of the user"));
346+
response.add(new Argument("lastname", "last name of the user"));
347+
response.add(new Argument("type", "the account type (admin, domain-admin, read-only-admin, user)"));
348+
response.add(new Argument("timezone", "user time zone"));
349+
response.add(new Argument("timezoneoffset", "user time zone offset from UTC 00:00"));
350+
response.add(new Argument("sessionkey", "Session key that can be passed in subsequent Query command calls"));
351+
apiCommand.setResponse(response);
352+
353+
out.writeObject(apiCommand);
354+
}
355+
356+
357+
private static void writeLogoutCommand(ObjectOutputStream out) throws ClassNotFoundException, IOException{
358+
ArrayList<Argument> request = new ArrayList<Argument>();
359+
ArrayList<Argument> response = new ArrayList<Argument>();
360+
361+
//Create a new command, set name and description
362+
Command apiCommand = new Command();
363+
apiCommand.setName("logout");
364+
apiCommand.setDescription("Logs out the user");
365+
366+
//Generate request - no request parameters
367+
apiCommand.setRequest(request);
368+
369+
//Generate response
370+
response.add(new Argument("success", "success if the logout action succeeded"));
371+
apiCommand.setResponse(response);
372+
373+
out.writeObject(apiCommand);
374+
}
375+
376+
268377

269378
private static ArrayList<Argument> setRequestFields(Field[] fields) {
270379
ArrayList<Argument> arguments = new ArrayList<Argument>();

‎server/src/com/cloud/api/doc/Argument.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ public Argument(String name) {
3030
this.name = name;
3131
}
3232

33+
public Argument(String name, String description, boolean required) {
34+
this.name = name;
35+
this.description = description;
36+
this.required = required;
37+
}
38+
39+
public Argument(String name, String description) {
40+
this.name = name;
41+
this.description = description;
42+
}
43+
3344
public String getName() {
3445
return name;
3546
}

0 commit comments

Comments
 (0)