Add java API wrapper for performing multiple config changes in one hit

This commit is contained in:
Jeremy Lakeman 2014-06-23 15:19:18 +09:30
parent 9f6ace518a
commit 7d86fcd573
2 changed files with 20 additions and 6 deletions

View File

@ -485,6 +485,21 @@ public class ServalDCommand
return result.toString();
}
public enum ConfigAction{
set,
del,
sync
};
public static void configActions(Object... arguments) throws ServalDFailureException {
// TODO we could verify the types and number of arguments here, though servald is about to do that anyway.
String args[] = new String[arguments.length+1];
args[0]="config";
for (int i=0;i<arguments.length;i++)
args[i+1]=arguments[i].toString();
ServalDCommand.command(args);
}
public static void deleteConfig(String name) throws ServalDFailureException {
ServalDCommand.command("config", "del", name);
}

View File

@ -95,12 +95,11 @@ public class ServerControl {
if (client==null) {
String restfulPassword = ServalDCommand.getConfigItem("rhizome.api.restful.users." + restfulUsername + ".password");
if (restfulPassword == null) {
String pwd = new BigInteger(130, new SecureRandom()).toString(32);
ServalDCommand.setConfigItem("rhizome.api.restful.users." + restfulUsername + ".password", pwd);
ServalDCommand.configSync();
restfulPassword = ServalDCommand.getConfigItem("rhizome.api.restful.users." + restfulUsername + ".password");
if (restfulPassword == null)
throw new ServalDInterfaceException("Failed to set restful password");
restfulPassword = new BigInteger(130, new SecureRandom()).toString(32);
ServalDCommand.configActions(
ServalDCommand.ConfigAction.set, "rhizome.api.restful.users." + restfulUsername + ".password", restfulPassword,
ServalDCommand.ConfigAction.sync
);
}
client = new ServalDClient(this.httpPort, restfulUsername, restfulPassword);
}