use of fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration in project Payara by payara.
the class SetConfigSecretsDirectory method execute.
@Override
public void execute(AdminCommandContext context) {
// do validation
Path directoryPath = Paths.get(directory);
boolean absolute = true;
boolean relativeFound = false;
if (!Files.isDirectory(directoryPath) || !Files.exists(directoryPath) || !Files.isReadable(directoryPath)) {
absolute = false;
// ok try relative to the server root
context.getActionReport().appendMessage("Could not find readable directory at " + directoryPath.toString() + "\n");
Path instanceRoot = env.getInstanceRoot().toPath();
Path relative = Paths.get(instanceRoot.toString(), directory);
if (!Files.isDirectory(relative) || !Files.exists(relative) || !Files.isReadable(relative)) {
context.getActionReport().appendMessage("Could not find readable directory at " + relative.toString() + "\n");
context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
relativeFound = true;
directoryPath = relative;
context.getActionReport().appendMessage("Using readable directory at " + relative.toString() + "\n");
} else {
context.getActionReport().appendMessage("Using readable directory at " + directoryPath.toString() + "\n");
}
Config configVal = targetUtil.getConfig(target);
MicroprofileConfigConfiguration serviceConfig = configVal.getExtensionByType(MicroprofileConfigConfiguration.class);
try {
final Path toSet = directoryPath;
ConfigSupport.apply(new SingleConfigCode<MicroprofileConfigConfiguration>() {
@Override
public Object run(MicroprofileConfigConfiguration t) throws PropertyVetoException, TransactionFailure {
t.setSecretDir(toSet.toString());
return null;
}
}, serviceConfig);
} catch (TransactionFailure ex) {
Logger.getLogger(SetConfigSecretsDirectory.class.getName()).log(Level.SEVERE, "Could not set Directory", ex);
context.getActionReport().failure(Logger.getLogger(this.getClass().getName()), "Could not set Directory", ex);
}
}
Aggregations