Commit d89ffaf5 authored by Rostislav Dublin (EPAM)'s avatar Rostislav Dublin (EPAM)
Browse files

Merge branch 'version-endpoint' into 'master'

Added new version info endpoint (GONRG-2681)

See merge request !105
parents 8564abc8 d54f0727
Pipeline #61272 failed with stages
in 28 minutes and 46 seconds
This diff is collapsed.
......@@ -30,6 +30,7 @@ spec:
- operation:
notPaths: ["/","*/index.html",
"*/v2/api-docs",
"*/api/entitlements/v2/info",
"*/swagger","*/swagger-resources","*/swagger-ui.html",
"*/actuator/health", "*/health",
"*/configuration/ui","*/configuration/security",
......
......@@ -33,6 +33,8 @@ tags:
description: Update Group Api
- name: list-member-api
description: List Member Api
- name: info
description: Version info endpoint
paths:
/_ah/liveness_check:
get:
......@@ -481,6 +483,21 @@ paths:
security:
- JWT:
- global
/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:
JWT:
type: apiKey
......@@ -501,3 +518,43 @@ definitions:
type: object
UpdateGroupResponseDto:
type: object
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
......@@ -3,6 +3,7 @@
- [Introduction](#introduction)
* [Entitlement Service API](#entitlement-service-api)
- [OSDU Data Ecosystem user groups](#datalake-user-groups)
- [Version info endpoint](#version-info-endpoint)
## Introduction<a name="introduction"></a>
......@@ -223,3 +224,39 @@ OSDU Data Ecosystem user groups provides an abstraction from permission and user
| /entitlements/v1/groups/{group_email}/members/{member_email} | DELETE | service.entitlements.user |
[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
/*
* 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.entitlements.v2.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
/*
* 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.entitlements.v2.util;
import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
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;
import org.springframework.web.context.annotation.RequestScope;
@Component
@ConditionalOnMissingBean(type = "ConnectedOuterServicesBuilder")
@Slf4j
@RequestScope
public class CloudConnectedOuterServicesBuilder implements ConnectedOuterServicesBuilder {
private static final String REDIS_PREFIX = "Redis-";
private final 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();
}}
\ No newline at end of file
/*
* 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.entitlements.v2.api;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.info.VersionInfoBuilder;
import org.opengroup.osdu.core.common.model.info.VersionInfo;
@RunWith(MockitoJUnitRunner.class)
public class InfoApiTest {
@InjectMocks
private InfoApi sut;
@Mock
private VersionInfoBuilder versionInfoBuilder;
@Test
public void should_return200_getVersionInfo() throws IOException {
VersionInfo versionInfo = VersionInfo.builder()
.groupId("group")
.artifactId("artifact")
.version("0.1.0")
.buildTime("1000")
.branch("master")
.commitId("7777")
.commitMessage("Test commit")
.build();
when(versionInfoBuilder.buildVersionInfo()).thenReturn(versionInfo);
VersionInfo response = this.sut.info();
assertEquals(versionInfo, response);
}
}
......@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<properties>
<os-core-common.version>0.10.0</os-core-common.version>
<os-core-common.version>0.11.0-rc4</os-core-common.version>
<java.version>1.8</java.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
......@@ -43,6 +43,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.18.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
......@@ -71,9 +78,39 @@
<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>
<repositories>
......
......@@ -30,6 +30,12 @@
<groupId>org.opengroup.osdu.core.aws</groupId>
<artifactId>os-core-lib-aws</artifactId>
<version>${core-lib-aws.version}</version>
<exclusions>
<exclusion>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
......
......@@ -26,6 +26,9 @@ public class InterceptorConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(requestHeaderInterceptor).addPathPatterns("/**").excludePathPatterns("/_ah/**");
registry
.addInterceptor(requestHeaderInterceptor)
.addPathPatterns("/**")
.excludePathPatterns("/_ah/**", "/info");
}
}
......@@ -51,6 +51,10 @@
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
</exclusion>
<exclusion>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--
......
......@@ -221,7 +221,6 @@
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
......@@ -301,6 +300,21 @@
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>org.opengroup.osdu.entitlements.v2.Application</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
/*
* 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.entitlements.v2.gcp.service;
import org.opengroup.osdu.entitlements.v2.service.HealthService;
import org.springframework.stereotype.Service;
@Service
public class HealthServiceGCP implements HealthService {
@Override
public void performHealthCheck() {
}
}
\ No newline at end of file
......@@ -15,6 +15,9 @@ public class InterceptorConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(requestHeaderInterceptor).addPathPatterns("/**").excludePathPatterns("/_ah/**");
registry
.addInterceptor(requestHeaderInterceptor)
.addPathPatterns("/**")
.excludePathPatterns("/_ah/**", "/info");
}
}
......@@ -15,8 +15,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().disable()
.csrf().disable().authorizeRequests().anyRequest()
.authenticated().and().oauth2ResourceServer().jwt();
.csrf().disable().authorizeRequests()
.antMatchers("/info").permitAll()
.anyRequest().authenticated().and().oauth2ResourceServer().jwt();
}
}
......
......@@ -57,6 +57,12 @@
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-gcp</artifactId>
<version>0.10.0</version>
<exclusions>
<exclusion>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
......
......@@ -61,7 +61,7 @@ public class RequestHeaderInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws IOException {
if (TRUE.equals(validateSwaggerRequest(request))) {
if (isSwaggerRequest(request) || isVersionInfo(request)) {
return true;
}
......@@ -90,11 +90,16 @@ public class RequestHeaderInterceptor implements HandlerInterceptor {
return false;
}
private Boolean validateSwaggerRequest(HttpServletRequest request) {
private boolean isSwaggerRequest(HttpServletRequest request) {
String endpoint = request.getRequestURI().replace(request.getContextPath(), "");
return endpoint.startsWith("/swagger") || endpoint.startsWith("/webjars");
}
private boolean isVersionInfo(HttpServletRequest request) {
String endpoint = request.getRequestURI().replace(request.getContextPath(), "");
return endpoint.startsWith("/info");
}
private UserInfo getUserInfoFromToken(String token) {
return getUserInfoFromIDToken(token);
}
......
/*
* 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.entitlements.v2.jdbc.service;
import org.opengroup.osdu.entitlements.v2.service.HealthService;
import org.springframework.stereotype.Service;
@Service
public class HealthServiceJdbc implements HealthService {
@Override
public void performHealthCheck() {
}
}
\ No newline at end of file
......@@ -50,11 +50,17 @@
<artifactId>os-core-lib-aws</artifactId>
<version>${core-lib-aws.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>0.10.0</version>
<version>0.11.0-rc4</version>
<scope>test</scope>
</dependency>
<dependency>
......
package org.opengroup.osdu.entitlements.v2.aws.acceptance.api;
import org.opengroup.osdu.entitlements.v2.acceptance.api.InfoApiTest;
import org.opengroup.osdu.entitlements.v2.util.AwsConfigurationService;
import org.opengroup.osdu.entitlements.v2.util.AwsTokenService;
public class InfoApiAwsTest extends InfoApiTest {
public InfoApiAwsTest() {
super(new AwsConfigurationService(), new AwsTokenService());