From 698aae6db9e42b0621c32ce2e4bef363c376384b Mon Sep 17 00:00:00 2001 From: neelesh thakur <nthakur4@slb.com> Date: Fri, 21 Aug 2020 06:55:01 -0400 Subject: [PATCH] refactor provider interfaces --- .gitlab/merge_request_templates/default.md | 25 +++++++++++++++++++ .../osdu/notification/api/PubsubEndpoint.java | 2 +- .../auth/AuthorizationFilter.java | 4 +-- .../auth/EntitlementsClientFactory.java | 2 +- .../di/CredentialHeadersProvider.java | 1 - .../di/SubscriptionClientFactory.java | 8 ++---- .../interfaces/IAppProperties.java} | 11 ++++---- .../interfaces}/IGoogleServiceAccount.java | 2 +- .../interfaces/IServiceAccountValidator.java} | 5 ++-- .../notification/utils/IAppProperties.java | 7 ------ .../notification/api/PubsubEndpointTests.java | 2 +- .../auth/AuthorizationFilterTest.java | 4 +-- .../osdu/notification/di/RequestInfoTest.java | 2 +- .../provider/azure/util/AppProperties.java | 2 +- .../AzureServiceAccountValidatorImpl.java | 4 +-- .../azure/util/GoogleServiceAccountImpl.java | 2 +- .../provider/gcp/util/AppProperties.java | 2 +- .../gcp/util/GoogleServiceAccountImpl.java | 2 +- .../GoogleServiceAccountValidatorImpl.java | 4 +-- 19 files changed, 53 insertions(+), 38 deletions(-) create mode 100644 .gitlab/merge_request_templates/default.md rename notification-core/src/main/java/org/opengroup/osdu/notification/{auth/AuthorizationService.java => provider/interfaces/IAppProperties.java} (74%) rename notification-core/src/main/java/org/opengroup/osdu/notification/{utils => provider/interfaces}/IGoogleServiceAccount.java (92%) rename notification-core/src/main/java/org/opengroup/osdu/notification/{utils/ServiceAccountValidator.java => provider/interfaces/IServiceAccountValidator.java} (87%) delete mode 100644 notification-core/src/main/java/org/opengroup/osdu/notification/utils/IAppProperties.java diff --git a/.gitlab/merge_request_templates/default.md b/.gitlab/merge_request_templates/default.md new file mode 100644 index 000000000..30b572826 --- /dev/null +++ b/.gitlab/merge_request_templates/default.md @@ -0,0 +1,25 @@ +## Type of change +- [ ] Bug Fix +- [ ] Feature + +**Please provide link to gitlab issue or ADR(Architecture Decision Record)** + +## Does this introduce a change in the core logic? +- [YES/NO] + +## Does this introduce a change in the cloud provider implementation, if so which cloud? +- [ ] AWS +- [ ] Azure +- [ ] GCP +- [ ] IBM + +## Does this introduce a breaking change? +- [YES/NO] + +## What is the current behavior? + +## What is the new/expected behavior? + +## Have you added/updated Unit Tests and Integration Tests? + +## Any other useful information diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/api/PubsubEndpoint.java b/notification-core/src/main/java/org/opengroup/osdu/notification/api/PubsubEndpoint.java index 975d66958..89a3376a1 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/api/PubsubEndpoint.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/api/PubsubEndpoint.java @@ -36,7 +36,7 @@ import org.opengroup.osdu.core.common.notification.SubscriptionException; import org.opengroup.osdu.notification.di.SubscriptionCacheFactory; import org.opengroup.osdu.notification.pubsub.PubsubRequestBodyExtractor; import org.opengroup.osdu.notification.utils.Config; -import org.opengroup.osdu.notification.utils.IGoogleServiceAccount; +import org.opengroup.osdu.notification.provider.interfaces.IGoogleServiceAccount; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; 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 c720b2d5c..36bfc8039 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 @@ -23,7 +23,7 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.provider.interfaces.IAuthorizationService; import org.opengroup.osdu.notification.di.RequestInfoExt; import org.opengroup.osdu.notification.utils.Config; -import org.opengroup.osdu.notification.utils.ServiceAccountValidator; +import org.opengroup.osdu.notification.provider.interfaces.IServiceAccountValidator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; @@ -40,7 +40,7 @@ public class AuthorizationFilter { @Autowired private RequestInfoExt requestInfoExt; @Autowired - private ServiceAccountValidator validator; + private IServiceAccountValidator validator; public boolean hasAnyPermission(String... requiredRoles) { DpsHeaders dpsHeaders = requestInfoExt.getHeaders(); diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/EntitlementsClientFactory.java b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/EntitlementsClientFactory.java index efd7a908e..53a5427d1 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/EntitlementsClientFactory.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/EntitlementsClientFactory.java @@ -19,7 +19,7 @@ package org.opengroup.osdu.notification.auth; import org.opengroup.osdu.core.common.entitlements.EntitlementsAPIConfig; import org.opengroup.osdu.core.common.entitlements.EntitlementsFactory; import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory; -import org.opengroup.osdu.notification.utils.IAppProperties; +import org.opengroup.osdu.notification.provider.interfaces.IAppProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.AbstractFactoryBean; import org.springframework.stereotype.Component; diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/di/CredentialHeadersProvider.java b/notification-core/src/main/java/org/opengroup/osdu/notification/di/CredentialHeadersProvider.java index f27e7815c..24b6646c8 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/di/CredentialHeadersProvider.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/di/CredentialHeadersProvider.java @@ -18,7 +18,6 @@ package org.opengroup.osdu.notification.di; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; import org.opengroup.osdu.notification.pubsub.PubsubRequestBodyExtractor; -import org.opengroup.osdu.notification.utils.IAppProperties; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Primary; diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/di/SubscriptionClientFactory.java b/notification-core/src/main/java/org/opengroup/osdu/notification/di/SubscriptionClientFactory.java index b367f7fc1..feda29e96 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/di/SubscriptionClientFactory.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/di/SubscriptionClientFactory.java @@ -16,17 +16,13 @@ package org.opengroup.osdu.notification.di; +import org.opengroup.osdu.core.common.notification.ISubscriptionFactory; import org.opengroup.osdu.core.common.notification.SubscriptionAPIConfig; import org.opengroup.osdu.core.common.notification.SubscriptionFactory; -import org.opengroup.osdu.notification.utils.IAppProperties; +import org.opengroup.osdu.notification.provider.interfaces.IAppProperties; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -import org.opengroup.osdu.core.common.notification.ISubscriptionFactory; -import org.opengroup.osdu.core.common.model.notification.*; @Component public class SubscriptionClientFactory extends AbstractFactoryBean<ISubscriptionFactory> { diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/AuthorizationService.java b/notification-core/src/main/java/org/opengroup/osdu/notification/provider/interfaces/IAppProperties.java similarity index 74% rename from notification-core/src/main/java/org/opengroup/osdu/notification/auth/AuthorizationService.java rename to notification-core/src/main/java/org/opengroup/osdu/notification/provider/interfaces/IAppProperties.java index 24b05695a..c5bf01120 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/AuthorizationService.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/provider/interfaces/IAppProperties.java @@ -14,10 +14,11 @@ * limitations under the License. */ -package org.opengroup.osdu.notification.auth; +package org.opengroup.osdu.notification.provider.interfaces; -import org.opengroup.osdu.core.common.model.http.DpsHeaders; +public interface IAppProperties { -public interface AuthorizationService { - String authorizeAny(DpsHeaders headers, String... roles); -} + String getAuthorizeAPI(); + + String getRegisterAPI(); +} \ No newline at end of file diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/utils/IGoogleServiceAccount.java b/notification-core/src/main/java/org/opengroup/osdu/notification/provider/interfaces/IGoogleServiceAccount.java similarity index 92% rename from notification-core/src/main/java/org/opengroup/osdu/notification/utils/IGoogleServiceAccount.java rename to notification-core/src/main/java/org/opengroup/osdu/notification/provider/interfaces/IGoogleServiceAccount.java index ae067a8a9..33628ba3d 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/utils/IGoogleServiceAccount.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/provider/interfaces/IGoogleServiceAccount.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.opengroup.osdu.notification.utils; +package org.opengroup.osdu.notification.provider.interfaces; public interface IGoogleServiceAccount { diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/utils/ServiceAccountValidator.java b/notification-core/src/main/java/org/opengroup/osdu/notification/provider/interfaces/IServiceAccountValidator.java similarity index 87% rename from notification-core/src/main/java/org/opengroup/osdu/notification/utils/ServiceAccountValidator.java rename to notification-core/src/main/java/org/opengroup/osdu/notification/provider/interfaces/IServiceAccountValidator.java index 1491eba4f..3b36bb1de 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/utils/ServiceAccountValidator.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/provider/interfaces/IServiceAccountValidator.java @@ -14,9 +14,10 @@ * limitations under the License. */ -package org.opengroup.osdu.notification.utils; +package org.opengroup.osdu.notification.provider.interfaces; + +public interface IServiceAccountValidator { -public interface ServiceAccountValidator { boolean isValidPublisherServiceAccount(String jwt); boolean isValidServiceAccount(String jwt, String userIdentity, String... audiences); diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/utils/IAppProperties.java b/notification-core/src/main/java/org/opengroup/osdu/notification/utils/IAppProperties.java deleted file mode 100644 index 16049cc10..000000000 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/utils/IAppProperties.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.opengroup.osdu.notification.utils; - -public interface IAppProperties { - String getAuthorizeAPI(); - - String getRegisterAPI(); -} \ No newline at end of file diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/api/PubsubEndpointTests.java b/notification-core/src/test/java/org/opengroup/osdu/notification/api/PubsubEndpointTests.java index 67b9a4a81..d3155489b 100644 --- a/notification-core/src/test/java/org/opengroup/osdu/notification/api/PubsubEndpointTests.java +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/api/PubsubEndpointTests.java @@ -37,7 +37,7 @@ import org.opengroup.osdu.core.common.notification.SubscriptionService; import org.opengroup.osdu.notification.di.CredentialHeadersProvider; import org.opengroup.osdu.notification.di.SubscriptionCacheFactory; import org.opengroup.osdu.notification.pubsub.PubsubRequestBodyExtractor; -import org.opengroup.osdu.notification.utils.IGoogleServiceAccount; +import org.opengroup.osdu.notification.provider.interfaces.IGoogleServiceAccount; import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.http.ResponseEntity; diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/auth/AuthorizationFilterTest.java b/notification-core/src/test/java/org/opengroup/osdu/notification/auth/AuthorizationFilterTest.java index c73e87d11..50a46790c 100644 --- a/notification-core/src/test/java/org/opengroup/osdu/notification/auth/AuthorizationFilterTest.java +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/auth/AuthorizationFilterTest.java @@ -28,7 +28,7 @@ import org.opengroup.osdu.core.common.provider.interfaces.IAuthorizationService; import org.opengroup.osdu.notification.di.RequestInfoExt; import org.opengroup.osdu.notification.pubsub.PubsubRequestBodyExtractor; import org.opengroup.osdu.notification.utils.Config; -import org.opengroup.osdu.notification.utils.ServiceAccountValidator; +import org.opengroup.osdu.notification.provider.interfaces.IServiceAccountValidator; import org.powermock.modules.junit4.PowerMockRunner; import java.util.HashMap; @@ -57,7 +57,7 @@ public class AuthorizationFilterTest { @Mock private IAuthorizationService authorizationService; @Mock - private ServiceAccountValidator validator; + private IServiceAccountValidator validator; @Mock private PubsubRequestBodyExtractor extractor; @InjectMocks diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/di/RequestInfoTest.java b/notification-core/src/test/java/org/opengroup/osdu/notification/di/RequestInfoTest.java index 2518ce8e1..a0a7d4814 100644 --- a/notification-core/src/test/java/org/opengroup/osdu/notification/di/RequestInfoTest.java +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/di/RequestInfoTest.java @@ -20,7 +20,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.opengroup.osdu.notification.utils.IAppProperties; +import org.opengroup.osdu.notification.provider.interfaces.IAppProperties; import org.powermock.modules.junit4.PowerMockRunner; import javax.servlet.http.HttpServletRequest; diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java index 10bac0d15..8d751e083 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java @@ -19,7 +19,7 @@ import com.azure.cosmos.CosmosClient; import com.azure.security.keyvault.secrets.SecretClient; import com.azure.security.keyvault.secrets.models.KeyVaultSecret; import org.opengroup.osdu.azure.KeyVaultFacade; -import org.opengroup.osdu.notification.utils.IAppProperties; +import org.opengroup.osdu.notification.provider.interfaces.IAppProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureServiceAccountValidatorImpl.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureServiceAccountValidatorImpl.java index 7f153b364..971666dd8 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureServiceAccountValidatorImpl.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureServiceAccountValidatorImpl.java @@ -14,11 +14,11 @@ package org.opengroup.osdu.notification.provider.azure.util; -import org.opengroup.osdu.notification.utils.ServiceAccountValidator; +import org.opengroup.osdu.notification.provider.interfaces.IServiceAccountValidator; import org.springframework.stereotype.Component; @Component -public class AzureServiceAccountValidatorImpl implements ServiceAccountValidator { +public class AzureServiceAccountValidatorImpl implements IServiceAccountValidator { @Override public boolean isValidPublisherServiceAccount(String jwt) { diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/GoogleServiceAccountImpl.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/GoogleServiceAccountImpl.java index ed4631926..9b0adf6c0 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/GoogleServiceAccountImpl.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/GoogleServiceAccountImpl.java @@ -15,7 +15,7 @@ package org.opengroup.osdu.notification.provider.azure.util; import lombok.SneakyThrows; -import org.opengroup.osdu.notification.utils.IGoogleServiceAccount; +import org.opengroup.osdu.notification.provider.interfaces.IGoogleServiceAccount; import org.springframework.stereotype.Component; import javax.naming.AuthenticationNotSupportedException; diff --git a/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/AppProperties.java b/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/AppProperties.java index 19789adf6..1aa85c59d 100644 --- a/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/AppProperties.java +++ b/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/AppProperties.java @@ -16,7 +16,7 @@ package org.opengroup.osdu.notification.provider.gcp.util; -import org.opengroup.osdu.notification.utils.IAppProperties; +import org.opengroup.osdu.notification.provider.interfaces.IAppProperties; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/GoogleServiceAccountImpl.java b/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/GoogleServiceAccountImpl.java index 7dcf3ba66..1555ab181 100644 --- a/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/GoogleServiceAccountImpl.java +++ b/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/GoogleServiceAccountImpl.java @@ -19,7 +19,7 @@ package org.opengroup.osdu.notification.provider.gcp.util; import lombok.SneakyThrows; import org.apache.http.impl.client.CloseableHttpClient; import org.opengroup.osdu.core.gcp.GoogleIdToken.IGoogleIdTokenFactory; -import org.opengroup.osdu.notification.utils.IGoogleServiceAccount; +import org.opengroup.osdu.notification.provider.interfaces.IGoogleServiceAccount; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; diff --git a/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/GoogleServiceAccountValidatorImpl.java b/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/GoogleServiceAccountValidatorImpl.java index 2d70b3d3c..3a1736a92 100644 --- a/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/GoogleServiceAccountValidatorImpl.java +++ b/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/GoogleServiceAccountValidatorImpl.java @@ -21,12 +21,12 @@ import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.json.jackson2.JacksonFactory; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.notification.utils.ServiceAccountValidator; +import org.opengroup.osdu.notification.provider.interfaces.IServiceAccountValidator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service -public class GoogleServiceAccountValidatorImpl implements ServiceAccountValidator { +public class GoogleServiceAccountValidatorImpl implements IServiceAccountValidator { private final NetHttpTransport netHttpTransport = new NetHttpTransport(); private final JacksonFactory jacksonFactory = new JacksonFactory(); -- GitLab