use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project devspaces-images by redhat-developer.
the class ProjectConverter method sanitizeClonePath.
private String sanitizeClonePath(String clonePath) throws DevfileException {
URI uri = clonePathToURI(clonePath);
if (uri.isAbsolute()) {
throw new DevfileException("The clonePath must be a relative path. This seems to be an URI with a scheme: " + clonePath);
}
uri = uri.normalize();
String path = uri.getPath();
if (path.isEmpty()) {
// the user tried to trick us with something like "blah/.."
throw new DevfileException("Cloning directly into projects root is not allowed." + " The clonePath that resolves to empty path: " + clonePath);
}
if (path.startsWith("/")) {
// user-authored. Just don't give the user impression we can support absolute paths.
throw new DevfileException("The clonePath must be a relative. This seems to be an absolute path: " + clonePath);
}
if (path.startsWith("..")) {
// an attempt to escape the projects root, e.g. "ich/../muss/../../raus". That's a no-no.
throw new DevfileException("The clonePath cannot escape the projects root. Don't use .. to try and do that." + " The invalid path was: " + clonePath);
}
return path;
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project devspaces-images by redhat-developer.
the class EditorComponentToWorkspaceApplier method apply.
/**
* Applies changes on workspace config according to the specified editor component.
*
* @param workspaceConfig workspace config on which changes should be applied
* @param editorComponent plugin component that should be applied
* @param contentProvider optional content provider that may be used for external component
* resource fetching
* @throws IllegalArgumentException if specified workspace config or plugin component is null
* @throws IllegalArgumentException if specified component has type different from cheEditor
*/
@Override
public void apply(WorkspaceConfigImpl workspaceConfig, ComponentImpl editorComponent, FileContentProvider contentProvider) throws DevfileException {
checkArgument(workspaceConfig != null, "Workspace config must not be null");
checkArgument(editorComponent != null, "Component must not be null");
checkArgument(EDITOR_COMPONENT_TYPE.equals(editorComponent.getType()), format("Plugin must have `%s` type", EDITOR_COMPONENT_TYPE));
final String editorComponentAlias = editorComponent.getAlias();
final String editorId = editorComponent.getId();
final String registryUrl = editorComponent.getRegistryUrl();
final ExtendedPluginFQN fqn = componentFQNParser.evaluateFQN(editorComponent, contentProvider);
if (!isNullOrEmpty(fqn.getReference())) {
workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, fqn.getReference());
} else {
workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, componentFQNParser.getCompositeId(registryUrl, editorId));
}
workspaceConfig.getCommands().stream().filter(c -> editorComponentAlias != null && editorComponentAlias.equals(c.getAttributes().get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE))).forEach(c -> c.getAttributes().put(PLUGIN_ATTRIBUTE, fqn.getId()));
// make sure id is set to be able to match component with plugin broker result
// when referenceContent is used
editorComponent.setId(fqn.getId());
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project devspaces-images by redhat-developer.
the class DevfileVersionDetector method devfileMajorVersion.
/**
* Gives major version of the devfile.
*
* <pre>
* 1 -> 1
* 1.0.0 -> 1
* 1.99 -> 1
* 2.0.0 -> 2
* 2.1 -> 2
* a.a -> DevfileException
* a -> DevfileException
* </pre>
*
* @param devfile to inspect
* @return major version of the devfile
* @throws DevfileException when can't find the field with version
*/
public int devfileMajorVersion(JsonNode devfile) throws DevfileException {
String version = devfileVersion(devfile);
int dot = version.indexOf(".");
final String majorVersion = dot > 0 ? version.substring(0, dot) : version;
try {
return Integer.parseInt(majorVersion);
} catch (NumberFormatException nfe) {
throw new DevfileException("Unable to parse devfile version. This is not a valid devfile.", nfe);
}
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project devspaces-images by redhat-developer.
the class PluginFQNParser method evaluateFqn.
/**
* Evaluates plugin FQN from provided reference by trying to fetch and parse its meta information.
*
* @param reference plugin reference to evaluate FQN from
* @param fileContentProvider content provider instance to perform plugin meta requests
* @return plugin FQN evaluated from given reference
* @throws InfrastructureException if plugin reference is invalid or inaccessible
*/
public ExtendedPluginFQN evaluateFqn(String reference, FileContentProvider fileContentProvider) throws InfrastructureException {
JsonNode contentNode;
try {
String pluginMetaContent = fileContentProvider.fetchContent(reference);
contentNode = yamlReader.readTree(pluginMetaContent);
} catch (DevfileException | IOException e) {
throw new InfrastructureException(format("Plugin reference URL '%s' is invalid.", reference), e);
}
JsonNode publisher = contentNode.path("publisher");
if (publisher.isMissingNode()) {
throw new InfrastructureException(formatMessage(reference, "publisher"));
}
JsonNode name = contentNode.get("name");
if (name.isMissingNode()) {
throw new InfrastructureException(formatMessage(reference, "name"));
}
JsonNode version = contentNode.get("version");
if (version.isMissingNode()) {
throw new InfrastructureException(formatMessage(reference, "version"));
}
if (!version.isValueNode()) {
throw new InfrastructureException(format("Plugin specified by reference URL '%s' has version field that cannot be parsed to string", reference));
}
return new ExtendedPluginFQN(reference, publisher.textValue(), name.textValue(), version.asText());
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project devspaces-images by redhat-developer.
the class KubernetesComponentToWorkspaceApplierTest method shouldThrowExceptionWhenRecipeComponentIsPresentAndContentProviderDoesNotSupportFetching.
@Test(expectedExceptions = DevfileException.class, expectedExceptionsMessageRegExp = "Fetching content of file `reference.yaml` specified in `reference` field of component `foo` is not " + "supported. Please provide its content in `referenceContent` field. Cause: fetch is not supported")
public void shouldThrowExceptionWhenRecipeComponentIsPresentAndContentProviderDoesNotSupportFetching() throws Exception {
// given
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
// when
applier.apply(workspaceConfig, component, e -> {
throw new DevfileException("fetch is not supported");
});
}
Aggregations