Commit eaa19f37 authored by Anastasiia Gelmut's avatar Anastasiia Gelmut Committed by Rostislav Dublin (EPAM)
Browse files

Added service version endpoint (GONRG-2938)

parent 9525af56
This diff is collapsed.
......@@ -46,4 +46,4 @@ 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
\ No newline at end of file
limitations under the License
......@@ -29,5 +29,5 @@ spec:
to:
- operation:
notPaths: ["/","*/swagger-resources","*/swagger","/api/schema-service/v1/webjars/*","*/v2/api-docs",
"/api/schema-service/v1/swagger-resources/*","*/swagger-ui.html", "*/actuator/health"]
"/api/schema-service/v1/swagger-resources/*","*/swagger-ui.html", "*/actuator/health", "/api/schema-service/v1/info"]
......@@ -5,6 +5,7 @@
- [How to use this service?](#using_this_service)
- [Current limitation](#limitation)
- [Schema Validation](#schema-validation)
- [Version info endpoint](#version-info-endpoint)
## Introduction <a name="introduction"></a>
......@@ -312,3 +313,38 @@ Following table gives you error message when breaking change is introduced at an
Note: The above array message would contain given schema version and existing schema in the system
## 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)
......@@ -7,6 +7,8 @@ info:
tags:
- name: Schema
description: Core Schema Service related methods
- name: info
description: "Version info endpoint"
security:
- bearer: []
paths:
......@@ -324,6 +326,21 @@ paths:
security:
- bearer: []
deprecated: false
/info:
get:
tags:
- info
summary: "Version info"
description: "For deployment available public `/info` endpoint, \
\ which provides build and git related information."
operationId: "Version info"
responses:
"200":
description: "Version info."
content:
application/json:
schema:
$ref: "#/components/schemas/VersionInfo"
servers:
- url: VALID_SCHEMA_SERVICE_BASE_URL
......@@ -482,4 +499,45 @@ components:
schemaVersionMinor: 0
schemaVersionPatch: 0
status: PUBLISHED
schema: {}
\ No newline at end of file
schema: {}
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: "#/components/schemas/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
......@@ -81,4 +81,39 @@
</profile>
</profiles>
<build>
<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>
<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>
......@@ -31,7 +31,7 @@
<properties>
<azure.version>2.1.7</azure.version>
<osdu.corelibazure.version>0.10.1</osdu.corelibazure.version>
<osdu.oscorecommon.version>0.10.0</osdu.oscorecommon.version>
<osdu.oscorecommon.version>0.11.0-rc4</osdu.oscorecommon.version>
<osdu.os-schema-core.version>0.10.0-SNAPSHOT</osdu.os-schema-core.version>
<mockito.version>1.10.19</mockito.version>
<cucumber.version>5.4.0</cucumber.version>
......
......@@ -45,6 +45,7 @@ public class AADSecurityConfig extends WebSecurityConfigurerAdapter {
"/configuration/security",
"/swagger",
"/swagger-ui.html",
"/info",
"/webjars/**").permitAll()
.anyRequest().authenticated()
.and()
......
......@@ -31,6 +31,7 @@ public class AADSecurityConfigWithIstioEnabled extends WebSecurityConfigurerAdap
"/configuration/security",
"/swagger",
"/swagger-ui.html",
"/info",
"/schema",
"/schema/**",
"/webjars/**").permitAll()
......
......@@ -6,6 +6,7 @@ AUTHORIZE_API_KEY=
management.health.elasticsearch.enabled=false
management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=health
management.endpoint.info.enabled=false
LOG_PREFIX=schema
# Use this property to name your shared tenant name
......
......@@ -23,6 +23,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
"/swagger-resources/**",
"/configuration/security",
"/swagger-ui.html",
"/info",
"/webjars/**").permitAll()
.anyRequest().authenticated().and().oauth2ResourceServer().jwt();
}
......
......@@ -13,7 +13,7 @@
<properties>
<springfox-version>2.7.0</springfox-version>
<os-core-common.version>0.10.0</os-core-common.version>
<os-core-common.version>0.11.0-rc4</os-core-common.version>
</properties>
<dependencies>
......
/*
* 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.schema.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();
}
}
......@@ -7,6 +7,7 @@ public class TestConstants {
public static final String GET_LIST_ENDPOINT = "/api/schema-service/v1/schema";
public static final String GET_ENDPOINT = "/api/schema-service/v1/schema/";
public static final String GET_FLATTENED_ENDPOINT = "/api/schema-service/v1/schema/{id}/IndexerSchemaV1";
public static final String GET_INFO_ENDPOINT = "/api/schema-service/v1/info";
//public static final String HOST = "http://localhost:8080";
public static final String INTERNAL_SERVER_ERROR = "internal server error";
public static final String INTERNAL = "INTERNAL";
......
package org.opengroup.osdu.schema.stepdefs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import com.google.inject.Inject;
import io.cucumber.java8.En;
import org.opengroup.osdu.schema.constants.TestConstants;
import org.opengroup.osdu.schema.stepdefs.model.HttpRequest;
import org.opengroup.osdu.schema.stepdefs.model.HttpResponse;
import org.opengroup.osdu.schema.stepdefs.model.SchemaServiceScope;
import org.opengroup.osdu.schema.util.HttpClientFactory;
import org.opengroup.osdu.schema.util.VersionInfoUtils;
public class InfoStepDef_GET implements En {
@Inject
private SchemaServiceScope context;
private VersionInfoUtils versionInfoUtil = new VersionInfoUtils();
public InfoStepDef_GET() {
Given("I send get request to version info endpoint", () -> {
HttpRequest httpRequest = HttpRequest.builder()
.url(TestConstants.HOST + TestConstants.GET_INFO_ENDPOINT)
.httpMethod(HttpRequest.GET)
.build();
HttpResponse response = HttpClientFactory.getInstance().send(httpRequest);
this.context.setHttpResponse(response);
});
Then("service should respond back with version info in response", () -> {
assertEquals(200, this.context.getHttpResponse().getCode());
VersionInfoUtils.VersionInfo responseObject = this.versionInfoUtil
.getVersionInfoFromResponse(this.context.getHttpResponse());
assertNotNull(responseObject.groupId);
assertNotNull(responseObject.artifactId);
assertNotNull(responseObject.version);
assertNotNull(responseObject.buildTime);
assertNotNull(responseObject.branch);
assertNotNull(responseObject.commitId);
assertNotNull(responseObject.commitMessage);
});
}
}
package org.opengroup.osdu.schema.util;
import com.google.gson.Gson;
import org.opengroup.osdu.schema.stepdefs.model.HttpResponse;
public class VersionInfoUtils {
public VersionInfo getVersionInfoFromResponse(HttpResponse response) {
String json = response.getBody();
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;
}
}
Feature: To verify version info endpoint content
@SchemaServiceAzure
Scenario: Verify version info endpoint content
Given I send get request to version info endpoint
Then service should respond back with version info in response
......@@ -7,6 +7,7 @@ public class TestConstants {
public static final String GET_LIST_ENDPOINT = "/api/schema-service/v1/schema";
public static final String GET_ENDPOINT = "/api/schema-service/v1/schema/";
public static final String GET_FLATTENED_ENDPOINT = "/api/schema-service/v1/schema/{id}/IndexerSchemaV1";
public static final String GET_INFO_ENDPOINT = "/api/schema-service/v1/info";
//public static final String HOST = "http://localhost:8080";
public static final String INTERNAL_SERVER_ERROR = "internal server error";
public static final String INTERNAL = "INTERNAL";
......
/*
* 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.schema.stepdefs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import com.google.inject.Inject;
import io.cucumber.java8.En;
import org.opengroup.osdu.schema.constants.TestConstants;
import org.opengroup.osdu.schema.stepdefs.model.HttpRequest;
import org.opengroup.osdu.schema.stepdefs.model.HttpResponse;
import org.opengroup.osdu.schema.stepdefs.model.SchemaServiceScope;
import org.opengroup.osdu.schema.util.HttpClientFactory;
import org.opengroup.osdu.schema.util.VersionInfoUtils;
public class InfoStepDef_GET implements En {
@Inject
private SchemaServiceScope context;
private VersionInfoUtils versionInfoUtil = new VersionInfoUtils();
public InfoStepDef_GET() {
Given("I send get request to version info endpoint", () -> {
HttpRequest httpRequest = HttpRequest.builder()
.url(TestConstants.HOST + TestConstants.GET_INFO_ENDPOINT)
.httpMethod(HttpRequest.GET)
.build();
HttpResponse response = HttpClientFactory.getInstance().send(httpRequest);
this.context.setHttpResponse(response);
});
Then("service should respond back with version info in response", () -> {
assertEquals(200, this.context.getHttpResponse().getCode());
VersionInfoUtils.VersionInfo responseObject = this.versionInfoUtil
.getVersionInfoFromResponse(this.context.getHttpResponse());
assertNotNull(responseObject.groupId);
assertNotNull(responseObject.artifactId);
assertNotNull(responseObject.version);
assertNotNull(responseObject.buildTime);
assertNotNull(responseObject.branch);
assertNotNull(responseObject.commitId);
assertNotNull(responseObject.commitMessage);
});
}
}
/*
* 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.schema.util;
import com.google.gson.Gson;
import org.opengroup.osdu.schema.stepdefs.model.HttpResponse;
public class VersionInfoUtils {
public VersionInfo getVersionInfoFromResponse(HttpResponse response) {
String json = response.getBody();
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;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment