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 ;
1516import  io .kafbat .ui .model .OAuthProviderDTO ;
1617import  io .kafbat .ui .util .DynamicConfigOperations ;
1718import  io .kafbat .ui .util .GithubReleaseInfo ;
19+ import  jakarta .annotation .Nullable ;
1820import  java .time .format .DateTimeFormatter ;
1921import  java .util .ArrayList ;
2022import  java .util .Collections ;
2123import  java .util .List ;
2224import  java .util .Optional ;
2325import  java .util .Properties ;
26+ import  lombok .extern .slf4j .Slf4j ;
2427import  org .springframework .beans .factory .annotation .Autowired ;
2528import  org .springframework .beans .factory .annotation .Value ;
2629import  org .springframework .boot .info .BuildProperties ;
3336import  org .springframework .stereotype .Service ;
3437
3538@ Service 
39+ @ Slf4j 
3640public  class  ApplicationInfoService  {
41+   @ Nullable 
3742  private  final  GithubReleaseInfo  githubReleaseInfo ;
3843  private  final  ApplicationContext  applicationContext ;
3944  private  final  DynamicConfigOperations  dynamicConfigOperations ;
@@ -44,36 +49,52 @@ public ApplicationInfoService(DynamicConfigOperations dynamicConfigOperations,
4449                                ApplicationContext  applicationContext ,
4550                                @ Autowired (required  = false ) BuildProperties  buildProperties ,
4651                                @ Autowired (required  = false ) GitProperties  gitProperties ,
52+                                 @ Value ("${"  + GITHUB_RELEASE_INFO_ENABLED  + ":true}" ) boolean  githubInfoEnabled ,
4753                                @ Value ("${"  + GITHUB_RELEASE_INFO_TIMEOUT  + ":10}" ) int  githubApiMaxWaitTime ) {
4854    this .applicationContext  = applicationContext ;
4955    this .dynamicConfigOperations  = dynamicConfigOperations ;
5056    this .buildProperties  = Optional .ofNullable (buildProperties ).orElse (new  BuildProperties (new  Properties ()));
5157    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+     }
5365  }
5466
5567  public  ApplicationInfoDTO  getApplicationInfo () {
56-     var  releaseInfo  = githubReleaseInfo .get ();
68+     var  releaseInfo  = githubReleaseInfo  !=  null  ?  githubReleaseInfo .get () :  null ;
5769    return  new  ApplicationInfoDTO ()
5870        .build (getBuildInfo (releaseInfo ))
5971        .enabledFeatures (getEnabledFeatures ())
6072        .latestRelease (convert (releaseInfo ));
6173  }
6274
75+   @ Nullable 
6376  private  ApplicationInfoLatestReleaseDTO  convert (GithubReleaseInfo .GithubReleaseDto  releaseInfo ) {
77+     if  (releaseInfo  == null ) {
78+       return  null ;
79+     }
6480    return  new  ApplicationInfoLatestReleaseDTO ()
6581        .htmlUrl (releaseInfo .html_url ())
6682        .publishedAt (releaseInfo .published_at ())
6783        .versionTag (releaseInfo .tag_name ());
6884  }
6985
7086  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 ()
7388        .commitId (gitProperties .getShortCommitId ())
7489        .version (buildProperties .getVersion ())
7590        .buildTime (buildProperties .getTime () != null 
7691            ? 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 ;
7798  }
7899
79100  private  List <EnabledFeaturesEnum > getEnabledFeatures () {
@@ -119,10 +140,13 @@ private List<OAuthProviderDTO> getOAuthProviders() {
119140  // updating on startup and every hour 
120141  @ Scheduled (fixedRateString  = "${github-release-info-update-rate:3600000}" )
121142  public  void  updateGithubReleaseInfo () {
122-     githubReleaseInfo .refresh ().subscribe ();
143+     if  (githubReleaseInfo  != null ) {
144+       githubReleaseInfo .refresh ().subscribe ();
145+     }
123146  }
124147
125148  @ VisibleForTesting 
149+   @ Nullable 
126150  GithubReleaseInfo  githubReleaseInfo () {
127151    return  githubReleaseInfo ;
128152  }
0 commit comments