From c248bad91d764ceebbab72d426054b2185b4b8a4 Mon Sep 17 00:00:00 2001 From: Rustam_Lotsmanenko Date: Tue, 31 May 2022 14:45:48 +0400 Subject: [PATCH] fix opa endpoint config --- .../storage/opa/service/OPAServiceConfig.java | 32 +++++++++++++++++++ .../storage/opa/service/OPAServiceImpl.java | 10 ++---- .../osdu/storage/opa/OPAServiceImplTest.java | 4 +++ 3 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 storage-core/src/main/java/org/opengroup/osdu/storage/opa/service/OPAServiceConfig.java diff --git a/storage-core/src/main/java/org/opengroup/osdu/storage/opa/service/OPAServiceConfig.java b/storage-core/src/main/java/org/opengroup/osdu/storage/opa/service/OPAServiceConfig.java new file mode 100644 index 000000000..9295c3dee --- /dev/null +++ b/storage-core/src/main/java/org/opengroup/osdu/storage/opa/service/OPAServiceConfig.java @@ -0,0 +1,32 @@ +/* + * Copyright 2020-2022 Google LLC + * Copyright 2020-2022 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 + * + * http://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.storage.opa.service; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Getter +@Setter +@Configuration +@ConfigurationProperties(prefix = "opa") +public class OPAServiceConfig { + + private String opaEndpoint; +} diff --git a/storage-core/src/main/java/org/opengroup/osdu/storage/opa/service/OPAServiceImpl.java b/storage-core/src/main/java/org/opengroup/osdu/storage/opa/service/OPAServiceImpl.java index fece5d46c..696608124 100644 --- a/storage-core/src/main/java/org/opengroup/osdu/storage/opa/service/OPAServiceImpl.java +++ b/storage-core/src/main/java/org/opengroup/osdu/storage/opa/service/OPAServiceImpl.java @@ -25,7 +25,6 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.indexer.OperationType; -import org.opengroup.osdu.core.common.model.storage.Record; import org.opengroup.osdu.core.common.model.storage.RecordMetadata; import org.opengroup.osdu.storage.opa.model.CreateOrUpdateValidationInput; import org.opengroup.osdu.storage.opa.model.CreateOrUpdateValidationRequest; @@ -33,23 +32,20 @@ import org.opengroup.osdu.storage.opa.model.CreateOrUpdateValidationResponse; import org.opengroup.osdu.storage.opa.model.ValidationInputRecord; import org.opengroup.osdu.storage.opa.model.ValidationOutputRecord; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Service; import java.lang.reflect.Type; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; @Service @ConfigurationProperties(prefix = "opa") public class OPAServiceImpl implements IOPAService { - private String opaEndpoint; + @Autowired + private OPAServiceConfig opaServiceConfig; @Autowired private DpsHeaders headers; @@ -98,7 +94,7 @@ public class OPAServiceImpl implements IOPAService { Type validationRequestType = new TypeToken() {}.getType(); String requestBody = gson.toJson(createOrUpdateValidationRequest, validationRequestType); - String evaluateUrl = String.format("%s/v1/data/osdu/partition/%s/dataauthz/records", opaEndpoint, headers.getPartitionIdWithFallbackToAccountId()); + String evaluateUrl = String.format("%s/v1/data/osdu/partition/%s/dataauthz/records", opaServiceConfig.getOpaEndpoint(), headers.getPartitionIdWithFallbackToAccountId()); logger.debug("opa url: " + evaluateUrl); HttpRequest httpRequest = HttpRequest.builder() diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/opa/OPAServiceImplTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/opa/OPAServiceImplTest.java index 18313ed76..0854d08da 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/opa/OPAServiceImplTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/opa/OPAServiceImplTest.java @@ -21,6 +21,7 @@ import org.opengroup.osdu.core.common.model.storage.Record; import org.opengroup.osdu.core.common.model.storage.RecordMetadata; import org.opengroup.osdu.core.common.model.storage.RecordState; import org.opengroup.osdu.storage.opa.model.ValidationOutputRecord; +import org.opengroup.osdu.storage.opa.service.OPAServiceConfig; import org.opengroup.osdu.storage.opa.service.OPAServiceImpl; import java.util.ArrayList; @@ -50,6 +51,9 @@ public class OPAServiceImplTest { @Mock private HttpResponse httpResponse; + @Mock + private OPAServiceConfig opaServiceConfig; + @InjectMocks private OPAServiceImpl sut; -- GitLab