Skip to content
Snippets Groups Projects
Commit 08822240 authored by Dmitrii Novikov (EPAM)'s avatar Dmitrii Novikov (EPAM) Committed by Riabokon Stanislav(EPAM)[GCP]
Browse files

Added new version info endpoint (GONRG-2681)

parent 854ab210
No related branches found
No related tags found
2 merge requests!143Master,!130Added new version info endpoint (GONRG-2681)
Showing
with 387 additions and 35 deletions
......@@ -17,7 +17,7 @@ The following software have components provided under the terms of this license:
- Apache Commons CLI (from http://commons.apache.org/proper/commons-cli/)
- Cobertura (from http://cobertura.sourceforge.net)
- Default Plexus Container (from https://repo1.maven.org/maven2/org/codehaus/plexus/plexus-container-default)
- Plexus Common Utilities (from https://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils)
- Plexus Common Utilities (from http://plexus.codehaus.org/plexus-utils)
- oro (from )
========================================================================
......@@ -511,7 +511,7 @@ The following software have components provided under the terms of this license:
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- PWDB :: Database (from https://repo1.maven.org/maven2/org/linguafranca/pwdb/database)
- Plexus Common Utilities (from https://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils)
- Plexus Common Utilities (from http://plexus.codehaus.org/plexus-utils)
- Plexus Velocity Component (from )
- PowerMock (from http://www.powermock.org)
- PowerMock (from http://www.powermock.org)
......@@ -671,7 +671,7 @@ The following software have components provided under the terms of this license:
- Hamcrest (from http://hamcrest.org/JavaHamcrest/)
- Hamcrest Core (from http://hamcrest.org/)
- HdrHistogram (from http://hdrhistogram.github.io/HdrHistogram/)
- Plexus Common Utilities (from https://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils)
- Plexus Common Utilities (from http://plexus.codehaus.org/plexus-utils)
- Reflections (from http://github.com/ronmamo/reflections)
- Stax2 API (from http://github.com/FasterXML/stax2-api)
- ThreeTen backport (from https://www.threeten.org/threetenbp)
......@@ -714,7 +714,7 @@ The following software have components provided under the terms of this license:
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java)
- Netty/Codec/HTTP (from https://repo1.maven.org/maven2/io/netty/netty-codec-http)
- Plexus Common Utilities (from https://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils)
- Plexus Common Utilities (from http://plexus.codehaus.org/plexus-utils)
- Protocol Buffers [Core] (from https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java)
- Protocol Buffers [Util] (from https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java-util)
- Protocol Buffers [Util] (from https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java-util)
......@@ -796,11 +796,11 @@ The following software have components provided under the terms of this license:
- Expression Language 3.0 (from https://projects.eclipse.org/projects/ee4j.el)
- JUnit Jupiter (Aggregator) (from https://junit.org/junit5/)
- JUnit Jupiter Params (from https://junit.org/junit5/)
- Logback Classic Module (from http://logback.qos.ch)
- Logback Classic Module (from https://repo1.maven.org/maven2/ch/qos/logback/logback-classic)
- Logback Contrib :: JSON :: Classic (from https://repo1.maven.org/maven2/ch/qos/logback/contrib/logback-json-classic)
- Logback Contrib :: JSON :: Core (from https://repo1.maven.org/maven2/ch/qos/logback/contrib/logback-json-core)
- Logback Contrib :: Jackson (from )
- Logback Core Module (from http://logback.qos.ch)
- Logback Core Module (from https://repo1.maven.org/maven2/ch/qos/logback/logback-core)
- Microsoft Application Insights Java SDK Core (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
......@@ -908,11 +908,11 @@ The following software have components provided under the terms of this license:
- Java Native Access Platform (from https://github.com/java-native-access/jna)
- Javassist (from http://www.javassist.org/)
- Javassist (from http://www.javassist.org/)
- Logback Classic Module (from http://logback.qos.ch)
- Logback Classic Module (from https://repo1.maven.org/maven2/ch/qos/logback/logback-classic)
- Logback Contrib :: JSON :: Classic (from https://repo1.maven.org/maven2/ch/qos/logback/contrib/logback-json-classic)
- Logback Contrib :: JSON :: Core (from https://repo1.maven.org/maven2/ch/qos/logback/contrib/logback-json-core)
- Logback Contrib :: Jackson (from )
- Logback Core Module (from http://logback.qos.ch)
- Logback Core Module (from https://repo1.maven.org/maven2/ch/qos/logback/logback-core)
- Microsoft Application Insights Java SDK Core (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
......@@ -1028,7 +1028,7 @@ Public-Domain
========================================================================
The following software have components provided under the terms of this license:
- Plexus Common Utilities (from https://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils)
- Plexus Common Utilities (from http://plexus.codehaus.org/plexus-utils)
- Spongy Castle (from http://rtyley.github.io/spongycastle/)
========================================================================
......
......@@ -19,6 +19,8 @@ security:
tags:
- name: LegalTag
description: ''
- name: info
description: "Version info endpoint"
schemes:
- https
consumes:
......@@ -308,6 +310,21 @@ paths:
- Bearer: []
- google_id_token: []
- sauth_id_token: []
/info:
get:
tags:
- info
summary: "Version info"
description: "For deployment available public `/info` endpoint, \
\ which provides build and git related information."
operationId: "Version info"
produces:
- "application/json"
responses:
200:
description: "Version info."
schema:
$ref: "#/definitions/VersionInfo"
securityDefinitions:
Bearer:
type: apiKey
......@@ -483,3 +500,43 @@ definitions:
example: '2025-12-25'
description: The optional expiration date of the contract in the format YYYY-MM-DD
description: The model to update an existing LegalTag
VersionInfo:
type: "object"
properties:
groupId:
type: "string"
description: "Maven artifact group ID."
actifactId:
type: "string"
description: "Maven artifact ID."
version:
type: "string"
description: "Maven artifact version"
buildTime:
type: "string"
description: "Maven artifact build time"
branch:
type: "string"
description: "Current git branch"
commitId:
type: "string"
description: "Latest commit hash"
commitMessage:
type: "string"
description: "Latest commit message"
connectedOuterServices:
type: "array"
description: "Connected outer services information"
items:
$ref: "#/definitions/ConnectedOuterService"
description: "Version info."
ConnectedOuterService:
type: "object"
properties:
name:
type: "string"
description: "Connected outer service name."
version:
type: "string"
description: "Connected outer service version."
description: "Connected outer service information."
\ No newline at end of file
......@@ -15,6 +15,7 @@
* [Compliance on consumption](#Compliance-on-consumption)
* [The LegalTag Changed notification](#The-LegalTag-Changed-notification)
* [Permissions](#Permissions)
* [Version info endpoint](#version-info-endpoint)
## Introduction<a name="Introduction"></a>
......@@ -509,3 +510,39 @@ If it has become incompliant, you must make sure associated data is no longer al
If it is marked compliant, data that was not allowed for consumption can now be consumed through your services.
[Back to table of contents](#TOC)
## Version info endpoint
For deployment available public `/info` endpoint, which provides build and git related information.
#### Example response:
```json
{
"groupId": "org.opengroup.osdu",
"artifactId": "storage-gcp",
"version": "0.10.0-SNAPSHOT",
"buildTime": "2021-07-09T14:29:51.584Z",
"branch": "feature/GONRG-2681_Build_info",
"commitId": "7777",
"commitMessage": "Added copyright to version info properties file",
"connectedOuterServices": [
{
"name": "elasticSearch",
"version":"..."
},
{
"name": "postgresSql",
"version":"..."
},
{
"name": "redis",
"version":"..."
}
]
}
```
This endpoint takes information from files, generated by `spring-boot-maven-plugin`,
`git-commit-id-plugin` plugins. Need to specify paths for generated files to matching
properties:
- `version.info.buildPropertiesPath`
- `version.info.gitPropertiesPath`
[Back to table of contents](#TOC)
\ No newline at end of file
......@@ -181,7 +181,6 @@
</dependencies>
<build>
<defaultGoal>test</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......@@ -191,6 +190,9 @@
<useSystemClassLoader>false</useSystemClassLoader>
<threadCount>1</threadCount>
</configuration>
<goals>
<goal>test</goal>
</goals>
</plugin>
</plugins>
</build>
......
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.legal.api;
import java.io.IOException;
import org.opengroup.osdu.core.common.info.VersionInfoBuilder;
import org.opengroup.osdu.core.common.model.info.VersionInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping
public class InfoApi {
@Autowired
private VersionInfoBuilder versionInfoBuilder;
@GetMapping(value = "/info", produces = MediaType.APPLICATION_JSON_VALUE)
public VersionInfo info() throws IOException {
return versionInfoBuilder.buildVersionInfo();
}
}
\ No newline at end of file
......@@ -2,9 +2,8 @@ package org.opengroup.osdu.legal.middleware;
import java.io.IOException;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
......@@ -12,19 +11,16 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.inject.Inject;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.provider.interfaces.IAuthorizationService;
import org.opengroup.osdu.core.common.http.ResponseHeadersFactory;
import org.opengroup.osdu.core.common.model.http.Request;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.springframework.context.annotation.Lazy;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.http.Request;
import org.opengroup.osdu.core.common.model.http.RequestInfo;
import org.opengroup.osdu.core.common.provider.interfaces.IAuthorizationService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.opengroup.osdu.core.common.model.http.RequestInfo;
@Component
@Lazy
public class LegalFilter implements Filter {
......@@ -68,16 +64,21 @@ public class LegalFilter implements Filter {
}finally {
logRequest(httpServletRequest, httpServletResponse, startTime);
}
}
@Override
public void destroy() {
}
private boolean validateIsHttps( HttpServletResponse httpServletResponse, HttpServletRequest httpServletRequest) {
String uri = requestInfo.getUri();
if(!isLocalHost(uri) && !isCronJob(uri) && !isSwagger(uri) && !isHealthCheck(uri) && !isOptionsMethod(httpServletRequest)) {
if (!isLocalHost(uri)
&& !isCronJob(uri)
&& !isSwagger(uri)
&& !isVersionInfo(uri)
&& !isHealthCheck(uri)
&& !isOptionsMethod(httpServletRequest)) {
if(!hasJwt()) {
httpServletResponse.setStatus(401);
return false;
......@@ -108,6 +109,11 @@ public class LegalFilter implements Filter {
private boolean isCronJob(String uri) {
return uri.contains("/jobs/updateLegalTagStatus");
}
private boolean isVersionInfo(String uri) {
return uri.contains("/info");
}
private boolean isSwagger(String uri) {
return uri.contains("/swagger") || uri.contains("/v2/api-docs") || uri.contains("/configuration/ui") || uri.contains("/webjars/");
}
......
package org.opengroup.osdu.legal.util;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.opengroup.osdu.core.common.cache.RedisCache;
import org.opengroup.osdu.core.common.info.ConnectedOuterServicesBuilder;
import org.opengroup.osdu.core.common.model.info.ConnectedOuterService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Component;
@Component
@ConditionalOnMissingBean(type = "ConnectedOuterServicesBuilder")
public class CloudConnectedOuterServicesBuilder implements ConnectedOuterServicesBuilder {
private static final String REDIS_PREFIX = "Redis-";
private List<RedisCache> redisCaches;
public CloudConnectedOuterServicesBuilder(List<RedisCache> redisCaches) {
this.redisCaches = redisCaches;
}
@Override
public List<ConnectedOuterService> buildConnectedOuterServices() {
return redisCaches.stream().map(this::fetchRedisInfo).collect(Collectors.toList());
}
private ConnectedOuterService fetchRedisInfo(RedisCache cache) {
String redisVersion = StringUtils.substringBetween(cache.info(), ":", "\r");
return ConnectedOuterService.builder()
.name(REDIS_PREFIX + StringUtils.substringAfterLast(cache.getClass().getName(), "."))
.version(redisVersion)
.build();
}
}
......@@ -8,7 +8,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<docker.image.prefix>opendes</docker.image.prefix>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<os-core-common.version>0.10.0</os-core-common.version>
<os-core-common.version>0.11.0-SNAPSHOT</os-core-common.version>
<snakeyaml.version>1.26</snakeyaml.version>
</properties>
......@@ -111,4 +111,46 @@
</profile>
</profiles>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.0.5</version>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
<dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>
${project.build.outputDirectory}/git.properties
</generateGitPropertiesFilename>
</configuration>
</plugin>
</plugins>
</build>
</project>
......@@ -39,4 +39,4 @@ server.ssl.key-alias=${SSL_KEY_ALIAS:osduonaws}
server.ssl.key-password=${SSL_KEY_PASSWORD:}
server.ssl.key-store-password=${SSL_KEY_STORE_PASSWORD:}
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration
\ No newline at end of file
......@@ -46,6 +46,7 @@ public class AADSecurityConfig extends WebSecurityConfigurerAdapter {
"/swagger-resources/**",
"/configuration/security",
"/swagger",
"/info",
"/swagger-ui.html",
"/webjars/**").permitAll()
.anyRequest().authenticated()
......
......@@ -9,6 +9,4 @@ spring.security.user.roles=service.legal.admin
REGION=us-central
AUTHORIZE_API=notused
LEGAL_HOSTNAME=notused
CRON_JOB_IP=10.0.0.1
CRON_JOB_IP=10.0.0.1
\ No newline at end of file
......@@ -41,6 +41,7 @@ public class GSuiteSecurityConfiguration extends WebSecurityConfigurerAdapter {
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/api-docs")
.antMatchers("/index")
.antMatchers("/info")
.antMatchers("/swagger");
}
......
......@@ -24,6 +24,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
"/actuator/**",
"/configuration/security",
"/swagger-ui.html",
"/info",
"/webjars/**").permitAll()
.anyRequest().authenticated().and().oauth2ResourceServer().jwt();
}
......
......@@ -40,6 +40,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/api-docs")
.antMatchers("/index")
.antMatchers("/info")
.antMatchers("/swagger");
}
}
......@@ -18,7 +18,4 @@ mongo-db-name={MONGO_DB_NAME}
mb-rabbitmq-uri=amqp://guest:guest@localhost:5672
REGION=us-central1
AUTHORIZE_API=https://entitlements-java-ckqkfalyaq-uc.a.run.app/entitlements/v1
AUTHORIZE_API=https://entitlements-java-ckqkfalyaq-uc.a.run.app/entitlements/v1
\ No newline at end of file
package org.opengroup.osdu.legal.acceptanceTests;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.legal.util.AwsLegalTagUtils;
public class TestGetInfoApiAcceptance extends GetInfoApiAcceptanceTests {
@Before
@Override
public void setup() throws Exception {
this.legalTagUtils = new AwsLegalTagUtils();
super.setup();
}
@After
@Override
public void teardown() throws Exception {
super.teardown();
this.legalTagUtils = null;
}
}
package org.opengroup.osdu.legal.acceptanceTests;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.opengroup.osdu.legal.util.AzureLegalTagUtils;
public class TestGetInfoApiAcceptance extends GetInfoApiAcceptanceTests {
@Before
@Override
public void setup() throws Exception {
this.legalTagUtils = new AzureLegalTagUtils();
super.setup();
}
@After
@Override
public void teardown() throws Exception {
super.teardown();
this.legalTagUtils = null;
}
@Test
@Override
public void should_return307_when_makingHttpRequest() throws Exception {
// services are enforced to run in https on Azure
}
@Test
@Override
public void should_return401_when_makingHttpRequestWithoutToken() throws Exception {
// services are enforced to run in https on Azure
}
}
package org.opengroup.osdu.legal.acceptanceTests;
import static org.junit.Assert.assertNotNull;
import com.sun.jersey.api.client.ClientResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.junit.Test;
import org.opengroup.osdu.legal.util.AcceptanceBaseTest;
import org.opengroup.osdu.legal.util.VersionInfoUtils;
public abstract class GetInfoApiAcceptanceTests extends AcceptanceBaseTest {
protected static final VersionInfoUtils VERSION_INFO_UTILS = new VersionInfoUtils();
@Test
public void should_returnInfo() throws Exception {
ClientResponse response = send(StringUtils.EMPTY, HttpStatus.SC_OK);
VersionInfoUtils.VersionInfo responseObject =
VERSION_INFO_UTILS.getVersionInfoFromResponse(response);
assertNotNull(responseObject.groupId);
assertNotNull(responseObject.artifactId);
assertNotNull(responseObject.version);
assertNotNull(responseObject.buildTime);
assertNotNull(responseObject.branch);
assertNotNull(responseObject.commitId);
assertNotNull(responseObject.commitMessage);
}
@Override
protected String getApi() {
return "info";
}
@Override
protected String getHttpMethod() {
return "GET";
}
@Override
public void should_return307_when_makingHttpRequest() throws Exception {
// not actual for this endpoint
}
@Override
public void should_return401_when_makingHttpRequestWithoutToken() throws Exception {
// not actual for this endpoint
}
}
......@@ -21,9 +21,9 @@ public abstract class AcceptanceBaseTest {
protected abstract String getHttpMethod();
public void setup() throws Exception {};
public void teardown() throws Exception {};
public void setup() throws Exception {}
public void teardown() throws Exception {}
protected String getBody(){
return "{}";
......
package org.opengroup.osdu.legal.util;
import static org.junit.Assert.assertTrue;
import com.google.gson.Gson;
import com.sun.jersey.api.client.ClientResponse;
public class VersionInfoUtils {
public VersionInfo getVersionInfoFromResponse(ClientResponse response) {
assertTrue(response.getType().toString().contains("application/json"));
String json = response.getEntity(String.class);
Gson gson = new Gson();
return gson.fromJson(json, VersionInfo.class);
}
public class VersionInfo {
public String groupId;
public String artifactId;
public String version;
public String buildTime;
public String branch;
public String commitId;
public String commitMessage;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment