[CST-5288] Info endpoint improvements

This commit is contained in:
Luca Giamminonni
2022-05-09 16:22:39 +02:00
parent fe181398d0
commit 7b49fbe661
5 changed files with 119 additions and 46 deletions

View File

@@ -14,7 +14,6 @@ import java.util.Arrays;
import org.apache.solr.client.solrj.SolrServerException;
import org.dspace.app.rest.DiscoverableEndpointsService;
import org.dspace.app.rest.health.GeoIpHealthIndicator;
import org.dspace.app.rest.info.VersionInfoContributor;
import org.dspace.authority.AuthoritySolrServiceImpl;
import org.dspace.discovery.SolrSearchCore;
import org.dspace.statistics.SolrStatisticsCore;
@@ -89,11 +88,6 @@ public class ActuatorConfiguration {
return new GeoIpHealthIndicator();
}
@Bean
public VersionInfoContributor versionInfoContributor() {
return new VersionInfoContributor();
}
public String getActuatorBasePath() {
return actuatorBasePath;
}

View File

@@ -1,38 +0,0 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.info;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import org.dspace.app.util.Util;
import org.dspace.services.ConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.info.Info.Builder;
import org.springframework.boot.actuate.info.InfoContributor;
/**
* Implementation of {@link InfoContributor} that add the version info.
*
* @author Luca Giamminonni (luca.giamminonni at 4science.it)
*
*/
public class VersionInfoContributor implements InfoContributor {
@Autowired
private ConfigurationService configurationService;
@Override
public void contribute(Builder builder) {
String sourceVersion = Util.getSourceVersion();
if (isNotBlank(sourceVersion)) {
String versionAttribute = configurationService.getProperty("actuator.info.version-attribute", "version");
builder.withDetail(versionAttribute, sourceVersion);
}
}
}

View File

@@ -0,0 +1,35 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.utils;
import org.dspace.app.util.Util;
import org.dspace.services.ConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
/**
* Class that use the configuration service to add a property named
* 'dspace.version' with the current DSpace application version.
*
* @author Luca Giamminonni (luca.giamminonni at 4science.it)
*
*/
@Component
public class DSpaceVersionConfigurationEnricher implements ApplicationRunner {
@Autowired
private ConfigurationService configurationService;
@Override
public void run(ApplicationArguments args) throws Exception {
configurationService.addPropertyValue("dspace.version", Util.getSourceVersion());
}
}

View File

@@ -0,0 +1,83 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.app.util.Util;
import org.dspace.services.ConfigurationService;
import org.hamcrest.Matcher;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Integration tests for info actuator.
*
* @author Luca Giamminonni (luca.giamminonni at 4science.it)
*
*/
public class InfoEndpointIT extends AbstractControllerIntegrationTest {
private static final String INFO_PATH = "/actuator/info";
@Autowired
private ConfigurationService configurationService;
@Test
public void testWithAnonymousUser() throws Exception {
getClient().perform(get(INFO_PATH))
.andExpect(status().isUnauthorized());
}
@Test
public void testWithNotAdminUser() throws Exception {
String token = getAuthToken(eperson.getEmail(), password);
getClient(token).perform(get(INFO_PATH))
.andExpect(status().isForbidden());
}
@Test
public void testWithAdminUser() throws Exception {
String token = getAuthToken(admin.getEmail(), password);
getClient(token).perform(get(INFO_PATH))
.andExpect(status().isOk())
.andExpect(jsonPath("$.app.name", matchProperty("dspace.name")))
.andExpect(jsonPath("$.app.version", is(Util.getSourceVersion())))
.andExpect(jsonPath("$.app.dir", matchProperty("dspace.dir")))
.andExpect(jsonPath("$.app.url", matchProperty("dspace.server.url")))
.andExpect(jsonPath("$.app.db", matchProperty("db.url")))
.andExpect(jsonPath("$.app.solr.server", matchProperty("solr.server")))
.andExpect(jsonPath("$.app.solr.prefix", matchProperty("solr.multicorePrefix")))
.andExpect(jsonPath("$.app.mail.server", matchProperty("mail.server")))
.andExpect(jsonPath("$.app.mail.from-address", matchProperty("mail.from.address")))
.andExpect(jsonPath("$.app.mail.feedback-recipient", matchProperty("feedback.recipient")))
.andExpect(jsonPath("$.app.mail.mail-admin", matchProperty("mail.admin")))
.andExpect(jsonPath("$.app.mail.mail-helpdesk", matchProperty("mail.helpdesk")))
.andExpect(jsonPath("$.app.mail.alert-recipient", matchProperty("alert.recipient")))
.andExpect(jsonPath("$.app.cors.allowed-origins", matchProperty("rest.cors.allowed-origins")))
.andExpect(jsonPath("$.app.ui.url", matchProperty("dspace.ui.url")))
.andExpect(jsonPath("$.java").exists());
}
private Matcher<?> matchProperty(String name) {
return is(configurationService.getProperty(name));
}
}

View File

@@ -35,6 +35,7 @@ management.info.env.enabled = true
management.info.java.enabled = true
info.app.name = ${dspace.name}
info.app.version = ${dspace.version}
info.app.dir = ${dspace.dir}
info.app.url = ${dspace.server.url}
info.app.db = ${db.url}
@@ -50,5 +51,3 @@ info.app.mail.alert-recipient = ${alert.recipient}
info.app.cors.allowed-origins = ${rest.cors.allowed-origins}
info.app.ui.url = ${dspace.ui.url}
actuator.info.version-attribute = version