Skip to content

Commit f1f15de

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 f1f15de

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

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

Lines changed: 18 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;
@@ -44,36 +45,49 @@ public ApplicationInfoService(DynamicConfigOperations dynamicConfigOperations,
4445
ApplicationContext applicationContext,
4546
@Autowired(required = false) BuildProperties buildProperties,
4647
@Autowired(required = false) GitProperties gitProperties,
48+
@Value("${" + GITHUB_RELEASE_INFO_ENABLED + ":true}") boolean githubInfoEnabled,
4749
@Value("${" + GITHUB_RELEASE_INFO_TIMEOUT + ":10}") int githubApiMaxWaitTime) {
4850
this.applicationContext = applicationContext;
4951
this.dynamicConfigOperations = dynamicConfigOperations;
5052
this.buildProperties = Optional.ofNullable(buildProperties).orElse(new BuildProperties(new Properties()));
5153
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+
}
5359
}
5460

5561
public ApplicationInfoDTO getApplicationInfo() {
56-
var releaseInfo = githubReleaseInfo.get();
62+
var releaseInfo = githubReleaseInfo != null ? githubReleaseInfo.get() : null;
5763
return new ApplicationInfoDTO()
5864
.build(getBuildInfo(releaseInfo))
5965
.enabledFeatures(getEnabledFeatures())
6066
.latestRelease(convert(releaseInfo));
6167
}
6268

6369
private ApplicationInfoLatestReleaseDTO convert(GithubReleaseInfo.GithubReleaseDto releaseInfo) {
70+
if (releaseInfo == null) {
71+
return null;
72+
}
6473
return new ApplicationInfoLatestReleaseDTO()
6574
.htmlUrl(releaseInfo.html_url())
6675
.publishedAt(releaseInfo.published_at())
6776
.versionTag(releaseInfo.tag_name());
6877
}
6978

7079
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()
7381
.commitId(gitProperties.getShortCommitId())
7482
.version(buildProperties.getVersion())
7583
.buildTime(buildProperties.getTime() != null
7684
? 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;
7791
}
7892

7993
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)