public class GitLabRestClient {
- private static final String API_SUFFIX = "/api/v4";
+ private final GitLabSettings gitLabSettings;
- private final GitLabSettings settings;
-
- public GitLabRestClient(GitLabSettings settings) {
- this.settings = settings;
+ public GitLabRestClient(GitLabSettings gitLabSettings) {
+ this.gitLabSettings = gitLabSettings;
}
GsonUser getUser(OAuth20Service scribe, OAuth2AccessToken accessToken) {
- try (Response response = OAuthRestClient.executeRequest(settings.url() + API_SUFFIX + "/user", scribe, accessToken)) {
+ try (Response response = OAuthRestClient.executeRequest(gitLabSettings.apiUrl() + "/user", scribe, accessToken)) {
String responseBody = response.getBody();
return GsonUser.parse(responseBody);
} catch (IOException e) {
}
List<GsonGroup> getGroups(OAuth20Service scribe, OAuth2AccessToken accessToken) {
- return OAuthRestClient.executePaginatedRequest(settings.url() + API_SUFFIX + "/groups?min_access_level=10", scribe, accessToken, GsonGroup::parse);
+ return OAuthRestClient.executePaginatedRequest(gitLabSettings.apiUrl() + "/groups?min_access_level=10", scribe, accessToken, GsonGroup::parse);
}
}
return url;
}
+ public String apiUrl() {
+ return url() + "/api/v4";
+ }
+
public String applicationId() {
return configuration.get(GITLAB_AUTH_APPLICATION_ID).orElse(null);
}
.build(),
PropertyDefinition.builder(GITLAB_AUTH_URL)
.name("GitLab URL")
- .description("URL to access GitLab.")
+ .description("Base URL to access GitLab. https://gitlab.com for Gitlab SaaS")
.category(CATEGORY)
.subCategory(SUBCATEGORY)
.defaultValue("https://gitlab.com")
@Test
public void test_settings() {
assertThat(config.url()).isEqualTo("https://gitlab.com");
+ assertThat(config.apiUrl()).isEqualTo("https://gitlab.com/api/v4");
- settings.setProperty(GITLAB_AUTH_URL, "https://gitlab.com/api/");
- assertThat(config.url()).isEqualTo("https://gitlab.com/api");
+ settings.setProperty(GITLAB_AUTH_URL, "https://onpremise.gitlab.com/");
+ assertThat(config.url()).isEqualTo("https://onpremise.gitlab.com");
+ assertThat(config.apiUrl()).isEqualTo("https://onpremise.gitlab.com/api/v4");
- settings.setProperty(GITLAB_AUTH_URL, "https://gitlab.com/api");
- assertThat(config.url()).isEqualTo("https://gitlab.com/api");
+ settings.setProperty(GITLAB_AUTH_URL, "https://onpremise.gitlab.com");
+ assertThat(config.url()).isEqualTo("https://onpremise.gitlab.com");
+ assertThat(config.apiUrl()).isEqualTo("https://onpremise.gitlab.com/api/v4");
assertThat(config.isEnabled()).isFalse();
settings.setProperty(GITLAB_AUTH_ENABLED, "true");