-
Notifications
You must be signed in to change notification settings - Fork 71
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
Add an SSH Factory parameter resolver for unsupported SCM providers #567
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d3fe5cf
commit
vinokurig 0617d4b
commit
vinokurig b514738
Merge branch 'main' of github.com:eclipse-che/che-server into che-22488
vinokurig 3aa2e71
Merge branch 'main' of https://github.com/eclipse-che/che-server into…
vinokurig cb1039b
commit
vinokurig ddbd139
Merge branch 'che-22488' of github.com:eclipse-che/che-server into ch…
vinokurig 29821bc
Merge branch 'main' of github.com:eclipse-che/che-server into che-22488
vinokurig 5c15a2c
commit
vinokurig 7d23f73
commit
vinokurig 69333d5
commit
vinokurig ca0086c
Update prefix message in 'fetchContentWithoutToken'
artaleks9 3523728
Fix fomatting
artaleks9 7c9dd62
Merge branch 'main' of github.com:eclipse-che/che-server into che-22488
vinokurig caa1272
Merge branch 'che-22488' of github.com:eclipse-che/che-server into ch…
vinokurig ca0becc
fix tests
vinokurig df025f6
add test
vinokurig 0a43a5c
fixup
vinokurig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
|
||
Copyright (c) 2012-2023 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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>che-master-parent</artifactId> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<version>7.75.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>che-core-api-factory-git-ssh</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Che Core :: API :: Factory Resolver Git Ssh</name> | ||
<properties> | ||
<findbugs.failonerror>true</findbugs.failonerror> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>jakarta.inject</groupId> | ||
<artifactId>jakarta.inject-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.validation</groupId> | ||
<artifactId>jakarta.validation-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-dto</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-api-factory</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-api-factory-shared</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-api-workspace-shared</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.tomakehurst</groupId> | ||
<artifactId>wiremock-jre8-standalone</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.servlet</groupId> | ||
<artifactId>jakarta.servlet-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.ws.rs</groupId> | ||
<artifactId>jakarta.ws.rs-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-commons-json</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-core</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.slf4j</groupId> | ||
<artifactId>jcl-over-slf4j</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
31 changes: 31 additions & 0 deletions
31
...java/org/eclipse/che/api/factory/server/git/ssh/GitSshAuthorizingFileContentProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2012-2023 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.api.factory.server.git.ssh; | ||
|
||
import org.eclipse.che.api.factory.server.scm.AuthorizingFileContentProvider; | ||
import org.eclipse.che.api.factory.server.scm.PersonalAccessTokenManager; | ||
import org.eclipse.che.api.workspace.server.devfile.URLFetcher; | ||
|
||
/** | ||
* Git Ssh specific authorizing file content provider. | ||
* | ||
* @author Anatolii Bazko | ||
*/ | ||
class GitSshAuthorizingFileContentProvider extends AuthorizingFileContentProvider<GitSshUrl> { | ||
|
||
GitSshAuthorizingFileContentProvider( | ||
GitSshUrl gitSshUrl, | ||
URLFetcher urlFetcher, | ||
PersonalAccessTokenManager personalAccessTokenManager) { | ||
super(gitSshUrl, urlFetcher, personalAccessTokenManager); | ||
} | ||
} |
136 changes: 136 additions & 0 deletions
136
...main/java/org/eclipse/che/api/factory/server/git/ssh/GitSshFactoryParametersResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* Copyright (c) 2012-2023 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.api.factory.server.git.ssh; | ||
|
||
import static org.eclipse.che.api.factory.server.FactoryResolverPriority.LOWEST; | ||
import static org.eclipse.che.api.factory.shared.Constants.CURRENT_VERSION; | ||
import static org.eclipse.che.api.factory.shared.Constants.URL_PARAMETER_NAME; | ||
import static org.eclipse.che.dto.server.DtoFactory.newDto; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import java.util.Map; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import org.eclipse.che.api.core.ApiException; | ||
import org.eclipse.che.api.factory.server.FactoryResolverPriority; | ||
import org.eclipse.che.api.factory.server.RawDevfileUrlFactoryParameterResolver; | ||
import org.eclipse.che.api.factory.server.scm.PersonalAccessTokenManager; | ||
import org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl; | ||
import org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder; | ||
import org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto; | ||
import org.eclipse.che.api.factory.shared.dto.FactoryDto; | ||
import org.eclipse.che.api.factory.shared.dto.FactoryMetaDto; | ||
import org.eclipse.che.api.factory.shared.dto.FactoryVisitor; | ||
import org.eclipse.che.api.factory.shared.dto.ScmInfoDto; | ||
import org.eclipse.che.api.workspace.server.devfile.URLFetcher; | ||
import org.eclipse.che.api.workspace.shared.dto.devfile.ProjectDto; | ||
import org.eclipse.che.api.workspace.shared.dto.devfile.SourceDto; | ||
|
||
/** | ||
* Provides Factory Parameters resolver for Git Ssh repositories. | ||
* | ||
* @author Anatolii Bazko | ||
*/ | ||
@Singleton | ||
public class GitSshFactoryParametersResolver extends RawDevfileUrlFactoryParameterResolver { | ||
vinokurig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final GitSshURLParser gitSshURLParser; | ||
|
||
private final PersonalAccessTokenManager personalAccessTokenManager; | ||
|
||
@Inject | ||
public GitSshFactoryParametersResolver( | ||
GitSshURLParser gitSshURLParser, | ||
URLFetcher urlFetcher, | ||
URLFactoryBuilder urlFactoryBuilder, | ||
PersonalAccessTokenManager personalAccessTokenManager) { | ||
super(urlFactoryBuilder, urlFetcher); | ||
this.gitSshURLParser = gitSshURLParser; | ||
this.personalAccessTokenManager = personalAccessTokenManager; | ||
} | ||
|
||
@Override | ||
public boolean accept(@NotNull final Map<String, String> factoryParameters) { | ||
return factoryParameters.containsKey(URL_PARAMETER_NAME) | ||
&& gitSshURLParser.isValid(factoryParameters.get(URL_PARAMETER_NAME)); | ||
} | ||
|
||
@Override | ||
public FactoryMetaDto createFactory(@NotNull final Map<String, String> factoryParameters) | ||
throws ApiException { | ||
// no need to check null value of url parameter as accept() method has performed the check | ||
final GitSshUrl gitSshUrl = gitSshURLParser.parse(factoryParameters.get(URL_PARAMETER_NAME)); | ||
|
||
// create factory from the following location if location exists, else create default factory | ||
return urlFactoryBuilder | ||
.createFactoryFromDevfile( | ||
gitSshUrl, | ||
new GitSshAuthorizingFileContentProvider( | ||
gitSshUrl, urlFetcher, personalAccessTokenManager), | ||
extractOverrideParams(factoryParameters), | ||
true) | ||
.orElseGet(() -> newDto(FactoryDto.class).withV(CURRENT_VERSION).withSource("repo")) | ||
.acceptVisitor(new GitSshFactoryVisitor(gitSshUrl)); | ||
} | ||
|
||
/** | ||
* Visitor that puts the default devfile or updates devfile projects into the Git Ssh Factory, if | ||
* needed. | ||
*/ | ||
private class GitSshFactoryVisitor implements FactoryVisitor { | ||
|
||
private final GitSshUrl gitSshUrl; | ||
|
||
private GitSshFactoryVisitor(GitSshUrl gitSshUrl) { | ||
this.gitSshUrl = gitSshUrl; | ||
} | ||
|
||
@Override | ||
public FactoryDevfileV2Dto visit(FactoryDevfileV2Dto factoryDto) { | ||
ScmInfoDto scmInfo = | ||
newDto(ScmInfoDto.class) | ||
.withScmProviderName(gitSshUrl.getProviderName()) | ||
.withRepositoryUrl(gitSshUrl.getRepositoryLocation()); | ||
return factoryDto.withScmInfo(scmInfo); | ||
} | ||
|
||
@Override | ||
public FactoryDto visit(FactoryDto factory) { | ||
if (factory.getDevfile() == null) { | ||
factory.setDevfile(urlFactoryBuilder.buildDefaultDevfile(gitSshUrl.getRepository())); | ||
} | ||
|
||
updateProjects( | ||
factory.getDevfile(), | ||
() -> | ||
newDto(ProjectDto.class) | ||
.withSource( | ||
newDto(SourceDto.class) | ||
.withLocation(gitSshUrl.getRepositoryLocation()) | ||
.withType("git")) | ||
.withName(gitSshUrl.getRepository()), | ||
project -> {}); | ||
|
||
return factory; | ||
} | ||
} | ||
|
||
@Override | ||
public RemoteFactoryUrl parseFactoryUrl(String factoryUrl) { | ||
return gitSshURLParser.parse(factoryUrl); | ||
} | ||
|
||
@Override | ||
public FactoryResolverPriority priority() { | ||
return LOWEST; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add
RawDevfileUrlFactoryParameterResolver
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RawDevfileUrlFactoryParameterResolver
does not implementScmFileResolver