Commit 66a13540 authored by Hema Vishnu Pola [Microsoft]'s avatar Hema Vishnu Pola [Microsoft]
Browse files

Merge branch 'users/amaverma/refactorBlobStore' into 'master'

adding BlobServiceClientFactory

See merge request osdu/platform/system/lib/cloud/azure/os-core-lib-azure!20
parents f907a3e0 0b4d866f
......@@ -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
......@@ -21,7 +21,7 @@
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<packaging>jar</packaging>
<version>0.0.19</version>
<version>0.0.20</version>
<name>core-lib-azure</name>
<properties>
......
// 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;
}
}
// 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);
}
// 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;
}
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