diff --git a/src/main/java/io/choerodon/gitlab/app/task/GitlabConfigCommandRunner.java b/src/main/java/io/choerodon/gitlab/app/task/GitlabConfigCommandRunner.java new file mode 100644 index 0000000..2d8597f --- /dev/null +++ b/src/main/java/io/choerodon/gitlab/app/task/GitlabConfigCommandRunner.java @@ -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); + } + } +} diff --git a/src/main/java/io/choerodon/gitlab/infra/common/config/GitlabHealthy.java b/src/main/java/io/choerodon/gitlab/infra/common/config/GitlabHealthy.java index 054a83d..a45ee0d 100644 --- a/src/main/java/io/choerodon/gitlab/infra/common/config/GitlabHealthy.java +++ b/src/main/java/io/choerodon/gitlab/infra/common/config/GitlabHealthy.java @@ -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; @@ -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 { @@ -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(); } }