From be2e4394f67dec400b3920ddc9fcd6fb699c86b6 Mon Sep 17 00:00:00 2001 From: Aman Verma Date: Thu, 6 Aug 2020 15:44:50 +0530 Subject: [PATCH 1/7] adding logic to generate auth token for azure --- .../schemainfostore/AzureSchemaInfoStore.java | 4 +- .../src/main/resources/application.properties | 1 + .../opengroup/osdu/schema/util/AuthUtil.java | 20 +++--- .../schema/util/AzureServicePrincipal.java | 69 +++++++++++++++++++ 4 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 testing/schema-test-core/src/test/java/org/opengroup/osdu/schema/util/AzureServicePrincipal.java 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 ce594838..e74f42d4 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 @@ -187,7 +187,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore { pars.add(new SqlParameter("@majorVersion", schemaInfo.getSchemaIdentity().getSchemaVersionMajor())); FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(false); + options.setEnableCrossPartitionQuery(true); List schemaInfoList = cosmosStore.queryItems(headers.getPartitionId(), cosmosDBName,schemaInfoContainer, query, options, SchemaInfoDoc.class); TreeMap sortedMap = new TreeMap<>(Collections.reverseOrder()); @@ -316,7 +316,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore { } FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(false); + options.setEnableCrossPartitionQuery(true); List schemaInfoList = cosmosStore.queryItems(headers.getPartitionId(), cosmosDBName,schemaInfoContainer, query, options, SchemaInfoDoc.class); List schemaList = new LinkedList<>(); diff --git a/provider/schema-azure/src/main/resources/application.properties b/provider/schema-azure/src/main/resources/application.properties index 1ce0d92b..fba93330 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} 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 f7af9737..3434e1dc 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 @@ -3,21 +3,25 @@ package org.opengroup.osdu.schema.util; import com.google.common.base.Strings; 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 = 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; } diff --git a/testing/schema-test-core/src/test/java/org/opengroup/osdu/schema/util/AzureServicePrincipal.java b/testing/schema-test-core/src/test/java/org/opengroup/osdu/schema/util/AzureServicePrincipal.java new file mode 100644 index 00000000..cc341b86 --- /dev/null +++ b/testing/schema-test-core/src/test/java/org/opengroup/osdu/schema/util/AzureServicePrincipal.java @@ -0,0 +1,69 @@ +package org.opengroup.osdu.schema.util; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.util.HashMap; +import java.util.Map; + +public class AzureServicePrincipal { + public static String getIdToken(String sp_id, String sp_secret, String tenant_id, String app_resource_id) throws Exception { + String aad_endpoint = String.format("https://login.microsoftonline.com/%s/oauth2/token", tenant_id); + URL url = new URL(aad_endpoint); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("POST"); + con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + + Map parameters = new HashMap<>(); + parameters.put("grant_type", "client_credentials"); + parameters.put("client_id", sp_id); + parameters.put("client_secret", sp_secret); + parameters.put("resource", app_resource_id); + + con.setDoOutput(true); + DataOutputStream out = new DataOutputStream(con.getOutputStream()); + out.writeBytes(getParamsString(parameters)); + out.flush(); + out.close(); + + BufferedReader in = new BufferedReader( + new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer content = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + + con.disconnect(); + + Gson gson = new Gson(); + JsonObject jobj = gson.fromJson(content.toString(), JsonObject.class); + String token = jobj.get("access_token").getAsString(); + return token; + } + + private static String getParamsString(Map params) + throws UnsupportedEncodingException { + StringBuilder result = new StringBuilder(); + + for (Map.Entry entry : params.entrySet()) { + result.append(URLEncoder.encode(entry.getKey(), "UTF-8")); + result.append("="); + result.append(URLEncoder.encode(entry.getValue(), "UTF-8")); + result.append("&"); + } + + String resultString = result.toString(); + return resultString.length() > 0 + ? resultString.substring(0, resultString.length() - 1) + : resultString; + } +} -- GitLab From a259e6554ccc6e102e85fd2fdfd30d1273fb2918 Mon Sep 17 00:00:00 2001 From: Aman Verma Date: Thu, 6 Aug 2020 16:29:57 +0530 Subject: [PATCH 2/7] adding UTs for feed opetion change --- .../AzureSchemaInfoStoreTest.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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 86a5e0d9..41c8de91 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; @@ -112,6 +115,9 @@ public class AzureSchemaInfoStoreTest { any(), any()); assertEquals("", schemaInfoStore.getLatestMinorVerSchema(getMockSchemaInfo())); + ArgumentCaptor feedOptions = ArgumentCaptor.forClass(FeedOptions.class); + verify(cosmosStore).queryItems(eq(dataPartitionId), any(), any(), any(), feedOptions.capture(), any()); + assertTrue(feedOptions.getValue().getEnableCrossPartitionQuery()); } @Test @@ -124,7 +130,9 @@ public class AzureSchemaInfoStoreTest { Mockito.when(schemaStore.getSchema(dataPartitionId, schemaId)).thenReturn(CONTENT); assertEquals(CONTENT, schemaInfoStore.getLatestMinorVerSchema(getMockSchemaInfo())); - + ArgumentCaptor feedOptions = ArgumentCaptor.forClass(FeedOptions.class); + verify(cosmosStore).queryItems(eq(dataPartitionId), any(), any(), any(), feedOptions.capture(), any()); + assertTrue(feedOptions.getValue().getEnableCrossPartitionQuery()); } @Test @@ -445,6 +453,9 @@ public class AzureSchemaInfoStoreTest { assertEquals(1, schemaInfoStore.getSchemaInfoList(QueryParams.builder().limit(100).offset(0).build(), dataPartitionId).size()); + ArgumentCaptor feedOptions = ArgumentCaptor.forClass(FeedOptions.class); + verify(cosmosStore).queryItems(eq(dataPartitionId), any(), any(), any(), feedOptions.capture(), any()); + assertTrue(feedOptions.getValue().getEnableCrossPartitionQuery()); } @Test @@ -457,6 +468,9 @@ public class AzureSchemaInfoStoreTest { schemaInfoStore.getSchemaInfoList(QueryParams.builder().authority("test").source("test").entityType("test") .schemaVersionMajor(1l).schemaVersionMinor(1l).scope("test").status("test").latestVersion(false) .limit(100).offset(0).build(), "test").size()); + ArgumentCaptor feedOptions = ArgumentCaptor.forClass(FeedOptions.class); + verify(cosmosStore).queryItems(eq(dataPartitionId), any(), any(), any(), feedOptions.capture(), any()); + assertTrue(feedOptions.getValue().getEnableCrossPartitionQuery()); } @Test @@ -469,6 +483,9 @@ public class AzureSchemaInfoStoreTest { .getSchemaInfoList(QueryParams.builder().authority("test").source("test").entityType("test") .scope("test").status("test").latestVersion(true).limit(100).offset(0).build(), "test") .size()); + ArgumentCaptor feedOptions = ArgumentCaptor.forClass(FeedOptions.class); + verify(cosmosStore).queryItems(eq(dataPartitionId), any(), any(), any(), feedOptions.capture(), any()); + assertTrue(feedOptions.getValue().getEnableCrossPartitionQuery()); } @Test -- GitLab From 4a49a04cfa1edb31ac7c85908c7964e109266ede Mon Sep 17 00:00:00 2001 From: Aman Verma Date: Thu, 6 Aug 2020 17:25:49 +0530 Subject: [PATCH 3/7] adding azure-core-lib to pom.xml --- provider/schema-azure/pom.xml | 9 ++++++++- testing/schema-test-core/pom.xml | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/provider/schema-azure/pom.xml b/provider/schema-azure/pom.xml index f37de7e4..4922a40a 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,13 @@ org.springframework.boot spring-boot-starter-test + + + org.springframework.boot + spring-boot-starter-logging + + + test diff --git a/testing/schema-test-core/pom.xml b/testing/schema-test-core/pom.xml index 36c348ab..26659b60 100644 --- a/testing/schema-test-core/pom.xml +++ b/testing/schema-test-core/pom.xml @@ -59,6 +59,12 @@ 1.76.0 + + org.opengroup.osdu + core-lib-azure + 0.0.17 + + -- GitLab From dc6e8f7e124e36bf09acc0f7fcac49c9c2c6a137 Mon Sep 17 00:00:00 2001 From: Aman Verma Date: Thu, 6 Aug 2020 20:58:49 +0530 Subject: [PATCH 4/7] comsuming the modules from azure-core-lib --- provider/schema-azure/pom.xml | 1 - .../azure/definitions/TenantInfoDoc.java | 28 ------ .../azure/di/CosmosContainerConfig.java | 8 -- .../schema/azure/di/TenantFactoryImpl.java | 86 ------------------- .../src/main/resources/application.properties | 2 +- testing/schema-test-core/pom.xml | 23 +++++ .../opengroup/osdu/schema/util/AuthUtil.java | 3 +- .../schema/util/AzureServicePrincipal.java | 69 --------------- 8 files changed, 26 insertions(+), 194 deletions(-) delete mode 100644 provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/definitions/TenantInfoDoc.java delete mode 100644 provider/schema-azure/src/main/java/org/opengroup/osdu/schema/azure/di/TenantFactoryImpl.java delete mode 100644 testing/schema-test-core/src/test/java/org/opengroup/osdu/schema/util/AzureServicePrincipal.java diff --git a/provider/schema-azure/pom.xml b/provider/schema-azure/pom.xml index 4922a40a..c84c4e2f 100644 --- a/provider/schema-azure/pom.xml +++ b/provider/schema-azure/pom.xml @@ -58,7 +58,6 @@ 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 7b56d978..00000000 --- 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 517feb02..20ead530 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 6a5c7b8d..00000000 --- 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/resources/application.properties b/provider/schema-azure/src/main/resources/application.properties index fba93330..c5cccade 100644 --- a/provider/schema-azure/src/main/resources/application.properties +++ b/provider/schema-azure/src/main/resources/application.properties @@ -42,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/testing/schema-test-core/pom.xml b/testing/schema-test-core/pom.xml index 26659b60..3a5fe04c 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 @@ -62,6 +74,17 @@ org.opengroup.osdu core-lib-azure + + + ch.qos.logback + logback-classic + + + org.apache.logging.log4j + log4j-to-slf4j + + + 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 3434e1dc..6af4a60c 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,6 +1,7 @@ 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 { @@ -18,7 +19,7 @@ public class AuthUtil { 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 = AzureServicePrincipal.getIdToken(sp_id, sp_secret, tenant_id, 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"); } diff --git a/testing/schema-test-core/src/test/java/org/opengroup/osdu/schema/util/AzureServicePrincipal.java b/testing/schema-test-core/src/test/java/org/opengroup/osdu/schema/util/AzureServicePrincipal.java deleted file mode 100644 index cc341b86..00000000 --- a/testing/schema-test-core/src/test/java/org/opengroup/osdu/schema/util/AzureServicePrincipal.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.opengroup.osdu.schema.util; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLEncoder; -import java.util.HashMap; -import java.util.Map; - -public class AzureServicePrincipal { - public static String getIdToken(String sp_id, String sp_secret, String tenant_id, String app_resource_id) throws Exception { - String aad_endpoint = String.format("https://login.microsoftonline.com/%s/oauth2/token", tenant_id); - URL url = new URL(aad_endpoint); - HttpURLConnection con = (HttpURLConnection) url.openConnection(); - con.setRequestMethod("POST"); - con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - - Map parameters = new HashMap<>(); - parameters.put("grant_type", "client_credentials"); - parameters.put("client_id", sp_id); - parameters.put("client_secret", sp_secret); - parameters.put("resource", app_resource_id); - - con.setDoOutput(true); - DataOutputStream out = new DataOutputStream(con.getOutputStream()); - out.writeBytes(getParamsString(parameters)); - out.flush(); - out.close(); - - BufferedReader in = new BufferedReader( - new InputStreamReader(con.getInputStream())); - String inputLine; - StringBuffer content = new StringBuffer(); - while ((inputLine = in.readLine()) != null) { - content.append(inputLine); - } - in.close(); - - con.disconnect(); - - Gson gson = new Gson(); - JsonObject jobj = gson.fromJson(content.toString(), JsonObject.class); - String token = jobj.get("access_token").getAsString(); - return token; - } - - private static String getParamsString(Map params) - throws UnsupportedEncodingException { - StringBuilder result = new StringBuilder(); - - for (Map.Entry entry : params.entrySet()) { - result.append(URLEncoder.encode(entry.getKey(), "UTF-8")); - result.append("="); - result.append(URLEncoder.encode(entry.getValue(), "UTF-8")); - result.append("&"); - } - - String resultString = result.toString(); - return resultString.length() > 0 - ? resultString.substring(0, resultString.length() - 1) - : resultString; - } -} -- GitLab From 50251c015220f8ee94a2be6af2b28e0e6eb93db5 Mon Sep 17 00:00:00 2001 From: Aman Verma Date: Fri, 7 Aug 2020 13:13:07 +0530 Subject: [PATCH 5/7] setting cross partition query to false --- .../schemainfostore/AzureSchemaInfoStore.java | 8 ++++---- .../schemainfostore/AzureSchemaInfoStoreTest.java | 15 --------------- 2 files changed, 4 insertions(+), 19 deletions(-) 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 e74f42d4..f4f441b9 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" + @@ -187,7 +187,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore { pars.add(new SqlParameter("@majorVersion", schemaInfo.getSchemaIdentity().getSchemaVersionMajor())); FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); + options.setEnableCrossPartitionQuery(false); List schemaInfoList = cosmosStore.queryItems(headers.getPartitionId(), cosmosDBName,schemaInfoContainer, query, options, SchemaInfoDoc.class); TreeMap sortedMap = new TreeMap<>(Collections.reverseOrder()); @@ -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); @@ -316,7 +316,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore { } FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); + options.setEnableCrossPartitionQuery(false); List schemaInfoList = cosmosStore.queryItems(headers.getPartitionId(), cosmosDBName,schemaInfoContainer, query, options, SchemaInfoDoc.class); List schemaList = new LinkedList<>(); 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 41c8de91..036d8ca3 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 @@ -115,9 +115,6 @@ public class AzureSchemaInfoStoreTest { any(), any()); assertEquals("", schemaInfoStore.getLatestMinorVerSchema(getMockSchemaInfo())); - ArgumentCaptor feedOptions = ArgumentCaptor.forClass(FeedOptions.class); - verify(cosmosStore).queryItems(eq(dataPartitionId), any(), any(), any(), feedOptions.capture(), any()); - assertTrue(feedOptions.getValue().getEnableCrossPartitionQuery()); } @Test @@ -130,9 +127,6 @@ public class AzureSchemaInfoStoreTest { Mockito.when(schemaStore.getSchema(dataPartitionId, schemaId)).thenReturn(CONTENT); assertEquals(CONTENT, schemaInfoStore.getLatestMinorVerSchema(getMockSchemaInfo())); - ArgumentCaptor feedOptions = ArgumentCaptor.forClass(FeedOptions.class); - verify(cosmosStore).queryItems(eq(dataPartitionId), any(), any(), any(), feedOptions.capture(), any()); - assertTrue(feedOptions.getValue().getEnableCrossPartitionQuery()); } @Test @@ -453,9 +447,6 @@ public class AzureSchemaInfoStoreTest { assertEquals(1, schemaInfoStore.getSchemaInfoList(QueryParams.builder().limit(100).offset(0).build(), dataPartitionId).size()); - ArgumentCaptor feedOptions = ArgumentCaptor.forClass(FeedOptions.class); - verify(cosmosStore).queryItems(eq(dataPartitionId), any(), any(), any(), feedOptions.capture(), any()); - assertTrue(feedOptions.getValue().getEnableCrossPartitionQuery()); } @Test @@ -468,9 +459,6 @@ public class AzureSchemaInfoStoreTest { schemaInfoStore.getSchemaInfoList(QueryParams.builder().authority("test").source("test").entityType("test") .schemaVersionMajor(1l).schemaVersionMinor(1l).scope("test").status("test").latestVersion(false) .limit(100).offset(0).build(), "test").size()); - ArgumentCaptor feedOptions = ArgumentCaptor.forClass(FeedOptions.class); - verify(cosmosStore).queryItems(eq(dataPartitionId), any(), any(), any(), feedOptions.capture(), any()); - assertTrue(feedOptions.getValue().getEnableCrossPartitionQuery()); } @Test @@ -483,9 +471,6 @@ public class AzureSchemaInfoStoreTest { .getSchemaInfoList(QueryParams.builder().authority("test").source("test").entityType("test") .scope("test").status("test").latestVersion(true).limit(100).offset(0).build(), "test") .size()); - ArgumentCaptor feedOptions = ArgumentCaptor.forClass(FeedOptions.class); - verify(cosmosStore).queryItems(eq(dataPartitionId), any(), any(), any(), feedOptions.capture(), any()); - assertTrue(feedOptions.getValue().getEnableCrossPartitionQuery()); } @Test -- GitLab From d17eff3608ba40fc7bdbbb3d612f96a54c3751e2 Mon Sep 17 00:00:00 2001 From: Aman Verma Date: Fri, 7 Aug 2020 15:20:21 +0530 Subject: [PATCH 6/7] removing redundant exclusion --- testing/schema-test-core/pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/testing/schema-test-core/pom.xml b/testing/schema-test-core/pom.xml index 3a5fe04c..534fe1e6 100644 --- a/testing/schema-test-core/pom.xml +++ b/testing/schema-test-core/pom.xml @@ -75,19 +75,13 @@ org.opengroup.osdu core-lib-azure - - ch.qos.logback - logback-classic - org.apache.logging.log4j log4j-to-slf4j - 0.0.17 - -- GitLab From 90f904454f6a014efa4c2e2d781fbbc7c2612dca Mon Sep 17 00:00:00 2001 From: Aman Verma Date: Fri, 7 Aug 2020 15:57:19 +0530 Subject: [PATCH 7/7] updating pom.xml --- testing/schema-test-core/pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/testing/schema-test-core/pom.xml b/testing/schema-test-core/pom.xml index 534fe1e6..ed28aa90 100644 --- a/testing/schema-test-core/pom.xml +++ b/testing/schema-test-core/pom.xml @@ -74,12 +74,6 @@ org.opengroup.osdu core-lib-azure - - - org.apache.logging.log4j - log4j-to-slf4j - - 0.0.17 -- GitLab