From 712eca535d6c6495b829c5736a55f703644d8eb4 Mon Sep 17 00:00:00 2001 From: jeeppler Date: Mon, 28 Aug 2023 16:56:36 +0200 Subject: [PATCH] Replace status page API calls with SecHub Java API calls #2513 and implement #469 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - return JSON instead of text for the server version #469 - adjust the REST Doc tests für #469 - replace the status page API calls with SecHub Java API calls #2513 - improve return value of server status API call #2513 closes: #2513 closes: #469 --- gradle/projects.gradle | 11 +- .../mercedesbenz/sechub/api/SecHubClient.java | 48 +++++++- .../mercedesbenz/sechub/api/SecHubStatus.java | 17 +-- .../src/main/resources/reduced-openapi3.json | 114 +++++++++--------- ...ministrationRestControllerRestDocTest.java | 31 +++-- .../GetServerInfoScenario1IntTest.java | 19 +-- .../sechub/server/core/InfoService.java | 4 +- ...erverInfoAdministrationRestController.java | 5 +- .../sechub/server/core/ServerVersion.java | 4 + sechub-webui/build.gradle | 1 + .../sechub/webui/StatusController.java | 11 +- .../sechub/webui/StatusService.java | 57 +++++++-- .../src/main/resources/templates/status.html | 6 +- settings.gradle | 9 +- 14 files changed, 217 insertions(+), 120 deletions(-) create mode 100644 sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/ServerVersion.java diff --git a/gradle/projects.gradle b/gradle/projects.gradle index 24d112c8d7..9bc9496148 100644 --- a/gradle/projects.gradle +++ b/gradle/projects.gradle @@ -86,16 +86,10 @@ projectType = [ ], - /* SecHub frontend projects */ - springBootWebUiProjects:[ - project(':sechub-webui'), - ], - bootableSpringApplicationProjects:[ project(':sechub-server'), project(':sechub-pds'), project(':sechub-wrapper-checkmarx'), - project(':sechub-webui'), ], /* documentation projects */ @@ -128,7 +122,7 @@ projectType = [ } if (secHubBuildStage.providesGeneratedOpenApiFile()){ - /* add the java projects which need a open api file / compiled java api */ + /* add the java projects which need an open api file / compiled java api */ projectType.javaProjects.add(project(':sechub-api-java')) projectType.javaProjects.add(project(':sechub-systemtest')) @@ -141,6 +135,8 @@ if (secHubBuildStage.providesGeneratedOpenApiFile()){ /* make it possible to use integration test parts for systemtest (unit tests) as well */ projectType.integrationTestProjects.add(project(':sechub-systemtest')) + + //projectType.bootableSpringApplicationProjects.add(project(':sechub-webui')) } @@ -149,7 +145,6 @@ projectType.springBootProjects.addAll(projectType.springBootSecHubServerProjects projectType.springBootProjects.addAll(projectType.springBootPDSProjects) projectType.springBootProjects.addAll(projectType.springBootAdapterProjects) projectType.springBootProjects.addAll(projectType.springDocProjects) -projectType.springBootProjects.addAll(projectType.springBootWebUiProjects) projectType.javaProjects.addAll(projectType.springBootProjects) diff --git a/sechub-api-java/src/main/java/com/mercedesbenz/sechub/api/SecHubClient.java b/sechub-api-java/src/main/java/com/mercedesbenz/sechub/api/SecHubClient.java index 63436eb80b..7badabe47a 100644 --- a/sechub-api-java/src/main/java/com/mercedesbenz/sechub/api/SecHubClient.java +++ b/sechub-api-java/src/main/java/com/mercedesbenz/sechub/api/SecHubClient.java @@ -10,6 +10,9 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.TreeMap; import java.util.UUID; import java.util.concurrent.Callable; @@ -19,6 +22,8 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.json.JsonMapper; +import com.mercedesbenz.sechub.api.SecHubStatus.Jobs; +import com.mercedesbenz.sechub.api.SecHubStatus.Scheduler; import com.mercedesbenz.sechub.api.internal.ApiClientBuilder; import com.mercedesbenz.sechub.api.internal.OpenApiSecHubClientConversionHelper; import com.mercedesbenz.sechub.api.internal.WorkaroundAdminApi; @@ -275,16 +280,26 @@ public List fetchAllExecutorConfigurationInfo() throw /* + ................Status........................... + */ /* ++++++++++++++++++++++++++++++++++++++++++++++++++++ */ public SecHubStatus fetchSecHubStatus() throws SecHubClientException { - SecHubStatus status = new SecHubStatus(); + SecHubStatus status = null; + + Map statusInformation = new TreeMap<>(); + runOrFail(() -> { List statusInformationList = adminApi.adminListsStatusInformation(); + for (OpenApiStatusInformationInner info : statusInformationList) { String key = info.getKey(); if (key != null) { - status.statusInformation.put(key, info.getValue()); + statusInformation.put(key, info.getValue()); } } + }, "Was not able to fetch SecHub status!"); + + if (!statusInformation.isEmpty()) { + status = convertStatusMapToStatus(statusInformation); + } + return status; } @@ -468,6 +483,19 @@ public void approveJob(String projectId, UUID jobUUID) throws SecHubClientExcept runOrFail(() -> projectApi.userApprovesJob(projectId, jobUUID.toString()), "Job approve"); } + /* +++++++++++++++++++++++++++++++++++++++++++++++++ */ + /* + ................Version...................... + */ + /* +++++++++++++++++++++++++++++++++++++++++++++++++ */ + + public Optional getServerVersion() throws SecHubClientException { + runOrFail(() -> { + Optional serverVersion = Optional.of(adminApi.adminChecksServerVersion().getServerVersion()); + return serverVersion; + }, "Get server version"); + + return Optional.empty(); + } + /* ++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* + ................Helpers......................... + */ /* ++++++++++++++++++++++++++++++++++++++++++++++++++++ */ @@ -509,4 +537,20 @@ private interface SecHubClientListenerCaller { public void inform(SecHubClientListener listener); } + + private SecHubStatus convertStatusMapToStatus(Map statusMap) { + var schedulerEnabled = Boolean.valueOf(statusMap.get("status.scheduler.enabled")).booleanValue(); + var jobsAll = Long.valueOf(statusMap.get("status.scheduler.jobs.all")); + var jobsCancelRequested = Long.valueOf(statusMap.get("status.scheduler.jobs.cancel_requested")); + var jobsCanceled = Long.valueOf(statusMap.get("status.scheduler.jobs.canceled")); + var jobsEnded = Long.valueOf(statusMap.get("status.scheduler.jobs.ended")); + var jobsInitializing = Long.valueOf(statusMap.get("status.scheduler.jobs.initializing")); + var jobsReadyToStart = Long.valueOf(statusMap.get("status.scheduler.jobs.ready_to_start")); + var jobsStarted = Long.valueOf(statusMap.get("status.scheduler.jobs.started")); + + SecHubStatus.Scheduler scheduler = new Scheduler(schedulerEnabled); + SecHubStatus.Jobs jobs = new Jobs(jobsAll, jobsCancelRequested, jobsCanceled, jobsEnded, jobsInitializing, jobsReadyToStart, jobsStarted); + + return new SecHubStatus(scheduler, jobs); + } } diff --git a/sechub-api-java/src/main/java/com/mercedesbenz/sechub/api/SecHubStatus.java b/sechub-api-java/src/main/java/com/mercedesbenz/sechub/api/SecHubStatus.java index 99e9c165b5..5e1bc2cbce 100644 --- a/sechub-api-java/src/main/java/com/mercedesbenz/sechub/api/SecHubStatus.java +++ b/sechub-api-java/src/main/java/com/mercedesbenz/sechub/api/SecHubStatus.java @@ -1,21 +1,10 @@ -// SPDX-License-Identifier: MIT package com.mercedesbenz.sechub.api; -import java.util.Collections; -import java.util.Map; -import java.util.TreeMap; +public record SecHubStatus(Scheduler scheduler, Jobs jobs) { -public class SecHubStatus { - - Map statusInformation = new TreeMap<>(); - - public Map getStatusInformationMap() { - return Collections.unmodifiableMap(statusInformation); + public record Scheduler(boolean isEnabled) { } - @Override - public String toString() { - return "SecHubStatus [" + (statusInformation != null ? "statusInformation=" + statusInformation : "") + "]"; + public record Jobs(long all, long cancelRequested, long canceled, long ended, long initializating, long readyToStart, long started) { } - } diff --git a/sechub-api-java/src/main/resources/reduced-openapi3.json b/sechub-api-java/src/main/resources/reduced-openapi3.json index 9c6c59e04f..f5b68dd736 100644 --- a/sechub-api-java/src/main/resources/reduced-openapi3.json +++ b/sechub-api-java/src/main/resources/reduced-openapi3.json @@ -354,7 +354,7 @@ "200": { "description": "200", "content": { - "text/plain;charset=UTF-8": { + "application/json": { "schema": { "$ref": "#/components/schemas/ServerVersion" } @@ -2771,6 +2771,16 @@ "type": "string" } }, + "ServerVersion": { + "title": "ServerVersion", + "type": "object", + "properties": { + "serverVersion": { + "type": "string", + "description": "The sechub server version." + } + } + }, "UserSignup": { "title": "UserSignup", "type": "object", @@ -3185,6 +3195,55 @@ } } }, + "ExecutionProfileFetch": { + "title": "ExecutionProfileFetch", + "type": "object", + "properties": { + "configurations": { + "type": "array", + "items": { + "type": "object", + "properties": { + "productIdentifier": { + "type": "string", + "description": "executed product" + }, + "name": { + "type": "string", + "description": "name of configuration" + }, + "executorVersion": { + "type": "number", + "description": "executor version" + }, + "uuid": { + "type": "string", + "description": "uuid of configuration" + }, + "enabled": { + "type": "boolean", + "description": "enabled state of this config" + } + } + } + }, + "description": { + "type": "string", + "description": "A short description for the profile" + }, + "projectIds": { + "type": "array", + "description": "Projects can be linked by their ids here", + "items": { + "type": "string" + } + }, + "enabled": { + "type": "boolean", + "description": "Enabled state of profile, default is false" + } + } + }, "FalsePositives": { "title": "FalsePositives", "type": "object", @@ -3298,55 +3357,6 @@ } } }, - "ExecutionProfileFetch": { - "title": "ExecutionProfileFetch", - "type": "object", - "properties": { - "configurations": { - "type": "array", - "items": { - "type": "object", - "properties": { - "productIdentifier": { - "type": "string", - "description": "executed product" - }, - "name": { - "type": "string", - "description": "name of configuration" - }, - "executorVersion": { - "type": "number", - "description": "executor version" - }, - "uuid": { - "type": "string", - "description": "uuid of configuration" - }, - "enabled": { - "type": "boolean", - "description": "enabled state of this config" - } - } - } - }, - "description": { - "type": "string", - "description": "A short description for the profile" - }, - "projectIds": { - "type": "array", - "description": "Projects can be linked by their ids here", - "items": { - "type": "string" - } - }, - "enabled": { - "type": "boolean", - "description": "Enabled state of profile, default is false" - } - } - }, "FullScanDataZIP": { "title": "FullScanDataZIP", "type": "object" @@ -3383,10 +3393,6 @@ } } }, - "ServerVersion": { - "title": "ServerVersion", - "type": "object" - }, "JobId": { "title": "JobId", "type": "object", diff --git a/sechub-doc/src/test/java/com/mercedesbenz/sechub/restdoc/ServerInfoAdministrationRestControllerRestDocTest.java b/sechub-doc/src/test/java/com/mercedesbenz/sechub/restdoc/ServerInfoAdministrationRestControllerRestDocTest.java index 1c4ef6bd81..4d22673c76 100644 --- a/sechub-doc/src/test/java/com/mercedesbenz/sechub/restdoc/ServerInfoAdministrationRestControllerRestDocTest.java +++ b/sechub-doc/src/test/java/com/mercedesbenz/sechub/restdoc/ServerInfoAdministrationRestControllerRestDocTest.java @@ -1,12 +1,14 @@ // SPDX-License-Identifier: MIT package com.mercedesbenz.sechub.restdoc; -import static com.mercedesbenz.sechub.restdoc.RestDocumentation.*; -import static com.mercedesbenz.sechub.test.SecHubTestURLBuilder.*; -import static org.mockito.Mockito.*; -import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static com.mercedesbenz.sechub.restdoc.RestDocumentation.defineRestService; +import static com.mercedesbenz.sechub.test.SecHubTestURLBuilder.https; +import static org.mockito.Mockito.when; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import java.lang.annotation.Annotation; @@ -28,6 +30,7 @@ import com.mercedesbenz.sechub.docgen.util.RestDocFactory; import com.mercedesbenz.sechub.server.core.InfoService; import com.mercedesbenz.sechub.server.core.ServerInfoAdministrationRestController; +import com.mercedesbenz.sechub.server.core.ServerVersion; import com.mercedesbenz.sechub.sharedkernel.Profiles; import com.mercedesbenz.sechub.sharedkernel.RoleConstants; import com.mercedesbenz.sechub.sharedkernel.configuration.AbstractAllowSecHubAPISecurityConfiguration; @@ -48,7 +51,8 @@ public class ServerInfoAdministrationRestControllerRestDocTest implements TestIs private static final int PORT_USED = TestPortProvider.DEFAULT_INSTANCE.getRestDocTestPort(); - private static final String SERVER_VERSION = "0.12.3"; + private static final String SECHUB_SERVER_VERSION = "0.12.3"; + private static final String SERVER_VERSION = "serverVersion"; @Autowired private MockMvc mockMvc; @@ -63,16 +67,18 @@ public void restdoc_admin_get_server_version() throws Exception { String apiEndpoint = https(PORT_USED).buildGetServerVersionUrl(); Class useCase = UseCaseAdminChecksServerVersion.class; - when(serverInfoService.getVersionAsString()).thenReturn(SERVER_VERSION); + when(serverInfoService.getVersionAsString()).thenReturn(new ServerVersion(SECHUB_SERVER_VERSION)); + + String expectedContent = "{\"" + SERVER_VERSION + "\":\"" + SECHUB_SERVER_VERSION + "\"}"; /* execute + test @formatter:off */ this.mockMvc.perform( get(apiEndpoint). - contentType(MediaType.TEXT_PLAIN_VALUE). + contentType(MediaType.APPLICATION_JSON). header(AuthenticationHelper.HEADER_NAME, AuthenticationHelper.getHeaderValue()) ). andExpect(status().isOk()). - andExpect(content().string(SERVER_VERSION)). + andExpect(content().string(expectedContent)). andDo(defineRestService(). with(). useCaseData(useCase). @@ -80,9 +86,10 @@ public void restdoc_admin_get_server_version() throws Exception { responseSchema(OpenApiSchema.SERVER_VERSION.getSchema()). and(). document( - requestHeaders( + responseFields( + fieldWithPath(SERVER_VERSION).description("The sechub server version.") + ) - ) ) ); /* @formatter:on */ diff --git a/sechub-integrationtest/src/test/java/com/mercedesbenz/sechub/integrationtest/scenario1/GetServerInfoScenario1IntTest.java b/sechub-integrationtest/src/test/java/com/mercedesbenz/sechub/integrationtest/scenario1/GetServerInfoScenario1IntTest.java index 472aa573cd..1a44db9bc3 100644 --- a/sechub-integrationtest/src/test/java/com/mercedesbenz/sechub/integrationtest/scenario1/GetServerInfoScenario1IntTest.java +++ b/sechub-integrationtest/src/test/java/com/mercedesbenz/sechub/integrationtest/scenario1/GetServerInfoScenario1IntTest.java @@ -10,6 +10,7 @@ import org.junit.Test; import org.springframework.http.HttpStatus; +import com.mercedesbenz.sechub.commons.model.JSONConverter; import com.mercedesbenz.sechub.integrationtest.api.IntegrationTestSetup; public class GetServerInfoScenario1IntTest { @@ -33,18 +34,22 @@ public void get_server_version_anonymous_not_possible_results_in_unauthorized() @Test public void get_server_version_as_admin_is_possible() { + record ServerVersion(String serverVersion) { + } + ; + /* execute */ - String version = as(SUPER_ADMIN).getServerVersion(); + String json = as(SUPER_ADMIN).getServerVersion(); + + ServerVersion serverVersion = JSONConverter.get().fromJSON(ServerVersion.class, json); /* test */ - assertNotNull(version); - assertFalse(version.isEmpty()); /* version must be X.Y.Z and not something ala vX.Y.Z or X.Y.Z-server" */ - assertFalse(version.startsWith("v")); - assertFalse(version.endsWith("-server")); + assertFalse(serverVersion.serverVersion.startsWith("v")); + assertFalse(serverVersion.serverVersion.endsWith("-server")); /* check format is like regexp */ - assertTrue("Given version is not accepted:" + version + "\nExpected format like:" + VERSIONPATTERN_MAJOR_MINOR_HOTFIX, - PATTERN_ONLY_MAJOR_MINOR_HOTFIX.matcher(version).matches()); + assertTrue("Given version is not accepted:" + serverVersion.serverVersion + "\nExpected format like:" + VERSIONPATTERN_MAJOR_MINOR_HOTFIX, + PATTERN_ONLY_MAJOR_MINOR_HOTFIX.matcher(serverVersion.serverVersion).matches()); } } diff --git a/sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/InfoService.java b/sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/InfoService.java index 9959506add..059cff6b8e 100644 --- a/sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/InfoService.java +++ b/sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/InfoService.java @@ -19,7 +19,7 @@ public class InfoService { * @return version as string, always like "major.minor.hotfix{additional chars}" * - e.g. "1.0.0" or "0.6.0-alpha" */ - public String getVersionAsString() { + public ServerVersion getVersionAsString() { if (buildProperties == null) { /* * means we got no injection by ProjectInfoAutoConfiguration - means we are not @@ -27,7 +27,7 @@ public String getVersionAsString() { */ buildProperties = buildFallbackProperties(); } - return buildProperties.getVersion(); + return new ServerVersion(buildProperties.getVersion()); } public BuildProperties buildFallbackProperties() { diff --git a/sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/ServerInfoAdministrationRestController.java b/sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/ServerInfoAdministrationRestController.java index ff814118f0..2e7282a59d 100644 --- a/sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/ServerInfoAdministrationRestController.java +++ b/sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/ServerInfoAdministrationRestController.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; +import com.mercedesbenz.sechub.commons.model.JSONConverter; import com.mercedesbenz.sechub.sharedkernel.APIConstants; import com.mercedesbenz.sechub.sharedkernel.Profiles; import com.mercedesbenz.sechub.sharedkernel.RoleConstants; @@ -34,10 +35,10 @@ public class ServerInfoAdministrationRestController { name="REST API Call", description="Administrator wants to get the server version of SecHub", needsRestDoc=true)) - @RequestMapping(path = APIConstants.API_ADMINISTRATION+ "info/version", method = RequestMethod.GET, produces = { MediaType.TEXT_PLAIN_VALUE }) + @RequestMapping(path = APIConstants.API_ADMINISTRATION+ "info/version", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody public String getServerVersion() { /* @formatter:on */ - return serverInfoService.getVersionAsString(); + return JSONConverter.get().toJSON(serverInfoService.getVersionAsString()); } } diff --git a/sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/ServerVersion.java b/sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/ServerVersion.java new file mode 100644 index 0000000000..fb3ead73e4 --- /dev/null +++ b/sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/ServerVersion.java @@ -0,0 +1,4 @@ +package com.mercedesbenz.sechub.server.core; + +public record ServerVersion(String serverVersion) { +} diff --git a/sechub-webui/build.gradle b/sechub-webui/build.gradle index 9b8c75af1e..37c88d5dc4 100644 --- a/sechub-webui/build.gradle +++ b/sechub-webui/build.gradle @@ -12,6 +12,7 @@ plugins { dependencies { implementation project(':sechub-commons-core') + implementation project(':sechub-api-java') implementation library.springboot_starter_security implementation library.springboot_starter_thymeleaf implementation library.logstashLogbackEncoder diff --git a/sechub-webui/src/main/java/com/mercedesbenz/sechub/webui/StatusController.java b/sechub-webui/src/main/java/com/mercedesbenz/sechub/webui/StatusController.java index d0605a1f2e..68f3298e17 100644 --- a/sechub-webui/src/main/java/com/mercedesbenz/sechub/webui/StatusController.java +++ b/sechub-webui/src/main/java/com/mercedesbenz/sechub/webui/StatusController.java @@ -6,7 +6,8 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; -import reactor.core.publisher.Mono; +import com.mercedesbenz.sechub.api.SecHubClientException; +import com.mercedesbenz.sechub.api.SecHubStatus; @Controller public class StatusController { @@ -18,10 +19,14 @@ public class StatusController { @GetMapping("/status") String status(Model model) { - Mono secHubServerVersion = statusService.getServerVersion(); + SecHubStatus secHubServerStatus = null; + + secHubServerStatus = statusService.getSecHubServerStatusInformation(); + //model.addAttribute("secHubServerStatus", secHubServerStatus); + model.addAttribute("secHubServerAlive", statusService.isSecHubServerAlive()); model.addAttribute("sechubServerUrl", accessService.getSecHubServerUrl()); - model.addAttribute("sechubServerVersion", secHubServerVersion); + model.addAttribute("sechubServerVersion", statusService.getServerVersion()); return "status"; } } \ No newline at end of file diff --git a/sechub-webui/src/main/java/com/mercedesbenz/sechub/webui/StatusService.java b/sechub-webui/src/main/java/com/mercedesbenz/sechub/webui/StatusService.java index f174011f67..b9f25efe4a 100644 --- a/sechub-webui/src/main/java/com/mercedesbenz/sechub/webui/StatusService.java +++ b/sechub-webui/src/main/java/com/mercedesbenz/sechub/webui/StatusService.java @@ -1,29 +1,64 @@ // SPDX-License-Identifier: MIT package com.mercedesbenz.sechub.webui; +import java.net.URI; +import java.util.Optional; + import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; -import org.springframework.web.reactive.function.client.WebClient; -import reactor.core.publisher.Mono; +import com.mercedesbenz.sechub.api.SecHubClient; +import com.mercedesbenz.sechub.api.SecHubClientException; +import com.mercedesbenz.sechub.api.SecHubStatus; @Service -public class StatusService { +public class StatusService { @Autowired - WebClient webClient; + SecHubServerAccessService accessService; @Autowired CredentialService credentialService; + + private SecHubClient client = null; + + StatusService() { + client = new SecHubClient(URI.create("https://localhost:8443"), "int-test_superadmin", "int-test_superadmin-pwd", true); + } // TODO: Use the generated SecHub API client // TODO: Figure out what credentials are used to communicate to SecHub and how // they get injected - public Mono getServerVersion() { - return webClient.get().uri("/api/admin/info/version") - .headers(httpHeaders -> httpHeaders.setBasicAuth(credentialService.getUserId(), credentialService.getApiToken())).retrieve() - .onStatus(HttpStatus::is4xxClientError, error -> Mono.error(new RuntimeException("API not found"))) - .onStatus(HttpStatus::is5xxServerError, error -> Mono.error(new RuntimeException("Server is not responding"))).bodyToMono(String.class); - + public SecHubStatus getSecHubServerStatusInformation() { + + SecHubStatus status = null; + try { + status = client.fetchSecHubStatus(); + } catch (SecHubClientException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return status; + } + + public boolean isSecHubServerAlive() { + try { + return client.isServerAlive(); + } catch (SecHubClientException e) { + // TODO Auto-generated catch block + return false; + } + } + + public Optional getServerVersion() { + SecHubClient client = new SecHubClient(URI.create(accessService.getSecHubServerUrl()), "int-test_superadmin", "int-test_superadmin-pwd", true); + + try { + return client.getServerVersion(); + } catch (SecHubClientException e) { + // TODO Auto-generated catch block + return Optional.empty(); + } + } } diff --git a/sechub-webui/src/main/resources/templates/status.html b/sechub-webui/src/main/resources/templates/status.html index 6ab7d4b89c..03a7bddd9e 100644 --- a/sechub-webui/src/main/resources/templates/status.html +++ b/sechub-webui/src/main/resources/templates/status.html @@ -10,8 +10,12 @@

Status

+ + + - + + diff --git a/settings.gradle b/settings.gradle index 9df502e5da..473f9d0efc 100644 --- a/settings.gradle +++ b/settings.gradle @@ -75,10 +75,9 @@ include 'sechub-cli', 'sechub-wrapper-owasp-zap', // Wrapper checkmarx -'sechub-wrapper-checkmarx', +'sechub-wrapper-checkmarx' + -// WebUI -'sechub-webui' String buildStage = System.getProperty("sechub.build.stage"); @@ -87,7 +86,7 @@ if (buildStage!=null) { /* build stage properrty is set */ if (buildStage.equals("api-necessary") || buildStage.equals("all") ){ - include 'sechub-api-java', /* needs open api file to generate */ + include 'sechub-api-java', /* needs open api file to generate */ /* system test - needs java api*/ 'sechub-systemtest', @@ -98,6 +97,8 @@ if (buildStage!=null) { // Examples (are below 'sechub-examples' folder) 'sechub-examples:example-sechub-api-java' + /* WebUI - needs the Java API */ + 'sechub-webui' } }
Aliveunavailable
SchedulerenabledScheduler5
Jobs running5