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 0000000000000000000000000000000000000000..9295c3deee3714ff3e0f59bfde7965b9f71c2992 --- /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 fece5d46c25537edf08ae6e2ac10eb849b1f5158..696608124b6ec3e4f9651638822a0f1daae93851 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 18313ed76312f0e1e9e1bd816e9360152fafb430..0854d08daa1cb8caa0b79a2449ff05843d59e552 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;