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

Set SAAS Gitlab url if endpint is not defined #733

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions wsmaster/che-core-api-factory-gitlab-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-workspace</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-lang</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
package org.eclipse.che.api.factory.server.gitlab;

import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSet;
import java.util.Set;
Expand All @@ -19,6 +21,7 @@
import org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException;
import org.eclipse.che.api.factory.server.scm.exception.ScmItemNotFoundException;
import org.eclipse.che.api.factory.server.scm.exception.ScmUnauthorizedException;
import org.eclipse.che.commons.annotation.Nullable;

/** Gitlab OAuth token retriever. */
public class AbstractGitlabUserDataFetcher extends AbstractGitUserDataFetcher {
Expand All @@ -29,14 +32,15 @@ public class AbstractGitlabUserDataFetcher extends AbstractGitUserDataFetcher {

public static final Set<String> DEFAULT_TOKEN_SCOPES =
ImmutableSet.of("api", "write_repository", "openid");
private static final String GITLAB_SAAS_ENDPOINT = "https://gitlab.com";

public AbstractGitlabUserDataFetcher(
String serverUrl,
@Nullable String serverUrl,
String apiEndpoint,
PersonalAccessTokenManager personalAccessTokenManager,
String providerName) {
super(providerName, serverUrl, personalAccessTokenManager);
this.serverUrl = serverUrl;
this.serverUrl = isNullOrEmpty(serverUrl) ? GITLAB_SAAS_ENDPOINT : serverUrl;
this.apiEndpoint = apiEndpoint;
this.providerName = providerName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.common.Slf4jNotifier;
import com.google.common.net.HttpHeaders;
import java.lang.reflect.Field;
import java.util.Optional;
import org.eclipse.che.api.factory.server.scm.GitUserData;
import org.eclipse.che.api.factory.server.scm.PersonalAccessToken;
Expand Down Expand Up @@ -88,4 +89,17 @@ public void shouldFetchGitUserData() throws Exception {
assertEquals(gitUserData.getScmUsername(), "John Smith");
assertEquals(gitUserData.getScmUserEmail(), "john@example.com");
}

@Test
public void shouldSetSAASUrlAsDefault() throws Exception {
gitlabUserDataFetcher =
new GitlabUserDataFetcher(null, "http://che.api", personalAccessTokenManager);

Field serverUrlField =
gitlabUserDataFetcher.getClass().getSuperclass().getDeclaredField("serverUrl");
serverUrlField.setAccessible(true);
String serverUrl = (String) serverUrlField.get(gitlabUserDataFetcher);

assertEquals(serverUrl, "https://gitlab.com");
}
}
Loading