Skip to content

Commit

Permalink
[imp] 修改健康检查接口逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
王灏 committed May 5, 2023
1 parent 085c2a1 commit 108eea7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.choerodon.gitlab.app.task;

import org.gitlab4j.api.GitLabApi;
import org.gitlab4j.api.models.ApplicationSettings;
import org.gitlab4j.api.models.Setting;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
* 〈功能简述〉
* 〈〉
*
* @author wanghao
* @since 2023/5/5 14:53
*/
@Component
public class GitlabConfigCommandRunner implements CommandLineRunner {

@Value("${gitlab.url}")
private String url;

@Value("${gitlab.privateToken}")
private String privateToken;

@Override
public void run(String... args) throws Exception {
GitLabApi gitLabApi = new GitLabApi(url, privateToken);
ApplicationSettings applicationSettings = gitLabApi.getApplicationSettingsApi().getApplicationSettings();
if (!Boolean.TRUE.equals(applicationSettings.getSetting(Setting.ALLOW_LOCAL_REQUESTS_FROM_WEB_HOOKS_AND_SERVICES))) {
gitLabApi.getApplicationSettingsApi().updateApplicationSetting(Setting.ALLOW_LOCAL_REQUESTS_FROM_WEB_HOOKS_AND_SERVICES, true);
}
if (!Boolean.TRUE.equals(applicationSettings.getSetting(Setting.ALLOW_LOCAL_REQUESTS_FROM_SYSTEM_HOOKS))) {
gitLabApi.getApplicationSettingsApi().updateApplicationSetting(Setting.ALLOW_LOCAL_REQUESTS_FROM_SYSTEM_HOOKS, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import org.gitlab4j.api.GitLabApi;
import org.gitlab4j.api.GitLabApiException;
import org.gitlab4j.api.models.ApplicationSettings;
import org.gitlab4j.api.models.Setting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -12,7 +10,6 @@
import org.springframework.stereotype.Component;

import io.choerodon.core.exception.CommonException;
import io.choerodon.core.exception.FeignException;

@Component
public class GitlabHealthy implements HealthIndicator {
Expand Down Expand Up @@ -45,17 +42,6 @@ public Health health() {
if (errorCode == 401 || errorCode == 404) {
return Health.down().withDetail("Error Code", "the token or the url is error, or the ingress resolution error!").build();
} else {
try {
ApplicationSettings applicationSettings = gitLabApi.getApplicationSettingsApi().getApplicationSettings();
if (!Boolean.TRUE.equals(applicationSettings.getSetting(Setting.ALLOW_LOCAL_REQUESTS_FROM_WEB_HOOKS_AND_SERVICES))) {
gitLabApi.getApplicationSettingsApi().updateApplicationSetting(Setting.ALLOW_LOCAL_REQUESTS_FROM_WEB_HOOKS_AND_SERVICES, true);
}
if (!Boolean.TRUE.equals(applicationSettings.getSetting(Setting.ALLOW_LOCAL_REQUESTS_FROM_SYSTEM_HOOKS))) {
gitLabApi.getApplicationSettingsApi().updateApplicationSetting(Setting.ALLOW_LOCAL_REQUESTS_FROM_SYSTEM_HOOKS, true);
}
} catch (GitLabApiException e) {
throw new FeignException(e);
}
return Health.up().build();
}
}
Expand Down

0 comments on commit 108eea7

Please sign in to comment.