Skip to content

Commit

Permalink
fix(ui): display the right version
Browse files Browse the repository at this point in the history
close #861 #844
  • Loading branch information
tchiotludo committed Oct 29, 2021
1 parent ab23675 commit c61c056
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion client/src/containers/SideBar/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class Sidebar extends Component {
enableConnect
} = this.state;
const roles = this.state.roles || {};
const tag = 'Snapshot';
const tag = sessionStorage.getItem('version');
const { listConnects, listClusters } = this.setClustersAndConnects();
return (
<SideNav
Expand Down
1 change: 1 addition & 0 deletions client/src/utils/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Routes extends Root {
_setAuths(response) {
if (response.status === 200) {
sessionStorage.setItem('auths', JSON.stringify(response.data));
sessionStorage.setItem('version', response.data.version);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/akhq/controllers/AkhqController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import lombok.NoArgsConstructor;
import org.akhq.configs.*;
import org.akhq.modules.HasAnyPermission;
import org.akhq.utils.VersionProvider;

import javax.inject.Inject;
import java.util.ArrayList;
Expand Down Expand Up @@ -45,6 +46,8 @@ public class AkhqController extends AbstractController {
@Nullable
private HeaderAuth headerAuth;

@Inject
private VersionProvider versionProvider;

@HasAnyPermission()
@Get("api/cluster")
Expand Down Expand Up @@ -90,6 +93,7 @@ public AuthDefinition auths() {
authDefinition.loginEnabled = false;
}
}
authDefinition.version = versionProvider.getVersion();

return authDefinition;
}
Expand Down Expand Up @@ -176,6 +180,7 @@ public static class AuthDefinition {
private boolean loginEnabled;
private boolean formEnabled;
private List<OidcAuth> oidcAuths;
private String version;
}

@AllArgsConstructor
Expand Down
37 changes: 28 additions & 9 deletions src/main/java/org/akhq/utils/VersionProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,45 @@
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;

@Singleton
public class VersionProvider {

@Getter
private String tag = "Snapshot";
private String version = "Snapshot";

@Inject
Environment environment;

@PostConstruct
public void start() {
new PropertiesPropertySourceLoader()
.load("classpath:git", environment)
.ifPresent(properties -> setTag(properties.get("git.tags")));
this.version = Stream
.concat(
new PropertiesPropertySourceLoader()
.load("classpath:gradle", environment)
.stream()
.flatMap(properties -> Stream.of(properties.get("version"))),
new PropertiesPropertySourceLoader()
.load("classpath:git", environment)
.stream()
.flatMap(properties -> Stream
.of(
properties.get("git.tags"),
properties.get("git.branch")
)
)
)
.map(this::getVersion)
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst()
.orElse(this.version);
}

private void setTag(Object value) {
String candidate = Objects.toString(value, null);
this.tag = StringUtils.isNotEmpty(candidate) ? candidate : this.tag;
}
private Optional<String> getVersion(Object object) {
String candidate = Objects.toString(object, null);

return StringUtils.isNotEmpty(candidate) ? Optional.of(candidate) : Optional.empty();
}
}

0 comments on commit c61c056

Please sign in to comment.