Search in sources :

Example 6 with MicroprofileConfigConfiguration

use of fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration in project Payara by payara.

the class DirConfigSourceTest method testFindDir_AbsolutePath.

@Test
public void testFindDir_AbsolutePath() throws IOException {
    // given
    MicroprofileConfigConfiguration config = mock(MicroprofileConfigConfiguration.class);
    when(configService.getMPConfig()).thenReturn(config);
    when(config.getSecretDir()).thenReturn(testDirectory.toString());
    // when
    Optional<Path> sut = source.findDir();
    // then
    assertEquals(testDirectory, sut.get());
}
Also used : Path(java.nio.file.Path) MicroprofileConfigConfiguration(fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration) Test(org.junit.Test)

Example 7 with MicroprofileConfigConfiguration

use of fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration in project Payara by payara.

the class DirConfigSourceTest method testFindDir_NullPath.

@Test
public void testFindDir_NullPath() throws IOException {
    // given
    MicroprofileConfigConfiguration config = mock(MicroprofileConfigConfiguration.class);
    when(configService.getMPConfig()).thenReturn(config);
    when(config.getSecretDir()).thenReturn(null);
    // when
    Optional<Path> sut = source.findDir();
    // then
    assertFalse(sut.isPresent());
}
Also used : Path(java.nio.file.Path) MicroprofileConfigConfiguration(fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration) Test(org.junit.Test)

Example 8 with MicroprofileConfigConfiguration

use of fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration in project Payara by payara.

the class DirConfigSourceTest method testFindDir_NotExistingPath.

@Test
public void testFindDir_NotExistingPath() throws IOException {
    // given
    MicroprofileConfigConfiguration config = mock(MicroprofileConfigConfiguration.class);
    when(configService.getMPConfig()).thenReturn(config);
    when(config.getSecretDir()).thenReturn(DirConfigSource.DEFAULT_DIR);
    // when
    Optional<Path> sut = source.findDir();
    // then
    assertFalse(sut.isPresent());
}
Also used : Path(java.nio.file.Path) MicroprofileConfigConfiguration(fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration) Test(org.junit.Test)

Example 9 with MicroprofileConfigConfiguration

use of fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration in project Payara by payara.

the class BaseSetConfigSourceConfigurationCommand method execute.

@Override
public void execute(final AdminCommandContext context) {
    // Get the command report
    final ActionReport report = context.getActionReport();
    // Get the target configuration
    final Config targetConfig = targetUtil.getConfig(target);
    if (targetConfig == null) {
        report.setMessage("No such config named: " + target);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // Initialise the extra properties
    Properties extraProperties = report.getExtraProperties();
    if (extraProperties == null) {
        extraProperties = new Properties();
        report.setExtraProperties(extraProperties);
    }
    final MicroprofileConfigConfiguration mpConfigConfiguration = targetConfig.getExtensionByType(MicroprofileConfigConfiguration.class);
    Class<C> configSourceConfigClass = ConfigSourceExtensions.getConfigurationClass(getClass());
    C c = mpConfigConfiguration.getConfigSourceConfigurationByType(configSourceConfigClass);
    try {
        if (c == null) {
            ConfigSupport.apply(new SingleConfigCode<MicroprofileConfigConfiguration>() {

                @Override
                public Object run(final MicroprofileConfigConfiguration configurationProxy) throws PropertyVetoException, TransactionFailure {
                    C c = configurationProxy.createChild(configSourceConfigClass);
                    applyValues(report, c);
                    if (report.getActionExitCode() != ActionReport.ExitCode.FAILURE) {
                        configurationProxy.getConfigSourceConfigurationList().add(c);
                    } else {
                        c = null;
                    }
                    return c;
                }
            }, mpConfigConfiguration);
            c = mpConfigConfiguration.getConfigSourceConfigurationByType(configSourceConfigClass);
        } else {
            ConfigSupport.apply(new SingleConfigCode<C>() {

                public Object run(C cProxy) throws PropertyVetoException, TransactionFailure {
                    applyValues(report, cProxy);
                    return cProxy;
                }
            }, c);
        }
        // If the service is being changed dynamically
        if (dynamic) {
            if (server.isDas()) {
                if (targetUtil.getConfig(target).isDas()) {
                    configureDynamically(c);
                }
            } else {
                configureDynamically(c);
            }
        }
    } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Exception during command ", ex);
        report.setMessage(ex.getCause().getMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : 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) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties)

Example 10 with MicroprofileConfigConfiguration

use of fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration in project Payara by payara.

the class GetConfigSecretsDirectory method execute.

@Override
public void execute(AdminCommandContext context) {
    String result = "Not Found";
    Config configVal = targetUtil.getConfig(target);
    MicroprofileConfigConfiguration serviceConfig = configVal.getExtensionByType(MicroprofileConfigConfiguration.class);
    if (serviceConfig != null) {
        result = serviceConfig.getSecretDir();
    }
    context.getActionReport().setMessage("Directory" + ": " + result);
    Map<String, Object> extraPropertiesMap = new HashMap<>();
    extraPropertiesMap.put("directory", result);
    Properties extraProperties = new Properties();
    extraProperties.put("secretsDirectoryConfiguration", extraPropertiesMap);
    context.getActionReport().setExtraProperties(extraProperties);
}
Also used : MicroprofileConfigConfiguration(fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration) HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) Properties(java.util.Properties)

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