diff --git a/provider/schema-azure/pom.xml b/provider/schema-azure/pom.xml index f37de7e48c85c969b48f51539c46249e49516df9..c84c4e2fe369ecabfe653ebebe04c9d5a9ed89b7 100644 --- a/provider/schema-azure/pom.xml +++ b/provider/schema-azure/pom.xml @@ -40,7 +40,7 @@ org.opengroup.osdu core-lib-azure - 0.0.10 + 0.0.17 @@ -52,6 +52,12 @@ org.springframework.boot spring-boot-starter-test + + + org.springframework.boot + spring-boot-starter-logging + + test diff --git a/provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/definitions/TenantInfoDoc.java b/provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/definitions/TenantInfoDoc.java deleted file mode 100644 index 7b56d9784f1a0263892db72419b363aa788278ce..0000000000000000000000000000000000000000 --- a/provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/definitions/TenantInfoDoc.java +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright © Microsoft Corporation -// -// 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.schema.azure.definitions; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@AllArgsConstructor -@NoArgsConstructor -public class TenantInfoDoc { - private String id; - private String dataPartitionId; - private String complianceRuleSet; -} \ No newline at end of file diff --git a/provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/di/CosmosContainerConfig.java b/provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/di/CosmosContainerConfig.java index 517feb02965203a62cf28beb5a9f6b4a7264ba14..20ead530d1114892c7c9d95e1e9f603a6bdd7ddf 100644 --- a/provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/di/CosmosContainerConfig.java +++ b/provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/di/CosmosContainerConfig.java @@ -41,9 +41,6 @@ public class CosmosContainerConfig { @Value("${source.container.name}") private String sourceContainerName; - @Value("${tenant-info.container.name}") - private String tenantInfoContainerName; - @Bean public String authorityContainer() { return authorityContainerName; @@ -63,9 +60,4 @@ public class CosmosContainerConfig { public String sourceContainer() { return sourceContainerName; } - - @Bean - public String tenantInfoContainer() { - return tenantInfoContainerName; - } } \ No newline at end of file diff --git a/provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/di/TenantFactoryImpl.java b/provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/di/TenantFactoryImpl.java deleted file mode 100644 index 6a5c7b8d02246558a94af970b52a3121e1980589..0000000000000000000000000000000000000000 --- a/provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/di/TenantFactoryImpl.java +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright © Microsoft Corporation -// -// 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.schema.azure.di; - -import org.opengroup.osdu.azure.CosmosStore; -import org.opengroup.osdu.core.common.cache.ICache; -import org.opengroup.osdu.core.common.model.http.DpsHeaders; -import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; -import org.opengroup.osdu.core.common.model.tenant.TenantInfo; -import org.opengroup.osdu.schema.azure.definitions.TenantInfoDoc; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -@Component -public class TenantFactoryImpl implements ITenantFactory { - @Autowired - private String tenantInfoContainer; - - @Autowired - private CosmosStore cosmosStore; - - @Autowired - private String cosmosDBName; - - @Autowired - private DpsHeaders headers; - - private Map tenants; - - public boolean exists(String tenantName) - { - if (this.tenants == null) - initTenants(); - return this.tenants.containsKey(tenantName); - } - - public TenantInfo getTenantInfo(String tenantName) { - if (this.tenants == null) - initTenants(); - return this.tenants.get(tenantName); - } - - public Collection listTenantInfo() { - if (this.tenants == null) - initTenants(); - return this.tenants.values(); - } - - public ICache createCache(String tenantName, String host, int port, int expireTimeSeconds, Class classOfV) - { - return null; - } - - public void flushCache() {} - - private void initTenants() { - this.tenants = new HashMap<>(); - - cosmosStore.findAllItems( headers.getPartitionId(), cosmosDBName, tenantInfoContainer, TenantInfoDoc.class) - .forEach(doc -> { - TenantInfo ti = new TenantInfo(); - String tenantName = doc.getId(); - ti.setName(tenantName); - String complianceRuleSet = doc.getComplianceRuleSet(); - ti.setComplianceRuleSet(complianceRuleSet); - this.tenants.put(tenantName, ti) ; - }); - } -} - diff --git a/provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/impl/schemainfostore/AzureSchemaInfoStore.java b/provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/impl/schemainfostore/AzureSchemaInfoStore.java index ce594838b3ca307b381f20e68044afa227f9b261..f4f441b9c2b9e46b571d5a2c061646198e675f10 100644 --- a/provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/impl/schemainfostore/AzureSchemaInfoStore.java +++ b/provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/impl/schemainfostore/AzureSchemaInfoStore.java @@ -174,7 +174,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore { @Override public String getLatestMinorVerSchema(SchemaInfo schemaInfo) throws ApplicationException { - SqlQuerySpec query = new SqlQuerySpec("SELECT * FROM c WHERE STARTSWITH(c.id, @partitionId)" + + SqlQuerySpec query = new SqlQuerySpec("SELECT * FROM c WHERE c.dataPartitionId = @partitionId" + " AND c.flattenedSchemaInfo.authority = @authority" + " AND c.flattenedSchemaInfo.source = @source" + " AND c.flattenedSchemaInfo.entityType = @entityType" + @@ -272,7 +272,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore { @Override public List getSchemaInfoList(QueryParams queryParams, String tenantId) throws ApplicationException { - String queryText = "SELECT * FROM c WHERE STARTSWITH(c.id, @partitionId)"; + String queryText = "SELECT * FROM c WHERE c.dataPartitionId = @partitionId"; HashMap parameterMap = new HashMap<>(); // Populate the implicit partitionId parameter parameterMap.put("@partitionId", tenantId); diff --git a/provider/schema-azure/src/main/resources/application.properties b/provider/schema-azure/src/main/resources/application.properties index 1ce0d92b887f3978ad5b061deb796d3eab79908e..c5cccadee936e4b76b9ba0f7994b5c81b6717ee3 100644 --- a/provider/schema-azure/src/main/resources/application.properties +++ b/provider/schema-azure/src/main/resources/application.properties @@ -13,6 +13,7 @@ # limitations under the License. LOG_PREFIX=schema +server.servlet.context-path=/api/schema-service/v1 AUTHORIZE_API=${entitlements_service_endpoint} AUTHORIZE_API_KEY=${entitlements_service_api_key} @@ -41,5 +42,5 @@ authority.container.name=Authority entity-type.container.name=EntityType schema-info.container.name=SchemaInfo source.container.name=Source -tenant-info.container.name=TenantInfo +tenantInfo.container.name=TenantInfo server.port=8080 diff --git a/provider/schema-azure/src/test/java/org/opengroup/osdu/schema/provider/azure/impl/schemainfostore/AzureSchemaInfoStoreTest.java b/provider/schema-azure/src/test/java/org/opengroup/osdu/schema/provider/azure/impl/schemainfostore/AzureSchemaInfoStoreTest.java index 86a5e0d90064c0b8ecf4418eaef406a7375d93ef..036d8ca37334c5bc47efce6b7687b7ca67100384 100644 --- a/provider/schema-azure/src/test/java/org/opengroup/osdu/schema/provider/azure/impl/schemainfostore/AzureSchemaInfoStoreTest.java +++ b/provider/schema-azure/src/test/java/org/opengroup/osdu/schema/provider/azure/impl/schemainfostore/AzureSchemaInfoStoreTest.java @@ -20,6 +20,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; @@ -48,6 +49,8 @@ import java.io.IOException; import java.util.*; import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import static org.mockito.MockitoAnnotations.initMocks; @@ -124,7 +127,6 @@ public class AzureSchemaInfoStoreTest { Mockito.when(schemaStore.getSchema(dataPartitionId, schemaId)).thenReturn(CONTENT); assertEquals(CONTENT, schemaInfoStore.getLatestMinorVerSchema(getMockSchemaInfo())); - } @Test diff --git a/testing/schema-test-core/pom.xml b/testing/schema-test-core/pom.xml index 36c348ab720d5797baa417e4ecaec6acfc0e181d..ed28aa90c49a6a0d54f996811115e411cbb32fdf 100644 --- a/testing/schema-test-core/pom.xml +++ b/testing/schema-test-core/pom.xml @@ -15,6 +15,18 @@ org.opengroup.osdu os-schema-core + + + ch.qos.logback + logback-classic + + + org.apache.logging.log4j + log4j-to-slf4j + + + + 0.0.1 @@ -59,6 +71,11 @@ 1.76.0 + + org.opengroup.osdu + core-lib-azure + 0.0.17 + diff --git a/testing/schema-test-core/src/test/java/org/opengroup/osdu/schema/util/AuthUtil.java b/testing/schema-test-core/src/test/java/org/opengroup/osdu/schema/util/AuthUtil.java index f7af9737a31c0eb9aea137c001fb9dc9cf45a078..6af4a60c28badc4790370b869fd24f0dc466aeec 100644 --- a/testing/schema-test-core/src/test/java/org/opengroup/osdu/schema/util/AuthUtil.java +++ b/testing/schema-test-core/src/test/java/org/opengroup/osdu/schema/util/AuthUtil.java @@ -1,23 +1,28 @@ package org.opengroup.osdu.schema.util; import com.google.common.base.Strings; +import org.opengroup.osdu.azure.util.AzureServicePrincipal; public class AuthUtil { - public synchronized String getToken() throws Exception { + public synchronized String getToken() throws Exception { String token = null; String vendor = System.getProperty("VENDOR", System.getenv("VENDOR")); if (Strings.isNullOrEmpty(token) && vendor.equals("gcp")) { - String serviceAccountFile = System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER")); + String serviceAccountFile = System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER")); String audience = System.getProperty("INTEGRATION_TEST_AUDIENCE", System.getenv("INTEGRATION_TEST_AUDIENCE")); token = new GoogleServiceAccount(serviceAccountFile).getAuthToken(audience); }else if (Strings.isNullOrEmpty(token) && vendor.equals("aws")) { - System.out.println("Token generation code for aws comes here"); - } else if (Strings.isNullOrEmpty(token) && vendor.equals("azure")) { - System.out.println("Token generation code for azure comes here"); - } else if (Strings.isNullOrEmpty(token) && vendor.equals("ibm")) { - System.out.println("Token generation code for ibm comes here"); - } + System.out.println("Token generation code for aws comes here"); + } else if (Strings.isNullOrEmpty(token) && vendor.equals("azure")) { + String sp_id = System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER")); + String sp_secret = System.getProperty("TESTER_SERVICEPRINCIPAL_SECRET", System.getenv("TESTER_SERVICEPRINCIPAL_SECRET")); + String tenant_id = System.getProperty("AZURE_AD_TENANT_ID", System.getenv("AZURE_AD_TENANT_ID")); + String app_resource_id = System.getProperty("AZURE_AD_APP_RESOURCE_ID", System.getenv("AZURE_AD_APP_RESOURCE_ID")); + token = new AzureServicePrincipal().getIdToken(sp_id, sp_secret, tenant_id, app_resource_id); + } else if (Strings.isNullOrEmpty(token) && vendor.equals("ibm")) { + System.out.println("Token generation code for ibm comes here"); + } System.out.println("Bearer " + token); return "Bearer " + token; }