There is a security vulnerability in SSH key-generation using GitKraken < v8.0.1. If you used this tool to create SSH keys, please update GitKraken and regenerate. If you need help with this, contact forum-support@opengroup.org

Commit f4090d7e authored by Alan Braz's avatar Alan Braz Committed by ethiraj krishnamanaidu
Browse files

Revert "IBM provider project created from master"

This reverts commit 315de3bf.
parent 10e6aacc
......@@ -34,3 +34,4 @@ target/
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
*local.properties
......@@ -8,6 +8,9 @@ variables:
GCP_DEPLOY_ENV: p4d
GCP_DOMAIN: cloud.slb-ds.com
IBM_BUILD_SUBDIR: provider/schema-ibm
#IBM_INT_TEST_SUBDIR: testing/schema-test-ibm
include:
- project: "osdu/platform/ci-cd-pipelines"
file: "standard-setup.yml"
......@@ -15,9 +18,20 @@ include:
- project: "osdu/platform/ci-cd-pipelines"
file: "build/maven.yml"
- project: "osdu/platform/ci-cd-pipelines"
file: "scanners/fossa.yml"
# - project: "osdu/platform/ci-cd-pipelines"
# file: "scanners/fossa.yml"
# - project: "osdu/platform/ci-cd-pipelines"
# file: "cloud-providers/gcp.yml"
# - project: 'osdu/platform/ci-cd-pipelines'
# file: 'cloud-providers/aws.yml'
- project: "osdu/platform/ci-cd-pipelines"
file: "scanners/gitlab-ultimate.yml"
\ No newline at end of file
file: "cloud-providers/ibm.yml"
# - project: "osdu/platform/ci-cd-pipelines"
# file: "scanners/gitlab-ultimate.yml"
# - project: "osdu/platform/ci-cd-pipelines"
# file: "cloud-providers/azure.yml"
......@@ -41,6 +41,7 @@
<modules>
<module>schema-core</module>
<module>provider/schema-gcp</module>
<module>provider/schema-ibm</module>
</modules>
<repositories>
<repository>
......
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-schema</artifactId>
<version>0.0.1</version>
<relativePath>../../</relativePath>
</parent>
<artifactId>os-schema-ibm</artifactId>
<description>IBM cloud related implementation staff.</description>
<packaging>jar</packaging>
<properties>
<start-class>org.opengroup.osdu.schema.provider.ibm.app.SchemaIBMApplication</start-class>
<os-core-lib-ibm.version>0.0.19-SNAPSHOT</os-core-lib-ibm.version>
</properties>
<dependencies>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-schema-core</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-lib-ibm</artifactId>
<version>${os-core-lib-ibm.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/groups/17/-/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/projects/26/packages/maven</url>
</repository>
<snapshotRepository>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/projects/26/packages/maven</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>${start-class}</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<skipTests>${skipUnitTests}</skipTests>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package org.opengroup.osdu.schema.impl.schemainfostore;
import java.net.MalformedURLException;
import java.text.MessageFormat;
import javax.annotation.PostConstruct;
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.impl.schemainfostore.util.IbmDocumentStore;
import org.opengroup.osdu.schema.model.Authority;
import org.opengroup.osdu.schema.provider.ibm.AuthorityDoc;
import org.opengroup.osdu.schema.provider.interfaces.schemainfostore.IAuthorityStore;
import org.springframework.stereotype.Repository;
import org.springframework.web.context.annotation.RequestScope;
/**
* Repository class to to register authority in IBM store.
*
*/
@Repository
@RequestScope
public class IbmAuthorityStore extends IbmDocumentStore implements IAuthorityStore {
@PostConstruct
public void init() throws MalformedURLException {
initFactory(SchemaConstants.AUTHORITY);
}
@Override
public Authority get(String authorityId) throws NotFoundException, ApplicationException {
if (db.contains(authorityId)) {
AuthorityDoc sd = db.find(AuthorityDoc.class, authorityId);
return sd.getAuthority();
} else {
throw new NotFoundException(SchemaConstants.INVALID_INPUT);
}
}
@Override
public Authority create(Authority authority) throws ApplicationException, BadRequestException {
if (db.contains(authority.getAuthorityId())) {
logger.warning(SchemaConstants.AUTHORITY_EXISTS_ALREADY_REGISTERED);
throw new BadRequestException(
MessageFormat.format(SchemaConstants.AUTHORITY_EXISTS_EXCEPTION, authority.getAuthorityId()));
}
AuthorityDoc sd = new AuthorityDoc(authority);
try {
db.save(sd);
} catch (Exception ex) {
logger.error(SchemaConstants.OBJECT_INVALID, ex);
throw new ApplicationException(SchemaConstants.INVALID_INPUT);
}
logger.info(SchemaConstants.AUTHORITY_CREATED);
return sd.getAuthority();
}
}
package org.opengroup.osdu.schema.impl.schemainfostore;
import java.net.MalformedURLException;
import java.text.MessageFormat;
import javax.annotation.PostConstruct;
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.impl.schemainfostore.util.IbmDocumentStore;
import org.opengroup.osdu.schema.model.EntityType;
import org.opengroup.osdu.schema.provider.ibm.EntityTypeDoc;
import org.opengroup.osdu.schema.provider.interfaces.schemainfostore.IEntityTypeStore;
import org.springframework.stereotype.Repository;
import org.springframework.web.context.annotation.RequestScope;
/**
* Repository class to register Entity type in IBM store.
*
*
*/
@Repository
@RequestScope
public class IbmEntityTypeStore extends IbmDocumentStore implements IEntityTypeStore {
@PostConstruct
public void init() throws MalformedURLException {
initFactory(SchemaConstants.ENTITYTYPE_KIND);
}
@Override
public EntityType get(String entityTypeId) throws NotFoundException, ApplicationException {
if (db.contains(entityTypeId)) {
EntityTypeDoc sd = db.find(EntityTypeDoc.class, entityTypeId);
return sd.getEntityType();
} else {
throw new NotFoundException(SchemaConstants.INVALID_INPUT);
}
}
@Override
public EntityType create(EntityType entityType) throws BadRequestException, ApplicationException {
if (db.contains(entityType.getEntityTypeId())) {
logger.warning(SchemaConstants.ENTITY_TYPE_EXISTS);
throw new BadRequestException(
MessageFormat.format(SchemaConstants.ENTITY_TYPE_EXISTS_EXCEPTION, entityType.getEntityTypeId()));
}
EntityTypeDoc sd = new EntityTypeDoc(entityType);
try {
db.save(sd);
} catch (Exception ex) {
logger.error(SchemaConstants.OBJECT_INVALID, ex);
throw new ApplicationException(SchemaConstants.INVALID_INPUT);
}
logger.info(SchemaConstants.ENTITY_TYPE_CREATED);
return sd.getEntityType();
}
}
package org.opengroup.osdu.schema.impl.schemainfostore;
import static com.cloudant.client.api.query.Expression.eq;
import static com.cloudant.client.api.query.Operation.and;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.ibm.multitenancy.TenantFactory;
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.impl.schemainfostore.util.IbmDocumentStore;
import org.opengroup.osdu.schema.model.QueryParams;
import org.opengroup.osdu.schema.model.SchemaIdentity;
import org.opengroup.osdu.schema.model.SchemaInfo;
import org.opengroup.osdu.schema.model.SchemaRequest;
import org.opengroup.osdu.schema.provider.ibm.SchemaDoc;
import org.opengroup.osdu.schema.provider.interfaces.schemainfostore.ISchemaInfoStore;
import org.opengroup.osdu.schema.provider.interfaces.schemastore.ISchemaStore;
import org.opengroup.osdu.schema.util.VersionHierarchyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.context.annotation.RequestScope;
import com.cloudant.client.api.Database;
import com.cloudant.client.api.query.Expression;
import com.cloudant.client.api.query.QueryBuilder;
import com.cloudant.client.api.query.QueryResult;
import com.cloudant.client.api.query.Selector;
import com.google.gson.Gson;
/**
* Repository class to to register Schema in IBM Document Store.
*
*/
@Repository
@RequestScope
public class IbmSchemaInfoStore extends IbmDocumentStore implements ISchemaInfoStore {
private final static String AUTHORITY = "schemaIdentity.authority";
private final static String SOURCE = "schemaIdentity.source";
private final static String ENTITY_TYPE = "schemaIdentity.entityType";
private final static String SCHEMA_VERSION_MAJOR = "schemaIdentity.schemaVersionMajor";
private final static String SCHEMA_VERSION_MINOR = "schemaIdentity.schemaVersionMinor";
private final static String SCHEMA_VERSION_PATCH = "schemaIdentity.schemaVersionPatch";
private final static String SCOPE = "scope";
private final static String STATUS = "status";
@Inject
private TenantFactory tenantFactory;
@Autowired
private ISchemaStore schemaStore;
@PostConstruct
public void init() throws MalformedURLException {
initFactory(SCHEMA_DATABASE);
}
@Override
public boolean isUnique(String schemaId, String tenantId) throws ApplicationException {
Set<String> tenantList = new HashSet<>();
tenantList.add(SchemaConstants.ACCOUNT_ID_COMMON_PROJECT);
tenantList.add(tenantId);
// code to call check uniqueness
if (tenantId.equalsIgnoreCase(SchemaConstants.ACCOUNT_ID_COMMON_PROJECT)) {
List<String> privateTenantList = tenantFactory.listTenantInfo().stream().map(TenantInfo::getDataPartitionId)
.collect(Collectors.toList());
tenantList.addAll(privateTenantList);
}
for (String tenant : tenantList) {
try {
if (getDatabaseForTenant(tenant, SCHEMA_DATABASE).contains(schemaId)) {
return false; // DB exists and contains schemaId, so is not unique
}
} catch (MalformedURLException e) {
// DB doesn't exist, so its unique
throw new ApplicationException("Unable to find database for tenant " + tenant);
}
}
return true;
}
/**
* Method to get schemaInfo from IBM store
*
* @param schemaId
* @return schemaInfo object
* @throws ApplicationException
* @throws NotFoundException
*/
@Override
public SchemaInfo getSchemaInfo(String schemaId) throws ApplicationException, NotFoundException {
if (db.contains(schemaId)) {
SchemaDoc sd = db.find(SchemaDoc.class, schemaId);
return sd.getSchemaInfo();
} else {
throw new NotFoundException(SchemaConstants.SCHEMA_NOT_PRESENT);
}
}
/**
* Method to Create schema in IBM store
*
* @param schemaRequest
* @return schemaInfo object
* @throws ApplicationException
* @throws BadRequestException
*/
@Override
public SchemaInfo createSchemaInfo(SchemaRequest schemaRequest) throws ApplicationException, BadRequestException {
String schemaId = schemaRequest.getSchemaInfo().getSchemaIdentity().getId();
if (db.contains(schemaId)) {
logger.warning("Schema " + schemaId + " already exist. Can't create again.");
throw new BadRequestException("Schema " + schemaId + " already exist. Can't create again.");
}
validateSupercededBy(schemaRequest);
SchemaDoc sd = new SchemaDoc(schemaRequest.getSchemaInfo());
try {
Date date = new Date();
long now = date.getTime();
sd.setCreatedDate(now);
db.save(sd);
} catch (Exception ex) {
logger.error(SchemaConstants.OBJECT_INVALID);
throw new ApplicationException(SchemaConstants.SCHEMA_CREATION_FAILED_INVALID_OBJECT);
}
logger.info(SchemaConstants.SCHEMA_CREATED);
return sd.getSchemaInfo();
}
/**
* Method to update schema in IBM store
*
* @param schemaRequest
* @return schemaInfo object
* @throws ApplicationException
* @throws BadRequestException
*/
@Override
public SchemaInfo updateSchemaInfo(SchemaRequest schemaRequest) throws ApplicationException, BadRequestException {
String schemaId = schemaRequest.getSchemaInfo().getSchemaIdentity().getId();
validateSupercededBy(schemaRequest);
SchemaDoc sdStored = db.find(SchemaDoc.class, schemaId);
SchemaDoc sd = new SchemaDoc(schemaRequest.getSchemaInfo());
sd.setRev(sdStored.getRev());
try {
db.update(sd);
} catch (Exception ex) {
logger.error(SchemaConstants.OBJECT_INVALID, ex);
throw new ApplicationException("Invalid object, updation failed");
}
return sd.getSchemaInfo();
}
/**
* Method to clean schemaInfo in IBM datastore of tenantId
*
* @param schemaId
* @return status
* @throws ApplicationException
*/
@Override
public boolean cleanSchema(String schemaId) throws ApplicationException {
try {
if (db.contains(schemaId)) {
SchemaDoc sd = db.find(SchemaDoc.class, schemaId);
db.remove(sd);
return true;
}
return false;
} catch (Exception ex) {
logger.error(SchemaConstants.OBJECT_INVALID, ex);
return false;
}
}
@Override
public String getLatestMinorVerSchema(SchemaInfo schemaInfo) throws ApplicationException {
QueryResult<SchemaDoc> results = db.query(new QueryBuilder(getSelectorForMinorVerSchema(schemaInfo)).build(),
SchemaDoc.class);
TreeMap<Long, SchemaDoc> sortedMap = new TreeMap<>(Collections.reverseOrder());
for (SchemaDoc doc : results.getDocs()) {
sortedMap.put(doc.getSchemaInfo().getSchemaIdentity().getSchemaVersionMinor(), doc);
}
if (sortedMap.size() != 0) {
Entry<Long, SchemaDoc> sd = sortedMap.firstEntry();
SchemaDoc doc = sd.getValue();
try {
return schemaStore.getSchema(null, doc.getId());
} catch (NotFoundException e) {
return new String();
}
}
return new String();
}
private void validateSupercededBy(SchemaRequest schemaRequest) throws BadRequestException{
if (schemaRequest.getSchemaInfo().getSupersededBy() != null) {
if (schemaRequest.getSchemaInfo().getSupersededBy().getId() == null
|| !db.contains(schemaRequest.getSchemaInfo().getSupersededBy().getId())) {
logger.error(SchemaConstants.INVALID_SUPERSEDEDBY_ID);
throw new BadRequestException(SchemaConstants.INVALID_SUPERSEDEDBY_ID);
}
}
}
private Selector getSelectorForMinorVerSchema(SchemaInfo schemaInfo) {
return and(
eq(AUTHORITY, schemaInfo.getSchemaIdentity().getAuthority()),
eq(ENTITY_TYPE, schemaInfo.getSchemaIdentity().getEntityType()),
eq(SCHEMA_VERSION_MAJOR, schemaInfo.getSchemaIdentity().getSchemaVersionMajor()),
eq(SOURCE, schemaInfo.getSchemaIdentity().getSource())
);
}
@Override
public List<SchemaInfo> getSchemaInfoList(QueryParams queryParams, String tenantId) throws ApplicationException {
long numRecords = LIMIT_SIZE;
if (Long.valueOf(queryParams.getLimit()) != null) {
numRecords = Long.valueOf(queryParams.getLimit());
}
String selectorWithoutFilter = "{ \"selector\": {} }";
String finalQuery = null;
Selector selector = getSelector(queryParams);
if(selector == null)
finalQuery = selectorWithoutFilter;
else
finalQuery = new QueryBuilder(getSelector(queryParams)).limit(numRecords).build();
Database dbWithTenant = null;
try {
dbWithTenant = getDatabaseForTenant(tenantId, SCHEMA_DATABASE);