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());
}
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());
}
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());
}
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);
}
}
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);
}
Aggregations