mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-20 09:26:37 +00:00
Add java API wrapper for performing multiple config changes in one hit
This commit is contained in:
parent
9f6ace518a
commit
7d86fcd573
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user