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 ;
15
16
import io .kafbat .ui .model .OAuthProviderDTO ;
16
17
import io .kafbat .ui .util .DynamicConfigOperations ;
17
18
import io .kafbat .ui .util .GithubReleaseInfo ;
19
+ import jakarta .annotation .Nullable ;
18
20
import java .time .format .DateTimeFormatter ;
19
21
import java .util .ArrayList ;
20
22
import java .util .Collections ;
21
23
import java .util .List ;
22
24
import java .util .Optional ;
23
25
import java .util .Properties ;
26
+ import lombok .extern .slf4j .Slf4j ;
24
27
import org .springframework .beans .factory .annotation .Autowired ;
25
28
import org .springframework .beans .factory .annotation .Value ;
26
29
import org .springframework .boot .info .BuildProperties ;
33
36
import org .springframework .stereotype .Service ;
34
37
35
38
@ Service
39
+ @ Slf4j
36
40
public class ApplicationInfoService {
41
+ @ Nullable
37
42
private final GithubReleaseInfo githubReleaseInfo ;
38
43
private final ApplicationContext applicationContext ;
39
44
private final DynamicConfigOperations dynamicConfigOperations ;
@@ -44,36 +49,52 @@ public ApplicationInfoService(DynamicConfigOperations dynamicConfigOperations,
44
49
ApplicationContext applicationContext ,
45
50
@ Autowired (required = false ) BuildProperties buildProperties ,
46
51
@ Autowired (required = false ) GitProperties gitProperties ,
52
+ @ Value ("${" + GITHUB_RELEASE_INFO_ENABLED + ":true}" ) boolean githubInfoEnabled ,
47
53
@ Value ("${" + GITHUB_RELEASE_INFO_TIMEOUT + ":10}" ) int githubApiMaxWaitTime ) {
48
54
this .applicationContext = applicationContext ;
49
55
this .dynamicConfigOperations = dynamicConfigOperations ;
50
56
this .buildProperties = Optional .ofNullable (buildProperties ).orElse (new BuildProperties (new Properties ()));
51
57
this .gitProperties = Optional .ofNullable (gitProperties ).orElse (new GitProperties (new Properties ()));
52
- githubReleaseInfo = new GithubReleaseInfo (githubApiMaxWaitTime );
58
+ if (githubInfoEnabled ) {
59
+ this .githubReleaseInfo = new GithubReleaseInfo (githubApiMaxWaitTime );
60
+ } else {
61
+ this .githubReleaseInfo = null ;
62
+ log .warn ("Check for latest release is disabled."
63
+ + " Note that old versions are not supported, please make sure that your system is up to date." );
64
+ }
53
65
}
54
66
55
67
public ApplicationInfoDTO getApplicationInfo () {
56
- var releaseInfo = githubReleaseInfo .get ();
68
+ var releaseInfo = githubReleaseInfo != null ? githubReleaseInfo .get () : null ;
57
69
return new ApplicationInfoDTO ()
58
70
.build (getBuildInfo (releaseInfo ))
59
71
.enabledFeatures (getEnabledFeatures ())
60
72
.latestRelease (convert (releaseInfo ));
61
73
}
62
74
75
+ @ Nullable
63
76
private ApplicationInfoLatestReleaseDTO convert (GithubReleaseInfo .GithubReleaseDto releaseInfo ) {
77
+ if (releaseInfo == null ) {
78
+ return null ;
79
+ }
64
80
return new ApplicationInfoLatestReleaseDTO ()
65
81
.htmlUrl (releaseInfo .html_url ())
66
82
.publishedAt (releaseInfo .published_at ())
67
83
.versionTag (releaseInfo .tag_name ());
68
84
}
69
85
70
86
private ApplicationInfoBuildDTO getBuildInfo (GithubReleaseInfo .GithubReleaseDto release ) {
71
- return new ApplicationInfoBuildDTO ()
72
- .isLatestRelease (release .tag_name () != null && release .tag_name ().equals (buildProperties .getVersion ()))
87
+ var buildInfo = new ApplicationInfoBuildDTO ()
73
88
.commitId (gitProperties .getShortCommitId ())
74
89
.version (buildProperties .getVersion ())
75
90
.buildTime (buildProperties .getTime () != null
76
91
? DateTimeFormatter .ISO_INSTANT .format (buildProperties .getTime ()) : null );
92
+ if (release != null ) {
93
+ buildInfo = buildInfo .isLatestRelease (
94
+ release .tag_name () != null && release .tag_name ().equals (buildProperties .getVersion ())
95
+ );
96
+ }
97
+ return buildInfo ;
77
98
}
78
99
79
100
private List <EnabledFeaturesEnum > getEnabledFeatures () {
@@ -119,10 +140,13 @@ private List<OAuthProviderDTO> getOAuthProviders() {
119
140
// updating on startup and every hour
120
141
@ Scheduled (fixedRateString = "${github-release-info-update-rate:3600000}" )
121
142
public void updateGithubReleaseInfo () {
122
- githubReleaseInfo .refresh ().subscribe ();
143
+ if (githubReleaseInfo != null ) {
144
+ githubReleaseInfo .refresh ().subscribe ();
145
+ }
123
146
}
124
147
125
148
@ VisibleForTesting
149
+ @ Nullable
126
150
GithubReleaseInfo githubReleaseInfo () {
127
151
return githubReleaseInfo ;
128
152
}
0 commit comments