Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devfile local features implenentation with schema validation and automated model build. #11998

Merged
merged 54 commits into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
8317bd0
Initial commit
mshaposhnik Nov 1, 2018
76a381f
Initial implementation
mshaposhnik Nov 2, 2018
94754e2
fixup
mshaposhnik Nov 2, 2018
df92cac
Merge branch 'master' into devfile
mshaposhnik Nov 5, 2018
e9f8e95
Added create workspace from yaml method
mshaposhnik Nov 6, 2018
05c26ec
Apply devfile schema refacorings;
mshaposhnik Nov 8, 2018
c3ace6a
Apply new schema
mshaposhnik Nov 9, 2018
d428140
Merge branch 'master' into devfile
mshaposhnik Nov 9, 2018
137c52b
Add tests
mshaposhnik Nov 13, 2018
96ba661
Add tests & model fixups
mshaposhnik Nov 15, 2018
8e35675
fixup! Add tests & model fixups
mshaposhnik Nov 15, 2018
989e70c
Add n\l;
mshaposhnik Nov 15, 2018
0014ef6
Add schema & validation
mshaposhnik Nov 19, 2018
9a4c9d7
Merge branch 'master' into devfile
mshaposhnik Nov 19, 2018
984f964
Add pojo gen from schema
mshaposhnik Nov 19, 2018
b53b516
Add schema generation
mshaposhnik Nov 20, 2018
0a91ba7
Review fix
mshaposhnik Nov 21, 2018
71f5d17
Minor code refactorings
mshaposhnik Nov 21, 2018
93ce24c
Fixup
mshaposhnik Nov 22, 2018
aed2ec0
Merge branch 'master' into devfile-new
mshaposhnik Nov 22, 2018
8a3e5f0
Review fixes
mshaposhnik Nov 22, 2018
4e8ff8f
Merge branch 'master' into devfile-new
mshaposhnik Nov 22, 2018
b968538
Merge branch 'master' into devfile-new
mshaposhnik Nov 27, 2018
db334a4
Review fixes
mshaposhnik Nov 27, 2018
78ec48c
Review fixups;
mshaposhnik Nov 28, 2018
f2b5a80
Added ws name validation and verbose mode
mshaposhnik Nov 28, 2018
a786998
Chavge version -> spec version
mshaposhnik Nov 29, 2018
781134e
Review fixes
mshaposhnik Nov 29, 2018
f992bc4
Minor fixup
mshaposhnik Nov 30, 2018
ed8e224
Use schema provider in validator
mshaposhnik Nov 30, 2018
eab5132
Added tests
mshaposhnik Dec 1, 2018
ce0de4d
Fmt fix
mshaposhnik Dec 1, 2018
decb524
Rename class
mshaposhnik Dec 1, 2018
80c7382
Minor fixes
mshaposhnik Dec 2, 2018
c99c3bc
Code fix
mshaposhnik Dec 2, 2018
62c4012
Code fix
mshaposhnik Dec 2, 2018
786fc90
Code fix
mshaposhnik Dec 2, 2018
0c9f2ce
Review fixes
mshaposhnik Dec 3, 2018
a392a65
Merge branch 'master' into devfile-new
mshaposhnik Dec 3, 2018
1a3c281
Review fixes
mshaposhnik Dec 3, 2018
414800b
Review fixes
mshaposhnik Dec 3, 2018
d6c5df1
Add swagger docs
mshaposhnik Dec 3, 2018
8fc4213
Review fixes
mshaposhnik Dec 3, 2018
e90cb39
Fix javadocs
mshaposhnik Dec 3, 2018
cd9c8d2
Code fixups
mshaposhnik Dec 3, 2018
dbd754b
Review fixes
mshaposhnik Dec 4, 2018
b0165f3
Add permissions for devfile export method
mshaposhnik Dec 5, 2018
1cc89bf
Fixup
mshaposhnik Dec 5, 2018
1d7f5c4
Minor fixups
mshaposhnik Dec 5, 2018
5fb7f9f
Merge branch 'master' into devfile-new
mshaposhnik Dec 6, 2018
ff05d07
Upgrade version
mshaposhnik Dec 6, 2018
597bb77
Rename test method
mshaposhnik Dec 6, 2018
a1bbe9f
Use IOutil to read file
mshaposhnik Dec 6, 2018
33116b0
Use IOutil to read file
mshaposhnik Dec 6, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions assembly/assembly-wsmaster-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-devfile</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-factory</artifactId>
Expand Down Expand Up @@ -305,6 +309,10 @@
<groupId>org.eclipse.che.multiuser</groupId>
<artifactId>che-multiuser-machine-authentication</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.multiuser</groupId>
<artifactId>che-multiuser-permission-devfile</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.multiuser</groupId>
<artifactId>che-multiuser-permission-factory</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.eclipse.che.api.core.rest.CheJsonProvider;
import org.eclipse.che.api.core.rest.MessageBodyAdapter;
import org.eclipse.che.api.core.rest.MessageBodyAdapterInterceptor;
import org.eclipse.che.api.devfile.server.DevfileSchemaValidator;
import org.eclipse.che.api.devfile.server.DevfileService;
import org.eclipse.che.api.factory.server.FactoryAcceptValidator;
import org.eclipse.che.api.factory.server.FactoryCreateValidator;
import org.eclipse.che.api.factory.server.FactoryEditValidator;
Expand Down Expand Up @@ -154,6 +156,9 @@ protected void configure() {
bind(org.eclipse.che.api.user.server.PreferencesService.class);
bind(org.eclipse.che.security.oauth.OAuthAuthenticationService.class);

bind(DevfileSchemaValidator.class);
bind(DevfileService.class);

MapBinder<String, String> stacks =
MapBinder.newMapBinder(
binder(), String.class, String.class, Names.named(StackLoader.CHE_PREDEFINED_STACKS));
Expand Down Expand Up @@ -371,6 +376,7 @@ private void configureMultiUserMode(
bind(org.eclipse.che.multiuser.permission.logger.LoggerServicePermissionsFilter.class);

bind(org.eclipse.che.multiuser.permission.factory.FactoryPermissionsFilter.class);
bind(org.eclipse.che.multiuser.permission.devfile.DevfilePermissionsFilter.class);
bind(
org.eclipse.che.multiuser.permission.installer.InstallerRegistryServicePermissionsFilter
.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
*/
public interface Command {

/**
* {@link Command} attribute which indicates the working directory where the given command must be
* run
*/
String WORKING_DIRECTORY_ATTRIBUTE = "workingDir";

/**
* Returns command name (i.e. 'start tomcat') The name should be unique per user in one workspace,
* which means that user may create only one command with the same name in the same workspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import static java.lang.String.format;
import static java.util.Collections.emptyList;
import static org.eclipse.che.api.core.model.workspace.config.Command.WORKING_DIRECTORY_ATTRIBUTE;
import static org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposerFactoryProvider.SECURE_EXPOSER_IMPL_PROPERTY;

import com.google.common.annotations.Beta;
Expand Down Expand Up @@ -212,7 +213,7 @@ private CommandImpl asCommand(String machineName, Command command) {
command.getName(),
command.getCommand().stream().collect(Collectors.joining(" ")),
"custom");
cmd.getAttributes().put("workDir", command.getWorkingDir());
cmd.getAttributes().put(WORKING_DIRECTORY_ATTRIBUTE, command.getWorkingDir());
cmd.getAttributes().put("machineName", machineName);
return cmd;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.eclipse.che.api.core.model.workspace.config.Command.WORKING_DIRECTORY_ATTRIBUTE;
import static org.eclipse.che.api.core.model.workspace.config.MachineConfig.MEMORY_LIMIT_ATTRIBUTE;
import static org.eclipse.che.commons.lang.NameGenerator.generate;
import static org.eclipse.che.workspace.infrastructure.kubernetes.Constants.CHE_ORIGINAL_NAME_LABEL;
Expand Down Expand Up @@ -136,7 +137,8 @@ public void shouldProvisionPluginsCommandsToEnvironment() throws Exception {
envCommand.getCommandLine(),
pluginCommand.getCommand().stream().collect(Collectors.joining(" ")));
assertEquals(envCommand.getType(), "custom");
assertEquals(envCommand.getAttributes().get("workDir"), pluginCommand.getWorkingDir());
assertEquals(
envCommand.getAttributes().get(WORKING_DIRECTORY_ATTRIBUTE), pluginCommand.getWorkingDir());
assertEquals(envCommand.getAttributes().get("machineName"), POD_NAME + "/plugin-container");
}

Expand Down
122 changes: 122 additions & 0 deletions multiuser/permission/che-multiuser-permission-devfile/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2012-2018 Red Hat, Inc.
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
which is available at https://www.eclipse.org/legal/epl-2.0/

SPDX-License-Identifier: EPL-2.0

Contributors:
Red Hat, Inc. - initial API and implementation

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>che-multiuser-permission</artifactId>
<groupId>org.eclipse.che.multiuser</groupId>
<version>6.16.0-SNAPSHOT</version>
</parent>
<artifactId>che-multiuser-permission-devfile</artifactId>
<name>Che Multiuser :: Devfile Permissions</name>
<dependencies>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-devfile</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-workspace</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-test</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.multiuser</groupId>
<artifactId>che-multiuser-api-permission</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.multiuser</groupId>
<artifactId>che-multiuser-permission-workspace</artifactId>
</dependency>
<dependency>
<groupId>org.everrest</groupId>
<artifactId>everrest-core</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-dto</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-factory-shared</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.everrest</groupId>
<artifactId>everrest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<!-- compiler inlines constants, so it is impossible to find reference on dependency -->
<execution>
<id>analyze</id>
<configuration>
<ignoredDependencies>
<ignoreDependency>org.eclipse.che.multiuser:che-multiuser-api-permission</ignoreDependency>
<ignoreDependency>org.eclipse.che.core:che-core-api-devfile</ignoreDependency>
</ignoredDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.multiuser.permission.devfile;

import javax.inject.Inject;
import javax.ws.rs.Path;
import org.eclipse.che.api.core.ForbiddenException;
import org.eclipse.che.api.core.NotFoundException;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.devfile.server.DevfileService;
import org.eclipse.che.api.workspace.server.WorkspaceManager;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl;
import org.eclipse.che.commons.env.EnvironmentContext;
import org.eclipse.che.commons.subject.Subject;
import org.eclipse.che.everrest.CheMethodInvokerFilter;
import org.eclipse.che.multiuser.permission.workspace.server.WorkspaceDomain;
import org.everrest.core.Filter;
import org.everrest.core.resource.GenericResourceMethod;

/** Restricts access to methods of {@link DevfileService} by user's permissions. */
@Filter
@Path("/devfile{path:(/.*)?}")
public class DevfilePermissionsFilter extends CheMethodInvokerFilter {

private final WorkspaceManager workspaceManager;

@Inject
public DevfilePermissionsFilter(WorkspaceManager workspaceManager) {
this.workspaceManager = workspaceManager;
}

@Override
protected void filter(GenericResourceMethod genericResourceMethod, Object[] arguments)
throws ForbiddenException, NotFoundException, ServerException {
final String methodName = genericResourceMethod.getMethod().getName();
switch (methodName) {
// public methods
case "getSchema":
case "createFromYaml":
return;
case "createFromWorkspace":
{
// check user has reading rights
checkPermissionsWithCompositeKey((String) arguments[0]);
return;
}
default:
throw new ForbiddenException("The user does not have permission to perform this operation");
}
}

private void checkPermissionsWithCompositeKey(String key)
throws ForbiddenException, NotFoundException, ServerException {
final Subject currentSubject = EnvironmentContext.getCurrent().getSubject();
if (!key.contains(":") && !key.contains("/")) {
// key is id
currentSubject.checkPermission(WorkspaceDomain.DOMAIN_ID, key, WorkspaceDomain.READ);
} else {
final WorkspaceImpl workspace = workspaceManager.getWorkspace(key);
currentSubject.checkPermission(
WorkspaceDomain.DOMAIN_ID, workspace.getId(), WorkspaceDomain.READ);
}
}
}
Loading