diff --git a/README.md b/README.md index f9093e5af99de1ed9a0a1cbe1b500c7a01f87e89..9f4e93d6372c86ce2f30ca6f01abc62cc8303f6a 100644 --- a/README.md +++ b/README.md @@ -78,4 +78,5 @@ Enabled transaction logger and slf4jlogger | name | value | description | | --- | --- | --- | | `tenantInfo.container.name` | `TenantInfo` | cosmos container name | -| `azure.cosmosdb.database` | ex `dev-osdu-r2-db` | cosmos databse name | \ No newline at end of file +| `azure.cosmosdb.database` | ex `dev-osdu-r2-db` | cosmos database name | +| `storage_account` | ex `testStorage` | storage account name | \ No newline at end of file diff --git a/pom.xml b/pom.xml index e69dc863fe018b66c4a3b9e7e7bd4d1173f30ee6..e34db581cec9aa0765ea08fa3fa72be8110019fe 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ org.opengroup.osdu core-lib-azure jar - 0.0.19 + 0.0.20 core-lib-azure diff --git a/src/main/java/org/opengroup/osdu/azure/blobstorage/BlobServiceClientFactoryImpl.java b/src/main/java/org/opengroup/osdu/azure/blobstorage/BlobServiceClientFactoryImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..1a62a81a1ddd4adc2ecf4e2ed713f7cb4f9ebafa --- /dev/null +++ b/src/main/java/org/opengroup/osdu/azure/blobstorage/BlobServiceClientFactoryImpl.java @@ -0,0 +1,62 @@ +// 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.azure.blobstorage; + +import com.azure.identity.DefaultAzureCredential; +import com.azure.storage.blob.BlobServiceClient; +import com.azure.storage.blob.BlobServiceClientBuilder; +import org.opengroup.osdu.azure.di.BlobStoreConfiguration; +import org.opengroup.osdu.common.Validators; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; + +/** + * Implementation for IBlobServiceClientFactory. + */ +public class BlobServiceClientFactoryImpl implements IBlobServiceClientFactory { + + @Autowired + private DefaultAzureCredential defaultAzureCredential; + + @Autowired + @Lazy + private BlobStoreConfiguration blobStoreConfiguration; + + private BlobServiceClient blobServiceClient; + + /** + * Parameter-less constructor. + * This initializes the blobServiceClient. + */ + public BlobServiceClientFactoryImpl() { + Validators.checkNotNull(defaultAzureCredential, "Credential cannot be null"); + Validators.checkNotNullAndNotEmpty(blobStoreConfiguration.getStorageAccountName(), "Storage account name cannot be null"); + + String endpoint = String.format("https://%s.blob.core.windows.net", blobStoreConfiguration.getStorageAccountName()); + blobServiceClient = new BlobServiceClientBuilder() + .endpoint(endpoint) + .credential(defaultAzureCredential) + .buildClient(); + } + + /** + * @param dataPartitionId data partition id. + * @return BlobServiceClient corresponding to the given data partition id. + */ + @Override + public BlobServiceClient getBlobServiceClient(final String dataPartitionId) { + return blobServiceClient; + } +} diff --git a/src/main/java/org/opengroup/osdu/azure/blobstorage/IBlobServiceClientFactory.java b/src/main/java/org/opengroup/osdu/azure/blobstorage/IBlobServiceClientFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..48e278f75990f23849afbc4b7d08d11e901d292b --- /dev/null +++ b/src/main/java/org/opengroup/osdu/azure/blobstorage/IBlobServiceClientFactory.java @@ -0,0 +1,30 @@ +// 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.azure.blobstorage; + +import com.azure.storage.blob.BlobServiceClient; + +/** + * Interface for Blob service client factory to return appropriate + * blobServiceClient based on the data partition id. + */ +public interface IBlobServiceClientFactory { + /** + * + * @param dataPartitionId data partition id. + * @return BlobServiceClient corresponding to the given data partition id. + */ + BlobServiceClient getBlobServiceClient(String dataPartitionId); +} diff --git a/src/main/java/org/opengroup/osdu/azure/di/BlobStoreConfiguration.java b/src/main/java/org/opengroup/osdu/azure/di/BlobStoreConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..14d0b6e571605bac119828cb1e59f24c94f96400 --- /dev/null +++ b/src/main/java/org/opengroup/osdu/azure/di/BlobStoreConfiguration.java @@ -0,0 +1,32 @@ +// 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.azure.di; + +import lombok.Getter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; + +/** + * A configuration bean class to set up blob store related variables. + */ +@Configuration +@Getter +@Lazy +public class BlobStoreConfiguration { + + @Value("${azure.storage.account-name}") + private String storageAccountName; +}