fix: allow to override devfileFilename
parent
fc5a7c3de6
commit
f2bceb8b26
|
|
@ -60,7 +60,7 @@ public class URLFactoryBuilder {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(URLFactoryBuilder.class);
|
||||
|
||||
public static final String DEVFILE_NAME = "devfileName";
|
||||
public static final String DEVFILE_FILENAME = "devfileFilename";
|
||||
|
||||
private final String defaultCheEditor;
|
||||
private final String defaultChePlugins;
|
||||
|
|
@ -106,8 +106,8 @@ public class URLFactoryBuilder {
|
|||
String devfileYamlContent;
|
||||
|
||||
// Apply the new devfile name to look for
|
||||
if (overrideProperties.containsKey(DEVFILE_NAME)) {
|
||||
remoteFactoryUrl.setDevfileFilename(overrideProperties.get(DEVFILE_NAME));
|
||||
if (overrideProperties.containsKey(DEVFILE_FILENAME)) {
|
||||
remoteFactoryUrl.setDevfileFilename(overrideProperties.get(DEVFILE_FILENAME));
|
||||
}
|
||||
|
||||
for (DevfileLocation location : remoteFactoryUrl.devfileFileLocations()) {
|
||||
|
|
|
|||
|
|
@ -285,7 +285,8 @@ public class URLFactoryBuilderTest {
|
|||
};
|
||||
|
||||
String pathToDevfile = "my-custom-devfile-path.yaml";
|
||||
Map<String, String> propertiesMap = singletonMap(URLFactoryBuilder.DEVFILE_NAME, pathToDevfile);
|
||||
Map<String, String> propertiesMap =
|
||||
singletonMap(URLFactoryBuilder.DEVFILE_FILENAME, pathToDevfile);
|
||||
FactoryMetaDto factory =
|
||||
urlFactoryBuilder
|
||||
.createFactoryFromDevfile(githubLikeRemoteUrl, s -> myLocation + ".list", propertiesMap)
|
||||
|
|
|
|||
|
|
@ -42,12 +42,19 @@ import org.eclipse.che.api.workspace.server.devfile.exception.OverrideParameterE
|
|||
public class OverridePropertiesApplier {
|
||||
|
||||
private final List<String> allowedFirstSegments =
|
||||
asList("apiVersion", "metadata", "projects", "attributes");
|
||||
asList("apiVersion", "metadata", "projects", "attributes", "devfileFilename");
|
||||
|
||||
private final List<String> skipJsonSegments = asList("devfileFilename");
|
||||
|
||||
public JsonNode applyPropertiesOverride(
|
||||
JsonNode devfileNode, Map<String, String> overrideProperties)
|
||||
throws OverrideParameterException {
|
||||
for (Map.Entry<String, String> entry : overrideProperties.entrySet()) {
|
||||
|
||||
// skip some segment
|
||||
if (skipJsonSegments.contains(entry.getKey())) {
|
||||
continue;
|
||||
}
|
||||
String[] pathSegments = parseSegments(entry.getKey());
|
||||
if (pathSegments.length < 1) {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
package org.eclipse.che.api.workspace.server.devfile;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
|
@ -44,6 +45,27 @@ public class OverridePropertiesApplierTest {
|
|||
assertEquals(result.get("metadata").get("generateName").textValue(), "go");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotOverrideDevfileFilenameInDevfile() throws Exception {
|
||||
String json =
|
||||
"{"
|
||||
+ "\"apiVersion\": \"2.0.0\","
|
||||
+ "\"metadata\": {"
|
||||
+ " \"generateName\": \"python\""
|
||||
+ " }"
|
||||
+ "}";
|
||||
Map<String, String> overrides = new HashMap<>();
|
||||
overrides.put("devfileFilename", "devfile.v2");
|
||||
overrides.put("metadata.generateName", "go");
|
||||
// when
|
||||
JsonNode result = applier.applyPropertiesOverride(jsonMapper.readTree(json), overrides);
|
||||
|
||||
// then
|
||||
assertEquals(result.get("metadata").get("generateName").textValue(), "go");
|
||||
// this parameter is accepted but not added into the JSON
|
||||
assertNull(result.get("devfileFilename"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateUnExistingOverridePropertiesInDevfile() throws Exception {
|
||||
String json = "{" + "\"apiVersion\": \"1.0.0\"" + "}";
|
||||
|
|
@ -197,7 +219,7 @@ public class OverridePropertiesApplierTest {
|
|||
@Test(
|
||||
expectedExceptions = OverrideParameterException.class,
|
||||
expectedExceptionsMessageRegExp =
|
||||
"Override path 'commands.run.foo.bar' starts with an unsupported field pointer. Supported fields are \\{\"apiVersion\",\"metadata\",\"projects\"\\,\"attributes\"\\}.")
|
||||
"Override path 'commands.run.foo.bar' starts with an unsupported field pointer. Supported fields are \\{\"apiVersion\",\"metadata\",\"projects\"\\,\"attributes\"\\,\"devfileFilename\"\\}.")
|
||||
public void shouldThrowExceptionIfOverrideReferenceUsesUnsupportedField() throws Exception {
|
||||
String json =
|
||||
"{"
|
||||
|
|
|
|||
Loading…
Reference in New Issue