Search in sources :

Example 36 with DevfileException

use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.

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;
}
Also used : URI(java.net.URI) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)

Example 37 with DevfileException

use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.

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());
}
Also used : PLUGIN_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.PLUGIN_ATTRIBUTE) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) WORKSPACE_TOOLING_EDITOR_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE) String.format(java.lang.String.format) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) ComponentToWorkspaceApplier(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier) Inject(javax.inject.Inject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) COMPONENT_ALIAS_COMMAND_ATTRIBUTE(org.eclipse.che.api.workspace.server.devfile.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE) EDITOR_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE) ComponentFQNParser(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentFQNParser) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN)

Example 38 with DevfileException

use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project devspaces-images by redhat-developer.

the class URLFileContentProvider method fetchContent.

@Override
public String fetchContent(String fileURL) throws IOException, DevfileException {
    URI fileURI;
    String requestURL;
    try {
        fileURI = new URI(fileURL);
    } catch (URISyntaxException e) {
        throw new DevfileException(e.getMessage(), e);
    }
    if (fileURI.isAbsolute()) {
        requestURL = fileURL;
    } else {
        if (devfileLocation == null) {
            throw new DevfileException(format("It is unable to fetch a file %s as relative to devfile, since devfile location" + " is unknown. Try specifying absolute URL.", fileURL));
        }
        requestURL = devfileLocation.resolve(fileURI).toString();
    }
    try {
        return urlFetcher.fetch(requestURL);
    } catch (IOException e) {
        throw new IOException(format("Failed to fetch a file from URL %s. Make sure the URL" + " of the devfile points to the raw content of it (e.g. not to the webpage" + " showing it but really just its contents). Additionally, if you're using " + " relative form, make sure the referenced files are actually stored" + " relative to the devfile on the same host," + " or try to specify URL in absolute form. The current attempt to download" + " the file failed with the following error message: %s", fileURL, e.getMessage()), e);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)

Example 39 with DevfileException

use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project devspaces-images by redhat-developer.

the class DefaultEditorProvisioner method provisionAsyncStoragePlugin.

/**
 * Provision the for async storage service, it will provide ability backup and restore project
 * source using special storage. Will torn on only if workspace start in Ephemeral mode and has
 * attribute 'asyncPersist = true'
 *
 * @param components The set of components currently present in the Devfile
 * @param contentProvider content provider for plugin references retrieval
 * @throws DevfileException - A DevfileException containing any caught InfrastructureException
 */
private void provisionAsyncStoragePlugin(List<ComponentImpl> components, FileContentProvider contentProvider) throws DevfileException {
    try {
        Map<String, String> missingPluginsIdToRef = Collections.singletonMap(componentFQNParser.getPluginPublisherAndName(asyncStoragePluginRef), asyncStoragePluginRef);
        addMissingPlugins(components, contentProvider, missingPluginsIdToRef);
    } catch (InfrastructureException e) {
        throw new DevfileException(e.getMessage(), e);
    }
}
Also used : DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 40 with DevfileException

use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project devspaces-images by redhat-developer.

the class DefaultEditorProvisioner method provisionDefaultPlugins.

/**
 * Provision the default editor plugins and add them to the the Devfile's component list
 *
 * @param components The set of components currently present in the Devfile
 * @param contentProvider content provider for plugin references retrieval
 * @throws DevfileException - A DevfileException containing any caught InfrastructureException
 */
private void provisionDefaultPlugins(List<ComponentImpl> components, FileContentProvider contentProvider) throws DevfileException {
    Map<String, String> missingPluginsIdToRef = new HashMap<>(defaultPluginsToRefs);
    removeAlreadyAddedPlugins(components, contentProvider, missingPluginsIdToRef);
    try {
        addMissingPlugins(components, contentProvider, missingPluginsIdToRef);
    } catch (InfrastructureException e) {
        throw new DevfileException(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Aggregations

DevfileException (org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)52 Test (org.testng.annotations.Test)22 IOException (java.io.IOException)20 ApiException (org.eclipse.che.api.core.ApiException)18 FileContentProvider (org.eclipse.che.api.workspace.server.devfile.FileContentProvider)18 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)16 HashMap (java.util.HashMap)14 List (java.util.List)14 DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)14 Map (java.util.Map)12 Optional (java.util.Optional)12 ServerException (org.eclipse.che.api.core.ServerException)12 ExtendedError (org.eclipse.che.api.core.rest.shared.dto.ExtendedError)12 ScmCommunicationException (org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException)12 ScmUnauthorizedException (org.eclipse.che.api.factory.server.scm.exception.ScmUnauthorizedException)12 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 Collections (java.util.Collections)10 UnauthorizedException (org.eclipse.che.api.core.UnauthorizedException)10 UnknownScmProviderException (org.eclipse.che.api.factory.server.scm.exception.UnknownScmProviderException)10