Skip to content

Commit 3c4131c

Browse files
committed
Allow disabling GitHub release info
The application info object contains details about the latest version which is queried online from GitHub API. While this info can be useful, it raises warning when Kafbat UI is deployed in environments with restricted internet access. Introduce a new property "github.release.info.enabled" (default: true) that can be set to "false" to disable release info and just display the currently running version/commit.
1 parent cb9a105 commit 3c4131c

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

api/src/main/java/io/kafbat/ui/service/ApplicationInfoService.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static io.kafbat.ui.api.model.AuthType.DISABLED;
44
import static io.kafbat.ui.api.model.AuthType.OAUTH2;
55
import static io.kafbat.ui.model.ApplicationInfoDTO.EnabledFeaturesEnum;
6+
import static io.kafbat.ui.util.GithubReleaseInfo.GITHUB_RELEASE_INFO_ENABLED;
67
import static io.kafbat.ui.util.GithubReleaseInfo.GITHUB_RELEASE_INFO_TIMEOUT;
78

89
import com.google.common.annotations.VisibleForTesting;
@@ -21,6 +22,7 @@
2122
import java.util.List;
2223
import java.util.Optional;
2324
import java.util.Properties;
25+
import jakarta.annotation.Nullable;
2426
import org.springframework.beans.factory.annotation.Autowired;
2527
import org.springframework.beans.factory.annotation.Value;
2628
import org.springframework.boot.info.BuildProperties;
@@ -34,6 +36,7 @@
3436

3537
@Service
3638
public class ApplicationInfoService {
39+
@Nullable
3740
private final GithubReleaseInfo githubReleaseInfo;
3841
private final ApplicationContext applicationContext;
3942
private final DynamicConfigOperations dynamicConfigOperations;
@@ -44,36 +47,50 @@ public ApplicationInfoService(DynamicConfigOperations dynamicConfigOperations,
4447
ApplicationContext applicationContext,
4548
@Autowired(required = false) BuildProperties buildProperties,
4649
@Autowired(required = false) GitProperties gitProperties,
50+
@Value("${" + GITHUB_RELEASE_INFO_ENABLED + ":true}") boolean githubInfoEnabled,
4751
@Value("${" + GITHUB_RELEASE_INFO_TIMEOUT + ":10}") int githubApiMaxWaitTime) {
4852
this.applicationContext = applicationContext;
4953
this.dynamicConfigOperations = dynamicConfigOperations;
5054
this.buildProperties = Optional.ofNullable(buildProperties).orElse(new BuildProperties(new Properties()));
5155
this.gitProperties = Optional.ofNullable(gitProperties).orElse(new GitProperties(new Properties()));
52-
githubReleaseInfo = new GithubReleaseInfo(githubApiMaxWaitTime);
56+
if (githubInfoEnabled) {
57+
this.githubReleaseInfo = new GithubReleaseInfo(githubApiMaxWaitTime);
58+
} else {
59+
this.githubReleaseInfo = null;
60+
}
5361
}
5462

5563
public ApplicationInfoDTO getApplicationInfo() {
56-
var releaseInfo = githubReleaseInfo.get();
64+
var releaseInfo = githubReleaseInfo != null ? githubReleaseInfo.get() : null;
5765
return new ApplicationInfoDTO()
5866
.build(getBuildInfo(releaseInfo))
5967
.enabledFeatures(getEnabledFeatures())
6068
.latestRelease(convert(releaseInfo));
6169
}
6270

71+
@Nullable
6372
private ApplicationInfoLatestReleaseDTO convert(GithubReleaseInfo.GithubReleaseDto releaseInfo) {
73+
if (releaseInfo == null) {
74+
return null;
75+
}
6476
return new ApplicationInfoLatestReleaseDTO()
6577
.htmlUrl(releaseInfo.html_url())
6678
.publishedAt(releaseInfo.published_at())
6779
.versionTag(releaseInfo.tag_name());
6880
}
6981

7082
private ApplicationInfoBuildDTO getBuildInfo(GithubReleaseInfo.GithubReleaseDto release) {
71-
return new ApplicationInfoBuildDTO()
72-
.isLatestRelease(release.tag_name() != null && release.tag_name().equals(buildProperties.getVersion()))
83+
var buildInfo = new ApplicationInfoBuildDTO()
7384
.commitId(gitProperties.getShortCommitId())
7485
.version(buildProperties.getVersion())
7586
.buildTime(buildProperties.getTime() != null
7687
? DateTimeFormatter.ISO_INSTANT.format(buildProperties.getTime()) : null);
88+
if (release != null) {
89+
buildInfo = buildInfo.isLatestRelease(
90+
release.tag_name() != null && release.tag_name().equals(buildProperties.getVersion())
91+
);
92+
}
93+
return buildInfo;
7794
}
7895

7996
private List<EnabledFeaturesEnum> getEnabledFeatures() {

api/src/main/java/io/kafbat/ui/util/GithubReleaseInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
@Slf4j
1010
public class GithubReleaseInfo {
11+
public static final String GITHUB_RELEASE_INFO_ENABLED = "github.release.info.enabled";
1112
public static final String GITHUB_RELEASE_INFO_TIMEOUT = "github.release.info.timeout";
1213

1314
private static final String GITHUB_LATEST_RELEASE_RETRIEVAL_URL =
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,43 @@
11
package io.kafbat.ui.service;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertNotNull;
5+
import static org.junit.jupiter.api.Assertions.assertNull;
46

57
import io.kafbat.ui.AbstractIntegrationTest;
8+
import io.kafbat.ui.util.DynamicConfigOperations;
69
import org.junit.jupiter.api.Test;
710
import org.springframework.beans.factory.annotation.Autowired;
811

912
class ApplicationInfoServiceTest extends AbstractIntegrationTest {
1013
@Autowired
1114
private ApplicationInfoService service;
1215

16+
@Autowired
17+
private DynamicConfigOperations dynamicConfigOperations;
18+
1319
@Test
1420
void testCustomGithubReleaseInfoTimeout() {
1521
assertEquals(100, service.githubReleaseInfo().getGithubApiMaxWaitTime());
1622
}
23+
24+
@Test
25+
void testDisabledReleaseInfo() {
26+
var service2 = new ApplicationInfoService(
27+
dynamicConfigOperations,
28+
null,
29+
null,
30+
null,
31+
false,
32+
101
33+
);
34+
35+
assertNull(service2.githubReleaseInfo(), "unexpected GitHub release info when disabled");
36+
var appInfo = service2.getApplicationInfo();
37+
assertNotNull(appInfo, "application info must not be NULL");
38+
assertNull(appInfo.getLatestRelease(), "latest release should be NULL when disabled");
39+
assertNotNull(appInfo.getBuild(), "build info must not be NULL");
40+
assertNotNull(appInfo.getEnabledFeatures(), "enabled features must not be NULL");
41+
}
42+
1743
}

frontend/src/components/Version/Version.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const Version: React.FC = () => {
1919

2020
return (
2121
<S.Wrapper>
22-
{!isLatestRelease && (
22+
{isLatestRelease === false && (
2323
<S.OutdatedWarning
2424
title={`Your app version is outdated. Latest version is ${
2525
versionTag || 'UNKNOWN'

0 commit comments

Comments
 (0)