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 ;
21
22
import java .util .List ;
22
23
import java .util .Optional ;
23
24
import java .util .Properties ;
25
+ import jakarta .annotation .Nullable ;
24
26
import org .springframework .beans .factory .annotation .Autowired ;
25
27
import org .springframework .beans .factory .annotation .Value ;
26
28
import org .springframework .boot .info .BuildProperties ;
34
36
35
37
@ Service
36
38
public class ApplicationInfoService {
39
+ @ Nullable
37
40
private final GithubReleaseInfo githubReleaseInfo ;
38
41
private final ApplicationContext applicationContext ;
39
42
private final DynamicConfigOperations dynamicConfigOperations ;
@@ -44,36 +47,50 @@ public ApplicationInfoService(DynamicConfigOperations dynamicConfigOperations,
44
47
ApplicationContext applicationContext ,
45
48
@ Autowired (required = false ) BuildProperties buildProperties ,
46
49
@ Autowired (required = false ) GitProperties gitProperties ,
50
+ @ Value ("${" + GITHUB_RELEASE_INFO_ENABLED + ":true}" ) boolean githubInfoEnabled ,
47
51
@ Value ("${" + GITHUB_RELEASE_INFO_TIMEOUT + ":10}" ) int githubApiMaxWaitTime ) {
48
52
this .applicationContext = applicationContext ;
49
53
this .dynamicConfigOperations = dynamicConfigOperations ;
50
54
this .buildProperties = Optional .ofNullable (buildProperties ).orElse (new BuildProperties (new Properties ()));
51
55
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
+ }
53
61
}
54
62
55
63
public ApplicationInfoDTO getApplicationInfo () {
56
- var releaseInfo = githubReleaseInfo .get ();
64
+ var releaseInfo = githubReleaseInfo != null ? githubReleaseInfo .get () : null ;
57
65
return new ApplicationInfoDTO ()
58
66
.build (getBuildInfo (releaseInfo ))
59
67
.enabledFeatures (getEnabledFeatures ())
60
68
.latestRelease (convert (releaseInfo ));
61
69
}
62
70
71
+ @ Nullable
63
72
private ApplicationInfoLatestReleaseDTO convert (GithubReleaseInfo .GithubReleaseDto releaseInfo ) {
73
+ if (releaseInfo == null ) {
74
+ return null ;
75
+ }
64
76
return new ApplicationInfoLatestReleaseDTO ()
65
77
.htmlUrl (releaseInfo .html_url ())
66
78
.publishedAt (releaseInfo .published_at ())
67
79
.versionTag (releaseInfo .tag_name ());
68
80
}
69
81
70
82
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 ()
73
84
.commitId (gitProperties .getShortCommitId ())
74
85
.version (buildProperties .getVersion ())
75
86
.buildTime (buildProperties .getTime () != null
76
87
? 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 ;
77
94
}
78
95
79
96
private List <EnabledFeaturesEnum > getEnabledFeatures () {
0 commit comments