Commit 7605c303 authored by Daniel Scholl's avatar Daniel Scholl
Browse files

Merge branch 'master' into schema_load

* master:
  Azure: fixing azure pom
  Reverting gitlab-ci yaml
  CORS fix
  Updating notice
  cherry picked upgrading core common
  ibm partition check added
  Update .gitlab-ci.yml
  Update .gitlab-ci.yml
  Update .gitlab-ci.yml
parents 83775050 b17ef0a0
......@@ -30,7 +30,7 @@
<properties>
<osdu.corelibazure.version>0.0.40</osdu.corelibazure.version>
<osdu.oscorecommon.version>0.3.18</osdu.oscorecommon.version>
<osdu.oscorecommon.version>0.3.28</osdu.oscorecommon.version>
<osdu.os-schema-core.version>0.6.0-SNAPSHOT</osdu.os-schema-core.version>
<mockito.version>1.10.19</mockito.version>
<cucumber.version>5.4.0</cucumber.version>
......@@ -45,6 +45,12 @@
<version>${osdu.corelibazure.version}</version>
<type>pom</type>
<scope>import</scope>
<exclusions>
<exclusion>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
......@@ -63,14 +69,14 @@
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<version>${osdu.corelibazure.version}</version>
<artifactId>os-core-common</artifactId>
<version>${osdu.oscorecommon.version}</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>${osdu.oscorecommon.version}</version>
<artifactId>core-lib-azure</artifactId>
<version>${osdu.corelibazure.version}</version>
</dependency>
<dependency>
......
......@@ -12,7 +12,7 @@
<properties>
<start-class>org.opengroup.osdu.schema.provider.ibm.app.SchemaIBMApplication</start-class>
<os-core-lib-ibm.version>0.3.8-SNAPSHOT</os-core-lib-ibm.version>
<os-core-lib-ibm.version>0.3.23-SNAPSHOT</os-core-lib-ibm.version>
</properties>
......
......@@ -28,6 +28,7 @@ import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
import org.opengroup.osdu.schema.exceptions.BadRequestException;
import org.opengroup.osdu.schema.exceptions.NotFoundException;
import org.opengroup.osdu.schema.exceptions.UnauthorizedException;
import org.opengroup.osdu.schema.impl.schemainfostore.util.IbmDocumentStore;
import org.opengroup.osdu.schema.model.QueryParams;
import org.opengroup.osdu.schema.model.SchemaIdentity;
......@@ -68,6 +69,9 @@ public class IbmSchemaInfoStore extends IbmDocumentStore implements ISchemaInfoS
@Inject
private TenantFactory tenantFactory;
@Inject
private TenantInfo tenant;
@Autowired
private ISchemaStore schemaStore;
......@@ -83,6 +87,11 @@ public class IbmSchemaInfoStore extends IbmDocumentStore implements ISchemaInfoS
@Override
public boolean isUnique(String schemaId, String tenantId) throws ApplicationException {
try {
tenant.getName();
} catch (Exception e) {
throw new UnauthorizedException("Unauthorized");
}
Set<String> tenantList = new HashSet<>();
tenantList.add(sharedTenant);
tenantList.add(tenantId);
......@@ -120,6 +129,11 @@ public class IbmSchemaInfoStore extends IbmDocumentStore implements ISchemaInfoS
*/
@Override
public SchemaInfo getSchemaInfo(String schemaId) throws ApplicationException, NotFoundException {
try {
tenant.getName();
} catch (Exception e) {
throw new UnauthorizedException("Unauthorized");
}
if (db.contains(schemaId)) {
SchemaDoc sd = db.find(SchemaDoc.class, schemaId);
return sd.getSchemaInfo();
......@@ -259,7 +273,12 @@ public class IbmSchemaInfoStore extends IbmDocumentStore implements ISchemaInfoS
@Override
public List<SchemaInfo> getSchemaInfoList(QueryParams queryParams, String tenantId) throws ApplicationException {
try {
tenant.getName();
} catch (Exception e) {
throw new UnauthorizedException("Unauthorized");
}
long numRecords = LIMIT_SIZE;
if (Long.valueOf(queryParams.getLimit()) != null) {
numRecords = Long.valueOf(queryParams.getLimit());
......
......@@ -21,6 +21,8 @@ import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Repository;
import org.springframework.web.context.annotation.RequestScope;
import org.opengroup.osdu.schema.exceptions.UnauthorizedException;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import com.ibm.cloud.objectstorage.services.s3.AmazonS3;
import com.ibm.cloud.objectstorage.services.s3.model.AmazonS3Exception;
import com.ibm.cloud.objectstorage.services.s3.model.ObjectMetadata;
......@@ -43,6 +45,9 @@ public class IBMSchemaStore implements ISchemaStore {
@Inject
private JaxRsDpsLog logger;
@Inject
private TenantInfo tenant;
AmazonS3 s3Client;
......@@ -67,6 +72,12 @@ public class IBMSchemaStore implements ISchemaStore {
// dataPartitionId not used b/c getting from header
String content = null;
try {
tenant.getName();
} catch (Exception e) {
throw new UnauthorizedException("Unauthorized");
}
try {
content = getObjectAsString(schemaId);
} catch (AmazonS3Exception s3Exp) {
......
......@@ -94,6 +94,9 @@ public class IbmSchemaInfoStoreTest {
@Mock
IBMSchemaStore schemaStore;
@Mock
TenantInfo tenant;
@Rule
public ExpectedException expectedException = ExpectedException.none();
......@@ -424,9 +427,11 @@ public class IbmSchemaInfoStoreTest {
List<SchemaDoc> schemaDocsList = new LinkedList<>();
schemaDocsList.add(schemaDoc);
schemaDocsList.add(latestSchemaDoc);
Mockito.when(headers.getPartitionIdWithFallbackToAccountId()).thenReturn(dataPartitionId);
Mockito.when(cloudantFactory.getDatabase(any(),anyString())).thenReturn(db);
Mockito.when(db.query(Mockito.any(),Mockito.any())).thenReturn(queryResult);
Mockito.when(queryResult.getDocs()).thenReturn(schemaDocsList);
Mockito.when(tenant.getName()).thenReturn(dataPartitionId);
assertEquals(2, schemaInfoStore.getSchemaInfoList(
QueryParams.builder().scope("test").status("test").latestVersion(true).limit(100).offset(0).build(),
......
......@@ -15,7 +15,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.ibm.objectstorage.CloudObjectStorageFactory;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
......@@ -36,6 +36,9 @@ public class IBMSchemaStoreTest {
@Mock
DpsHeaders headers;
@Mock
TenantInfo tenant;
@Mock
CloudObjectStorageFactory cosFactory;
......@@ -88,6 +91,7 @@ public class IBMSchemaStoreTest {
Mockito.when(cosFactory.getClient()).thenReturn(s3Client);
Mockito.when(cosFactory.getBucketName(dataPartitionId, BUCKET)).thenReturn(bucketName);
Mockito.when(s3Client.getObjectAsString(bucketName, SCHEMA_ID)).thenReturn(CONTENT);
Mockito.when(tenant.getName()).thenReturn(dataPartitionId);
Assert.assertEquals(CONTENT, schemaStore.getSchema(dataPartitionId, SCHEMA_ID));
}
......
......@@ -13,7 +13,7 @@
<properties>
<springfox-version>2.7.0</springfox-version>
<os-core-common.version>0.3.23</os-core-common.version>
<os-core-common.version>0.3.28</os-core-common.version>
</properties>
<dependencies>
......
......@@ -27,9 +27,10 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.http.ResponseHeaders;
import org.opengroup.osdu.core.common.http.ResponseHeadersFactory;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
......@@ -40,6 +41,12 @@ public class ResponseHeaderFIlter implements Filter {
@Autowired
private DpsHeaders dpsHeaders;
// defaults to * for any front-end, string must be comma-delimited if more than one domain
@Value("${ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS:*}")
String ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS;
private ResponseHeadersFactory responseHeadersFactory = new ResponseHeadersFactory();
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
......@@ -49,8 +56,8 @@ public class ResponseHeaderFIlter implements Filter {
HttpServletResponse httpResponse = (HttpServletResponse) response;
this.dpsHeaders.addCorrelationIdIfMissing();
Map<String, List<Object>> standardHeaders = ResponseHeaders.STANDARD_RESPONSE_HEADERS;
for (Map.Entry<String, List<Object>> header : standardHeaders.entrySet()) {
Map<String, String> responseHeaders = responseHeadersFactory.getResponseHeaders(ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS);
for(Map.Entry<String, String> header : responseHeaders.entrySet()){
httpResponse.addHeader(header.getKey(), header.getValue().toString());
}
httpResponse.addHeader(DpsHeaders.CORRELATION_ID, this.dpsHeaders.getCorrelationId());
......
......@@ -39,6 +39,7 @@ public class ResponseHeaderFilterTest {
public void test_ResponseHeaderFiler_Options() throws IOException, ServletException {
Mockito.when(httpServletRequest.getMethod()).thenReturn("OPTIONS");
org.springframework.test.util.ReflectionTestUtils.setField(responseHeaderFIlter, "ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS", "custom-domain");
responseHeaderFIlter.doFilter(httpServletRequest, httpServletResponse, chain);
assertNotNull(httpServletResponse);
responseHeaderFIlter.destroy();
......@@ -49,6 +50,7 @@ public class ResponseHeaderFilterTest {
public void test_ResponseHeaderFiler_Get() throws IOException, ServletException {
Mockito.when(httpServletRequest.getMethod()).thenReturn("GET");
org.springframework.test.util.ReflectionTestUtils.setField(responseHeaderFIlter, "ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS", "custom-domain");
responseHeaderFIlter.doFilter(httpServletRequest, httpServletResponse, chain);
assertNotNull(httpServletResponse);
responseHeaderFIlter.destroy();
......
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