|
3 | 3 | import static io.kafbat.ui.api.model.AuthType.DISABLED; |
4 | 4 | import static io.kafbat.ui.api.model.AuthType.OAUTH2; |
5 | 5 | import static io.kafbat.ui.model.ApplicationInfoDTO.EnabledFeaturesEnum; |
| 6 | +import static io.kafbat.ui.util.GithubReleaseInfo.GITHUB_RELEASE_INFO_ENABLED; |
6 | 7 | import static io.kafbat.ui.util.GithubReleaseInfo.GITHUB_RELEASE_INFO_TIMEOUT; |
7 | 8 |
|
8 | 9 | import com.google.common.annotations.VisibleForTesting; |
@@ -44,36 +45,49 @@ public ApplicationInfoService(DynamicConfigOperations dynamicConfigOperations, |
44 | 45 | ApplicationContext applicationContext, |
45 | 46 | @Autowired(required = false) BuildProperties buildProperties, |
46 | 47 | @Autowired(required = false) GitProperties gitProperties, |
| 48 | + @Value("${" + GITHUB_RELEASE_INFO_ENABLED + ":true}") boolean githubInfoEnabled, |
47 | 49 | @Value("${" + GITHUB_RELEASE_INFO_TIMEOUT + ":10}") int githubApiMaxWaitTime) { |
48 | 50 | this.applicationContext = applicationContext; |
49 | 51 | this.dynamicConfigOperations = dynamicConfigOperations; |
50 | 52 | this.buildProperties = Optional.ofNullable(buildProperties).orElse(new BuildProperties(new Properties())); |
51 | 53 | this.gitProperties = Optional.ofNullable(gitProperties).orElse(new GitProperties(new Properties())); |
52 | | - githubReleaseInfo = new GithubReleaseInfo(githubApiMaxWaitTime); |
| 54 | + if (githubInfoEnabled) { |
| 55 | + this.githubReleaseInfo = new GithubReleaseInfo(githubApiMaxWaitTime); |
| 56 | + } else { |
| 57 | + this.githubReleaseInfo = null; |
| 58 | + } |
53 | 59 | } |
54 | 60 |
|
55 | 61 | public ApplicationInfoDTO getApplicationInfo() { |
56 | | - var releaseInfo = githubReleaseInfo.get(); |
| 62 | + var releaseInfo = githubReleaseInfo != null ? githubReleaseInfo.get() : null; |
57 | 63 | return new ApplicationInfoDTO() |
58 | 64 | .build(getBuildInfo(releaseInfo)) |
59 | 65 | .enabledFeatures(getEnabledFeatures()) |
60 | 66 | .latestRelease(convert(releaseInfo)); |
61 | 67 | } |
62 | 68 |
|
63 | 69 | private ApplicationInfoLatestReleaseDTO convert(GithubReleaseInfo.GithubReleaseDto releaseInfo) { |
| 70 | + if (releaseInfo == null) { |
| 71 | + return null; |
| 72 | + } |
64 | 73 | return new ApplicationInfoLatestReleaseDTO() |
65 | 74 | .htmlUrl(releaseInfo.html_url()) |
66 | 75 | .publishedAt(releaseInfo.published_at()) |
67 | 76 | .versionTag(releaseInfo.tag_name()); |
68 | 77 | } |
69 | 78 |
|
70 | 79 | private ApplicationInfoBuildDTO getBuildInfo(GithubReleaseInfo.GithubReleaseDto release) { |
71 | | - return new ApplicationInfoBuildDTO() |
72 | | - .isLatestRelease(release.tag_name() != null && release.tag_name().equals(buildProperties.getVersion())) |
| 80 | + var buildInfo = new ApplicationInfoBuildDTO() |
73 | 81 | .commitId(gitProperties.getShortCommitId()) |
74 | 82 | .version(buildProperties.getVersion()) |
75 | 83 | .buildTime(buildProperties.getTime() != null |
76 | 84 | ? DateTimeFormatter.ISO_INSTANT.format(buildProperties.getTime()) : null); |
| 85 | + if (release != null) { |
| 86 | + buildInfo = buildInfo.isLatestRelease( |
| 87 | + release.tag_name() != null && release.tag_name().equals(buildProperties.getVersion()) |
| 88 | + ); |
| 89 | + } |
| 90 | + return buildInfo; |
77 | 91 | } |
78 | 92 |
|
79 | 93 | private List<EnabledFeaturesEnum> getEnabledFeatures() { |
|
0 commit comments