Commit 78eaa3cc authored by Alok Joshi's avatar Alok Joshi
Browse files

review comment changes

parent 6c6d8c66
Pipeline #36307 failed with stages
in 35 minutes and 21 seconds
......@@ -23,7 +23,8 @@ Here are steps to enable Policy service for a provider:
- Add and provide values for following runtime configuration in `application.properties`
```
service.policy.enabled=true
POLICY_API=${policy_service_endpoint}
service.policy.endpoint=${policy_service_endpoint}
policy.cache.timeout=<timeout_in_minutes>
PARTITION_API=${partition_service_endpoint}
```
......
......@@ -68,7 +68,7 @@ server.ssl.key-store-password=${SSL_KEY_STORE_PASSWORD:}
# Policy service properties
service.policy.enabled=false
POLICY_API=${ENTITLEMENTS_BASE_URL}/api/policy/v1
POLICY_ID=search
service.policy.endpoint=${ENTITLEMENTS_BASE_URL}/api/policy/v1
service.policy.id=search
PARTITION_API=${ENTITLEMENTS_BASE_URL}/api/partition/v1
aws.environment=${ENVIRONMENT}
\ No newline at end of file
......@@ -78,4 +78,6 @@ management.health.azure-key-vault.enabled=false
# Policy service properties
service.policy.enabled=${policy_enabled}
POLICY_API=${policy_service_endpoint}
\ No newline at end of file
service.policy.endpoint=${policy_service_endpoint}
policy.cache.timeout=5
service.policy.id=search
\ No newline at end of file
......@@ -14,22 +14,28 @@
package org.opengroup.osdu.search.policy.di;
import lombok.Getter;
import lombok.Setter;
import org.opengroup.osdu.core.common.partition.IPartitionFactory;
import org.opengroup.osdu.core.common.partition.PartitionAPIConfig;
import org.opengroup.osdu.core.common.partition.PartitionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
@Component
@Primary
@Configuration
@ConfigurationProperties
@Getter
@Setter
@ConditionalOnProperty(value = "service.policy.enabled", havingValue = "true", matchIfMissing = false)
public class PartitionClientFactory extends AbstractFactoryBean<IPartitionFactory> {
@Value("${PARTITION_API}")
private String partitionAPIEndpoint;
private String PARTITION_API;
@Override
public Class<?> getObjectType() {
......@@ -39,7 +45,7 @@ public class PartitionClientFactory extends AbstractFactoryBean<IPartitionFactor
@Override
protected IPartitionFactory createInstance() throws Exception {
PartitionAPIConfig apiConfig = PartitionAPIConfig.builder()
.rootUrl(partitionAPIEndpoint)
.rootUrl(PARTITION_API)
.build();
return new PartitionFactory(apiConfig);
}
......
......@@ -15,7 +15,8 @@
package org.opengroup.osdu.search.policy.di;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
......@@ -23,16 +24,17 @@ import org.springframework.context.annotation.Lazy;
import javax.inject.Named;
@Configuration
@ConfigurationProperties(prefix = "policy.cache")
@Getter
@Setter
@Lazy
public class PolicyCacheConfiguration {
@Value("${policy.cache.timeout:5}")
private int cacheTimeOut;
private int timeout;
@Bean
@Named("POLICY_CACHE_TIMEOUT")
public int getPolicyCacheTimeout() {
return cacheTimeOut;
return timeout;
}
}
......@@ -41,7 +41,7 @@ public class PolicyClientFactory extends AbstractFactoryBean<IPolicyFactory> {
@Override
protected IPolicyFactory createInstance() throws Exception {
PolicyAPIConfig apiConfig = PolicyAPIConfig.builder()
.rootUrl(serviceConfiguration.getPolicyApiEndpoint())
.rootUrl(serviceConfiguration.getEndpoint())
.build();
return new PolicyFactory(apiConfig, httpResponseBodyMapper);
}
......
......@@ -15,18 +15,18 @@
package org.opengroup.osdu.search.policy.di;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import lombok.Setter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConfigurationProperties(prefix = "service.policy")
@Getter
@Setter
@ConditionalOnProperty(value = "service.policy.enabled", havingValue = "true", matchIfMissing = false)
public class PolicyServiceConfiguration {
@Value("${POLICY_ID:search}")
private String policyId;
@Value("${POLICY_API}")
private String policyApiEndpoint;
private String id;
private String endpoint;
}
......@@ -89,7 +89,7 @@ public class PolicyServiceImpl implements IPolicyService{
searchPolicy.setRecords(records);
PolicyRequest policy = new PolicyRequest();
policy.setPolicyId(this.policyServiceConfiguration.getPolicyId());
policy.setPolicyId(this.policyServiceConfiguration.getId());
policy.setInput(new JsonParser().parse(new Gson().toJson(searchPolicy)).getAsJsonObject());
return policy;
}
......
......@@ -82,7 +82,7 @@ public class PolicyServiceImplTest {
Mockito.when(serviceClient.evaluateBatchPolicy(any())).thenReturn(batchPolicyResponse);
Groups groups = new Groups();
Mockito.when(entitlementsService.getGroups(any())).thenReturn(groups);
Mockito.when(policyServiceConfiguration.getPolicyId()).thenReturn("search");
Mockito.when(policyServiceConfiguration.getId()).thenReturn("search");
List<String> result = sut.evaluateSearchDataAuthorizationPolicy(recordMetadataList, OperationType.view);
Assert.assertEquals(1, result.size());
Assert.assertEquals("id:123", result.get(0));
......
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