Expand the raw devfile url resolver pattern with token query parameter
parent
974c1b1890
commit
06ca8300e5
|
|
@ -22,6 +22,7 @@ import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import org.eclipse.che.api.core.ApiException;
|
import org.eclipse.che.api.core.ApiException;
|
||||||
import org.eclipse.che.api.core.BadRequestException;
|
import org.eclipse.che.api.core.BadRequestException;
|
||||||
|
|
@ -40,6 +41,7 @@ public class RawDevfileUrlFactoryParameterResolver extends BaseFactoryParameterR
|
||||||
implements FactoryParametersResolver {
|
implements FactoryParametersResolver {
|
||||||
|
|
||||||
private static final String PROVIDER_NAME = "raw-devfile-url";
|
private static final String PROVIDER_NAME = "raw-devfile-url";
|
||||||
|
private static final Pattern PATTERN = Pattern.compile("^https?://.*\\.ya?ml(\\?token=.*)?$");
|
||||||
|
|
||||||
protected final URLFactoryBuilder urlFactoryBuilder;
|
protected final URLFactoryBuilder urlFactoryBuilder;
|
||||||
protected final URLFetcher urlFetcher;
|
protected final URLFetcher urlFetcher;
|
||||||
|
|
@ -62,7 +64,7 @@ public class RawDevfileUrlFactoryParameterResolver extends BaseFactoryParameterR
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(Map<String, String> factoryParameters) {
|
public boolean accept(Map<String, String> factoryParameters) {
|
||||||
String url = factoryParameters.get(URL_PARAMETER_NAME);
|
String url = factoryParameters.get(URL_PARAMETER_NAME);
|
||||||
return !isNullOrEmpty(url) && (url.endsWith(".yaml") || url.endsWith(".yml"));
|
return !isNullOrEmpty(url) && PATTERN.matcher(url).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
package org.eclipse.che.api.factory.server;
|
package org.eclipse.che.api.factory.server;
|
||||||
|
|
||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
|
import static java.util.Collections.singletonMap;
|
||||||
import static org.eclipse.che.api.factory.shared.Constants.URL_PARAMETER_NAME;
|
import static org.eclipse.che.api.factory.shared.Constants.URL_PARAMETER_NAME;
|
||||||
import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE;
|
import static org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE;
|
||||||
import static org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE;
|
import static org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE;
|
||||||
|
|
@ -28,7 +29,6 @@ import static org.testng.Assert.fail;
|
||||||
import static org.testng.AssertJUnit.assertEquals;
|
import static org.testng.AssertJUnit.assertEquals;
|
||||||
import static org.testng.AssertJUnit.assertTrue;
|
import static org.testng.AssertJUnit.assertTrue;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.eclipse.che.api.core.BadRequestException;
|
import org.eclipse.che.api.core.BadRequestException;
|
||||||
|
|
@ -162,12 +162,11 @@ public class RawDevfileUrlFactoryParameterResolverTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dataProvider = "devfileNames")
|
@Test(dataProvider = "devfileUrls")
|
||||||
public void shouldAcceptRawDevfileUrl(String devfileName) {
|
public void shouldAcceptRawDevfileUrl(String url) {
|
||||||
// when
|
// when
|
||||||
boolean result =
|
boolean result =
|
||||||
rawDevfileUrlFactoryParameterResolver.accept(
|
rawDevfileUrlFactoryParameterResolver.accept(singletonMap(URL_PARAMETER_NAME, url));
|
||||||
Collections.singletonMap(URL_PARAMETER_NAME, "https://host/path/" + devfileName));
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(result);
|
assertTrue(result);
|
||||||
|
|
@ -178,7 +177,7 @@ public class RawDevfileUrlFactoryParameterResolverTest {
|
||||||
// when
|
// when
|
||||||
boolean result =
|
boolean result =
|
||||||
rawDevfileUrlFactoryParameterResolver.accept(
|
rawDevfileUrlFactoryParameterResolver.accept(
|
||||||
Collections.singletonMap(URL_PARAMETER_NAME, "https://host/user/repo.git"));
|
singletonMap(URL_PARAMETER_NAME, "https://host/user/repo.git"));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertFalse(result);
|
assertFalse(result);
|
||||||
|
|
@ -196,8 +195,17 @@ public class RawDevfileUrlFactoryParameterResolverTest {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider(name = "devfileNames")
|
@DataProvider(name = "devfileUrls")
|
||||||
private Object[] devfileNames() {
|
private Object[] devfileUrls() {
|
||||||
return new String[] {"devfile.yaml", ".devfile.yaml", "any-name.yaml", "any-name.yml"};
|
return new String[] {
|
||||||
|
"https://host/path/devfile.yaml",
|
||||||
|
"https://host/path/.devfile.yaml",
|
||||||
|
"https://host/path/any-name.yaml",
|
||||||
|
"https://host/path/any-name.yml",
|
||||||
|
"https://host/path/devfile.yaml?token=TOKEN123",
|
||||||
|
"https://host/path/.devfile.yaml?token=TOKEN123",
|
||||||
|
"https://host/path/any-name.yaml?token=TOKEN123",
|
||||||
|
"https://host/path/any-name.yml?token=TOKEN123"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue