Skip to content

Commit

Permalink
Merge pull request #209 from istraka/issue_#208
Browse files Browse the repository at this point in the history
[#208] Allow config properties in template definitions & allow empty parameters
  • Loading branch information
istraka authored Jun 10, 2023
2 parents ef2b35b + 590a2de commit 70fdd29
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void deployCfTemplate(WithAwsCfTemplate awsTemplateDefinition, AwsSunsto
AwsCloudFormationCloudDeploymentManager deploymentManager = store.getAwsCfDemploymentManagerOrCreate();

try {
String content = getResourceContent(awsTemplateDefinition.template());
String content = getResourceContent(SunstoneConfig.resolveExpressionToString(awsTemplateDefinition.template()));
Map<String, String> parameters = getParameters(awsTemplateDefinition.parameters());
String region = SunstoneConfig.resolveExpressionToString(awsTemplateDefinition.region());
if (region == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void deployArmTemplate(WithAzureArmTemplate armTemplateDefinition, Azure

String content = null;
try {
content = getResourceContent(armTemplateDefinition.template());
content = getResourceContent(SunstoneConfig.resolveExpressionToString(armTemplateDefinition.template()));
String group = SunstoneConfig.resolveExpressionToString(armTemplateDefinition.group());
if (group == null) {
throw new IllegalArgumentSunstoneException("Resource group for Azure ARM template is not defined. "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import java.util.HashMap;
import java.util.Map;

import static sunstone.core.SunstoneConfig.resolveExpression;
import static sunstone.core.SunstoneConfig.resolveOptionalExpression;

/**
* Abstract class for providing common functionality for deploy operation to clouds. Tha class focuses on utilizing
* work flow regarding getting resources, parameters and so on.
Expand All @@ -25,7 +28,7 @@ protected static Map<String, String> getParameters(Parameter[] parameters) {
for (int i = 0; i < parameters.length; i++) {
parametersMap.put(parameters[i].k(), parameters[i].v());
}
parametersMap.forEach((key, value) -> parametersMap.put(key, SunstoneConfig.resolveExpressionToString(value)));
parametersMap.forEach((key, value) -> parametersMap.put(resolveExpression(key, String.class), resolveOptionalExpression(value, String.class).orElse("")));
return Collections.unmodifiableMap(parametersMap);
}

Expand Down
8 changes: 6 additions & 2 deletions core/src/main/java/sunstone/core/SunstoneConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.junit.platform.commons.util.StringUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -89,6 +89,10 @@ public static <V> V resolveExpression(String expression, Class<V> clazz) {
return config.getValue(SunstoneExpressionSource.registerExpression(expression), clazz);
}

public static <V> Optional<V> resolveOptionalExpression(String expression, Class<V> clazz) {
return config.getOptionalValue(SunstoneExpressionSource.registerExpression(expression), clazz);
}


/**
*
Expand Down Expand Up @@ -116,7 +120,7 @@ public static <V> V resolveExpression(String expression, Class<V> clazz) {
*
*/
public static String resolveExpressionToString(String expression) {
return StringUtils.isBlank(expression) ? expression : resolveExpression(expression, String.class);
return resolveExpression(expression, String.class);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/sunstone/core/SunstoneExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
import org.junit.platform.commons.support.AnnotationSupport;
import org.junit.platform.commons.support.HierarchyTraversalMode;
import org.junit.platform.commons.util.StringUtils;
import sunstone.annotation.AbstractSetupTask;
import sunstone.annotation.Setup;
import sunstone.annotation.SunstoneCloudDeployAnnotation;
Expand Down Expand Up @@ -191,7 +192,7 @@ static void performDeploymentOperation(ExtensionContext ctx) throws SunstoneExce
throw new IllegalArgumentSunstoneException("Deployment method must have 0 parameters");
}
Deployment annotation = method.getAnnotation(Deployment.class);
String deploymentName = SunstoneConfig.resolveExpressionToString(annotation.name());
String deploymentName = StringUtils.isBlank(annotation.name()) ? "" : SunstoneConfig.resolveExpressionToString(annotation.name());

method.setAccessible(true);
Object invoke = method.invoke(null);
Expand Down

0 comments on commit 70fdd29

Please sign in to comment.