Search in sources :

Example 11 with MicroprofileConfigConfiguration

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);
    }
}
Also used : Path(java.nio.file.Path) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) MicroprofileConfigConfiguration(fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration) Config(com.sun.enterprise.config.serverbeans.Config)

Aggregations

MicroprofileConfigConfiguration (fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration)11 Config (com.sun.enterprise.config.serverbeans.Config)7 Path (java.nio.file.Path)5 Properties (java.util.Properties)4 Test (org.junit.Test)4 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 PropertyVetoException (java.beans.PropertyVetoException)2 HashMap (java.util.HashMap)2 ActionReport (org.glassfish.api.ActionReport)2