Skip to content

Commit

Permalink
Added initial implementation for saveMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
basiliskus committed Dec 5, 2023
1 parent 71da245 commit 8a1155b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions etor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ dependencies {
implementation project(':shared')
testImplementation testFixtures(project(':shared'))

implementation 'com.azure:azure-storage-blob:12.25.0'
implementation 'com.azure:azure-identity:1.11.1'

testImplementation 'org.apache.groovy:groovy:4.0.16'
testImplementation 'org.spockframework:spock-core:2.3-groovy-4.0'
testImplementation 'com.openpojo:openpojo:0.9.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
package gov.hhs.cdc.trustedintermediary.external.azure;

import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.storage.blob.BlobClient;
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.BlobServiceClientBuilder;
import gov.hhs.cdc.trustedintermediary.context.ApplicationContext;
import gov.hhs.cdc.trustedintermediary.etor.metadata.PartnerMetadata;
import gov.hhs.cdc.trustedintermediary.etor.metadata.PartnerMetadataStorage;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;

/** Implements the {@link PartnerMetadataStorage} using files stored in an Azure Storage Account. */
public class AzureStorageAccountPartnerMetadataStorage implements PartnerMetadataStorage {

private static final String STORAGE_ACCOUNT_BLOB_ENDPOINT =
ApplicationContext.getProperty("STORAGE_ACCOUNT_BLOB_ENDPOINT");
private static final String METADATA_CONTAINER_NAME =
ApplicationContext.getProperty("METADATA_CONTAINER_NAME");
private static final BlobContainerClient CONTAINER_CLIENT =
new BlobServiceClientBuilder()
.endpoint(STORAGE_ACCOUNT_BLOB_ENDPOINT)
.credential(new DefaultAzureCredentialBuilder().build())
.buildClient()
.getBlobContainerClient(METADATA_CONTAINER_NAME);

private static final AzureStorageAccountPartnerMetadataStorage INSTANCE =
new AzureStorageAccountPartnerMetadataStorage();

Expand All @@ -21,5 +39,11 @@ public PartnerMetadata readMetadata(final String uniqueId) {
}

@Override
public void saveMetadata(final PartnerMetadata metadata) {}
public void saveMetadata(final PartnerMetadata metadata) {
BlobClient blobClient = CONTAINER_CLIENT.getBlobClient(metadata.uniqueId() + ".json");
String content = "serialize(metadata)";
ByteArrayInputStream inputStream =
new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
blobClient.upload(inputStream, content.length(), true);
}
}
1 change: 1 addition & 0 deletions operations/template/app.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ resource "azurerm_linux_web_app" "api" {
ENV = var.environment
REPORT_STREAM_URL_PREFIX = "https://${local.rs_domain_prefix}prime.cdc.gov"
KEY_VAULT_NAME = azurerm_key_vault.key_storage.name
STORAGE_ACCOUNT_BLOB_ENDPOINT = azurerm_storage_account.storage.primary_blob_endpoint
METADATA_CONTAINER_NAME = azurerm_storage_container.metadata.name
}

Expand Down

0 comments on commit 8a1155b

Please sign in to comment.