From 279000bdcb78ea152228ceba30f96e85e657e587 Mon Sep 17 00:00:00 2001 From: "Dmitriy Novikov (EPAM)" <dmitrii_novikov1@epam.com> Date: Tue, 17 Aug 2021 13:26:40 +0000 Subject: [PATCH] Added new version info endpoint (GONRG-2811) --- NOTICE | 8 +-- docs/api/notification_openapi.yaml | 59 ++++++++++++++++++- docs/tutorial/DataNotification.md | 37 ++++++++++++ .../osdu/notification/api/InfoApi.java | 40 +++++++++++++ .../auth/AuthorizationFilter.java | 7 +-- .../osdu/notification/api/InfoApiTest.java | 56 ++++++++++++++++++ pom.xml | 42 ++++++++++++- provider/notification-gcp/pom.xml | 1 - .../provider/ibm/security/SecurityConfig.java | 1 + 9 files changed, 240 insertions(+), 11 deletions(-) create mode 100644 notification-core/src/main/java/org/opengroup/osdu/notification/api/InfoApi.java create mode 100644 notification-core/src/test/java/org/opengroup/osdu/notification/api/InfoApiTest.java diff --git a/NOTICE b/NOTICE index 2d4af556b..a8b3d2f64 100644 --- a/NOTICE +++ b/NOTICE @@ -114,10 +114,9 @@ The following software have components provided under the terms of this license: - IBM COS SDK for Java - Core (from https://github.com/ibm/ibm-cos-sdk-java) - Identity and Access Management (IAM) API v1-rev307-1.25.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-iam) - Identity and Access Management (IAM) API v1-rev307-1.25.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-iam) -- IntelliJ IDEA Annotations (from http://www.jetbrains.org) - J2ObjC Annotations (from https://github.com/google/j2objc/) - JBoss Logging 3 (from http://www.jboss.org) -- JBoss Threads (from ) +- JBoss Threads (from https://repo1.maven.org/maven2/org/jboss/threads/jboss-threads) - JCIP Annotations under Apache License (from http://stephenc.github.com/jcip-annotations) - JMES Path Query library (from https://aws.amazon.com/sdkforjava) - JSON Small and Fast Parser (from https://repo1.maven.org/maven2/net/minidev/json-smart) @@ -150,6 +149,7 @@ The following software have components provided under the terms of this license: - Java UUID Generator (from http://wiki.fasterxml.com/JugHome) - Javassist (from http://www.javassist.org/) - Javassist (from http://www.javassist.org/) +- JetBrains Java Annotations (from https://github.com/JetBrains/java-annotations) - Joda-Time (from https://www.joda.org/joda-time/) - KeePassJava2 :: All (from https://repo1.maven.org/maven2/org/linguafranca/pwdb/KeePassJava2) - KeePassJava2 :: DOM (from https://repo1.maven.org/maven2/org/linguafranca/pwdb/KeePassJava2-dom) @@ -165,8 +165,8 @@ The following software have components provided under the terms of this license: - Lucene Grouping (from https://repo1.maven.org/maven2/org/apache/lucene/lucene-grouping) - Lucene Highlighter (from https://repo1.maven.org/maven2/org/apache/lucene/lucene-highlighter) - Lucene Join (from https://repo1.maven.org/maven2/org/apache/lucene/lucene-join) -- Lucene Memory (from https://repo1.maven.org/maven2/org/apache/lucene/lucene-backward-codecs) - Lucene Memory (from https://repo1.maven.org/maven2/org/apache/lucene/lucene-memory) +- Lucene Memory (from https://repo1.maven.org/maven2/org/apache/lucene/lucene-backward-codecs) - Lucene Miscellaneous (from https://repo1.maven.org/maven2/org/apache/lucene/lucene-misc) - Lucene Queries (from https://repo1.maven.org/maven2/org/apache/lucene/lucene-queries) - Lucene QueryParsers (from https://repo1.maven.org/maven2/org/apache/lucene/lucene-queryparser) @@ -653,7 +653,7 @@ LGPL-2.1-or-later ======================================================================== The following software have components provided under the terms of this license: -- JBoss Threads (from ) +- JBoss Threads (from https://repo1.maven.org/maven2/org/jboss/threads/jboss-threads) - Javassist (from http://www.javassist.org/) - Javassist (from http://www.javassist.org/) - SnakeYAML (from http://www.snakeyaml.org) diff --git a/docs/api/notification_openapi.yaml b/docs/api/notification_openapi.yaml index e65325415..f4ec41d72 100644 --- a/docs/api/notification_openapi.yaml +++ b/docs/api/notification_openapi.yaml @@ -12,6 +12,8 @@ info: tags: - name: pubsub-endpoint description: Pubsub Endpoint + - name: info + description: Version info endpoint paths: /push-handlers/records-changed: post: @@ -45,6 +47,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: "#/components/schemas/VersionInfo" servers: - url: https://evq.csp.osdu.com/api/notification/v1 description: EVT @@ -66,4 +83,44 @@ components: type: string statusCodeValue: type: integer - format: int32 \ No newline at end of file + format: int32 + 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 diff --git a/docs/tutorial/DataNotification.md b/docs/tutorial/DataNotification.md index 93cc3a0d6..a590cc37b 100644 --- a/docs/tutorial/DataNotification.md +++ b/docs/tutorial/DataNotification.md @@ -11,6 +11,7 @@ * [Delete a Subscription by ID](#delete-subscription) * [Handle notifications](#process-messages) * [Update secret for a Subscription](#update-subscription) +* [Version info endpoint](#version-info-endpoint) * [Current Limitations](#limitation) ## Introduction <a name="introduction"></a> @@ -600,6 +601,42 @@ curl --request PUT \ [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) + ## Current Limitations <a name="limitation"></a> - There is no filtering applied on messages (such as based on the kind etc.) at the moment in OSDU. All the messages will be pushed to consumers. - Updates to existing records are notified as `create` event with attribute `recordUpdated` set to true. diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/api/InfoApi.java b/notification-core/src/main/java/org/opengroup/osdu/notification/api/InfoApi.java new file mode 100644 index 000000000..2df52563f --- /dev/null +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/api/InfoApi.java @@ -0,0 +1,40 @@ +/* + * 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.notification.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 diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/AuthorizationFilter.java b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/AuthorizationFilter.java index 2eb23d060..0d4693068 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/AuthorizationFilter.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/AuthorizationFilter.java @@ -55,10 +55,9 @@ public class AuthorizationFilter { } String path = request.getServletPath(); - if ("GET".equals(request.getMethod())) { - if (path.equals("/swagger-ui.html")) { - return true; - } + if ("GET".equals(request.getMethod()) && + (path.equals("/swagger-ui.html") || path.equals("/info"))) { + return true; } if (Arrays.asList(requiredRoles).contains(Config.CRON) && requestInfoExt.isCronRequest()) { diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/api/InfoApiTest.java b/notification-core/src/test/java/org/opengroup/osdu/notification/api/InfoApiTest.java new file mode 100644 index 000000000..343678e12 --- /dev/null +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/api/InfoApiTest.java @@ -0,0 +1,56 @@ +/* + * 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.notification.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("Merge commit") + .build(); + when(versionInfoBuilder.buildVersionInfo()).thenReturn(versionInfo); + VersionInfo response = this.sut.info(); + assertEquals(versionInfo, response); + } +} diff --git a/pom.xml b/pom.xml index 11457fcce..51b34af47 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ <java.version>8</java.version> <maven.compiler.target>${java.version}</maven.compiler.target> <maven.compiler.source>${java.version}</maven.compiler.source> - <os-core-common.version>0.11.0-rc3</os-core-common.version> + <os-core-common.version>0.11.0-SNAPSHOT</os-core-common.version> </properties> <licenses> @@ -128,4 +128,44 @@ </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> diff --git a/provider/notification-gcp/pom.xml b/provider/notification-gcp/pom.xml index 2cde8c2ad..ffdff897c 100644 --- a/provider/notification-gcp/pom.xml +++ b/provider/notification-gcp/pom.xml @@ -40,7 +40,6 @@ <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>os-core-common</artifactId> - <version>0.10.0</version> </dependency> <dependency> <groupId>org.opengroup.osdu</groupId> diff --git a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/security/SecurityConfig.java b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/security/SecurityConfig.java index 593efbbbf..bfa018bdf 100644 --- a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/security/SecurityConfig.java +++ b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/security/SecurityConfig.java @@ -20,6 +20,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { "/swagger-resources/**", "/configuration/security", "/swagger-ui.html", + "/info", "/webjars/**") .permitAll().anyRequest().authenticated().and().oauth2ResourceServer().jwt(); } -- GitLab