33import static io .kafbat .ui .api .model .AuthType .DISABLED ;
44import static io .kafbat .ui .api .model .AuthType .OAUTH2 ;
55import static io .kafbat .ui .model .ApplicationInfoDTO .EnabledFeaturesEnum ;
6+ import static io .kafbat .ui .util .GithubReleaseInfo .GITHUB_RELEASE_INFO_ENABLED ;
67import static io .kafbat .ui .util .GithubReleaseInfo .GITHUB_RELEASE_INFO_TIMEOUT ;
78
89import com .google .common .annotations .VisibleForTesting ;
2122import java .util .List ;
2223import java .util .Optional ;
2324import java .util .Properties ;
25+ import jakarta .annotation .Nullable ;
2426import org .springframework .beans .factory .annotation .Autowired ;
2527import org .springframework .beans .factory .annotation .Value ;
2628import org .springframework .boot .info .BuildProperties ;
3436
3537@ Service
3638public 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 () {
0 commit comments