Skip to content
Snippets Groups Projects
Commit 617ac71e authored by Auto GO3-NRG Ticket's avatar Auto GO3-NRG Ticket
Browse files

Auto commit when pipeline succeeds

parents 49065641 395ac125
No related branches found
No related tags found
1 merge request!98(GONRG-1768) GCP: logging impl
...@@ -17,20 +17,17 @@ package org.opengroup.osdu.legal.azure.countries; ...@@ -17,20 +17,17 @@ package org.opengroup.osdu.legal.azure.countries;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import org.opengroup.osdu.azure.blobstorage.IBlobContainerClientFactory; import org.opengroup.osdu.azure.blobstorage.BlobStore;
import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo; import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.legal.provider.interfaces.IStorageReader; import org.opengroup.osdu.legal.provider.interfaces.IStorageReader;
import org.opengroup.osdu.legal.provider.interfaces.IStorageReaderFactory; import org.opengroup.osdu.legal.provider.interfaces.IStorageReaderFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class StorageReaderFactoryImpl implements IStorageReaderFactory { public class StorageReaderFactoryImpl implements IStorageReaderFactory {
@Inject
private IBlobContainerClientFactory blobContainerClientFactory;
@Inject @Inject
private DpsHeaders headers; private DpsHeaders headers;
...@@ -38,11 +35,11 @@ public class StorageReaderFactoryImpl implements IStorageReaderFactory { ...@@ -38,11 +35,11 @@ public class StorageReaderFactoryImpl implements IStorageReaderFactory {
@Named("STORAGE_CONTAINER_NAME") @Named("STORAGE_CONTAINER_NAME")
private String containerName; private String containerName;
@Inject @Autowired
private JaxRsDpsLog logger; private BlobStore blobStore;
@Override @Override
public IStorageReader getReader(TenantInfo tenant, String projectRegion) { public IStorageReader getReader(TenantInfo tenant, String projectRegion) {
return new StorageReaderImpl(tenant, projectRegion, blobContainerClientFactory.getClient(headers.getPartitionId(), containerName), logger); return new StorageReaderImpl(headers.getPartitionId(), containerName, blobStore);
} }
} }
...@@ -14,57 +14,29 @@ ...@@ -14,57 +14,29 @@
package org.opengroup.osdu.legal.azure.countries; package org.opengroup.osdu.legal.azure.countries;
import com.azure.storage.blob.BlobContainerClient; import org.opengroup.osdu.azure.blobstorage.BlobStore;
import com.azure.storage.blob.specialized.BlockBlobClient;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.legal.provider.interfaces.IStorageReader; import org.opengroup.osdu.legal.provider.interfaces.IStorageReader;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
public class StorageReaderImpl implements IStorageReader { public class StorageReaderImpl implements IStorageReader {
private final TenantInfo tenantInfo;
private final String cloudRegion; private final BlobStore blobStore;
private BlobContainerClient blobContainerClient;
private JaxRsDpsLog logger; private final String dataPartitionId;
private final String containerName;
private static final String fileName = "Legal_COO.json"; private static final String fileName = "Legal_COO.json";
public StorageReaderImpl(TenantInfo tenantInfo, String cloudRegion, BlobContainerClient blobContainerClient, JaxRsDpsLog logger) { public StorageReaderImpl(String dataPartitionId, String containerName, BlobStore blobStore) {
this.tenantInfo = tenantInfo; this.dataPartitionId = dataPartitionId;
this.cloudRegion = cloudRegion; this.containerName = containerName;
this.blobContainerClient = blobContainerClient; this.blobStore = blobStore;
this.logger = logger;
} }
@Override @Override
public byte[] readAllBytes() { public byte[] readAllBytes() {
return readFromBlobStorage().getBytes(StandardCharsets.UTF_8); //should return a json format of an array of Country class return blobStore.readFromStorageContainer(dataPartitionId, fileName, containerName).getBytes(StandardCharsets.UTF_8); //should return a json format of an array of Country class
} }
/**
* This function should be fail close. It reads the pre-configuration file for the partition. As a security requirement, we should
* fail the corresponding request instead of assuming the content is empty, but it should only fail close on the request level not
* service level meaning the service could still start and running probably for the APIs which do not need the pre-configuration file
*/
public String readFromBlobStorage() {
BlockBlobClient blockBlobClient = blobContainerClient.getBlobClient(fileName).getBlockBlobClient();
if (blockBlobClient.exists())
{
try (ByteArrayOutputStream downloadStream = new ByteArrayOutputStream()) {
blockBlobClient.download(downloadStream);
String content = downloadStream.toString(StandardCharsets.UTF_8.name());
return content;
} catch (Exception e) {
String message = String.format("read %s failed", fileName);
throw new AppException(500, "Server error", message);
}
} else {
String message = String.format("%s does not exist on partition %s", fileName, tenantInfo.getDataPartitionId());
throw new AppException(500, "Server error", message);
}
}
} }
\ No newline at end of file
...@@ -42,6 +42,7 @@ azure.cosmosdb.legal.collection=LegalTag ...@@ -42,6 +42,7 @@ azure.cosmosdb.legal.collection=LegalTag
# Azure Blob Storage configuration # Azure Blob Storage configuration
azure.storage.container-name=legal-service-azure-configuration azure.storage.container-name=legal-service-azure-configuration
azure.storage.enable-https=true azure.storage.enable-https=true
azure.blobStore.required=true
# Azure Service Bus configuration # Azure Service Bus configuration
azure.servicebus.topic-name=${servicebus_topic_name} azure.servicebus.topic-name=${servicebus_topic_name}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment