From 108eea7d87fe7b92fb2b603940b42155e50a2c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=81=8F?= Date: Fri, 5 May 2023 14:56:38 +0800 Subject: [PATCH] =?UTF-8?q?[imp]=20=E4=BF=AE=E6=94=B9=E5=81=A5=E5=BA=B7?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E6=8E=A5=E5=8F=A3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/task/GitlabConfigCommandRunner.java | 37 +++++++++++++++++++ .../infra/common/config/GitlabHealthy.java | 14 ------- 2 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 src/main/java/io/choerodon/gitlab/app/task/GitlabConfigCommandRunner.java 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(); } }