Search in sources :

Example 1 with BlobServiceClientBuilder

use of com.azure.storage.blob.BlobServiceClientBuilder in project samza by apache.

the class AzureBlobClientBuilder method getBlobServiceAsyncClient.

/**
 * method creates BlobServiceAsyncClient using the configs provided earlier.
 * if the authentication method is set to {@link TokenCredential} then a {@link com.azure.identity.ClientSecretCredential}
 * is created and used for the Blob client. Else authentication is done via account name and key using the
 * {@link StorageSharedKeyCredential}.
 * The config used to determine which authentication is systems.%s.azureblob.useTokenCredentialAuthentication = true
 * for using TokenCredential.
 * @return BlobServiceAsyncClient
 */
public BlobServiceAsyncClient getBlobServiceAsyncClient() {
    BlobServiceClientBuilder blobServiceClientBuilder = getBlobServiceClientBuilder();
    if (azureBlobConfig.getUseTokenCredentialAuthentication(systemName)) {
        // Use your Azure Blob Storage account's name and client details to create a token credential object to access your account.
        TokenCredential tokenCredential = getTokenCredential();
        return blobServiceClientBuilder.credential(tokenCredential).buildAsyncClient();
    }
    // Use your Azure Blob Storage account's name and key to create a credential object to access your account.
    StorageSharedKeyCredential storageSharedKeyCredential = getStorageSharedKeyCredential();
    return blobServiceClientBuilder.credential(storageSharedKeyCredential).buildAsyncClient();
}
Also used : BlobServiceClientBuilder(com.azure.storage.blob.BlobServiceClientBuilder) StorageSharedKeyCredential(com.azure.storage.common.StorageSharedKeyCredential) TokenCredential(com.azure.core.credential.TokenCredential)

Example 2 with BlobServiceClientBuilder

use of com.azure.storage.blob.BlobServiceClientBuilder in project azure-iot-sdk-java by Azure.

the class ExportImportTests method setUp.

@BeforeClass
public static void setUp() throws IOException {
    iotHubConnectionString = Tools.retrieveEnvironmentVariableValue(TestConstants.IOT_HUB_CONNECTION_STRING_ENV_VAR_NAME);
    isBasicTierHub = Boolean.parseBoolean(Tools.retrieveEnvironmentVariableValue(TestConstants.IS_BASIC_TIER_HUB_ENV_VAR_NAME));
    storageAccountConnectionString = Tools.retrieveEnvironmentVariableValue(TestConstants.STORAGE_ACCOUNT_CONNECTION_STRING_ENV_VAR_NAME);
    isPullRequest = Boolean.parseBoolean(Tools.retrieveEnvironmentVariableValue(TestConstants.IS_PULL_REQUEST));
    registryManager = RegistryManager.createFromConnectionString(iotHubConnectionString, RegistryManagerOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build());
    String uuid = UUID.randomUUID().toString();
    deviceId = deviceId.concat("-" + uuid);
    BlobServiceClient blobClient = new BlobServiceClientBuilder().connectionString(storageAccountConnectionString).buildClient();
    // Creating the export storage container and getting its URI
    String exportContainerName = "exportcontainersample-" + uuid;
    exportContainer = blobClient.getBlobContainerClient(exportContainerName);
    exportContainer.create();
    // Creating the import storage container and getting its URI
    String importContainerName = "importcontainersample-" + uuid;
    importContainer = blobClient.getBlobContainerClient(importContainerName);
    importContainer.create();
}
Also used : BlobServiceClient(com.azure.storage.blob.BlobServiceClient) BlobServiceClientBuilder(com.azure.storage.blob.BlobServiceClientBuilder) BeforeClass(org.junit.BeforeClass)

Example 3 with BlobServiceClientBuilder

use of com.azure.storage.blob.BlobServiceClientBuilder in project beam by apache.

the class DefaultBlobstoreClientBuilderFactory method createBuilder.

@Override
public BlobServiceClientBuilder createBuilder(BlobstoreOptions blobstoreOptions) {
    BlobServiceClientBuilder builder = new BlobServiceClientBuilder();
    if (!Strings.isNullOrEmpty(blobstoreOptions.getAzureConnectionString())) {
        builder = builder.connectionString(blobstoreOptions.getAzureConnectionString());
    }
    if (blobstoreOptions.getAzureCredentialsProvider() != null) {
        builder = builder.credential(blobstoreOptions.getAzureCredentialsProvider());
    }
    if (!Strings.isNullOrEmpty(blobstoreOptions.getSasToken())) {
        builder = builder.sasToken(blobstoreOptions.getSasToken());
    }
    if (!Strings.isNullOrEmpty(blobstoreOptions.getAccountName()) && !Strings.isNullOrEmpty(blobstoreOptions.getAccessKey())) {
        StorageSharedKeyCredential credential = new StorageSharedKeyCredential(blobstoreOptions.getAccountName(), blobstoreOptions.getAccessKey());
        builder = builder.credential(credential);
    }
    if (!Strings.isNullOrEmpty(blobstoreOptions.getBlobServiceEndpoint())) {
        builder = builder.endpoint(blobstoreOptions.getBlobServiceEndpoint());
    }
    if (blobstoreOptions.getCustomerProvidedKey() != null) {
        builder = builder.customerProvidedKey(blobstoreOptions.getCustomerProvidedKey());
    }
    if (blobstoreOptions.getPipelinePolicy() != null) {
        builder = builder.addPolicy(blobstoreOptions.getPipelinePolicy());
    }
    if (blobstoreOptions.getHttpClient() != null) {
        builder = builder.httpClient(blobstoreOptions.getHttpClient());
    }
    if (blobstoreOptions.getHttpPipeline() != null) {
        builder = builder.pipeline(blobstoreOptions.getHttpPipeline());
    }
    return builder;
}
Also used : BlobServiceClientBuilder(com.azure.storage.blob.BlobServiceClientBuilder) StorageSharedKeyCredential(com.azure.storage.common.StorageSharedKeyCredential)

Example 4 with BlobServiceClientBuilder

use of com.azure.storage.blob.BlobServiceClientBuilder in project samza by apache.

the class AzureBlobClientBuilder method getBlobServiceClientBuilder.

/**
 * Method to get the builder {@link BlobServiceClientBuilder} for creating BlobServiceAsyncClient.
 * This builder is not provided the credential for authentication here.
 * this builder is given an endpoint for the Azure Storage account and a http client to be passed on to the
 * BlobServiceAsyncClient for blob creation.
 * @return BlobServiceClientBuilder
 */
private BlobServiceClientBuilder getBlobServiceClientBuilder() {
    // From the Azure portal, get your Storage account blob service AsyncClient endpoint.
    String endpoint = String.format(Locale.ROOT, azureUrlFormat, azureBlobConfig.getAzureAccountName(systemName));
    HttpLogOptions httpLogOptions = new HttpLogOptions();
    httpLogOptions.setLogLevel(HttpLogDetailLevel.HEADERS);
    BlobServiceClientBuilder blobServiceClientBuilder = new BlobServiceClientBuilder().httpLogOptions(httpLogOptions).endpoint(endpoint).httpClient(getHttpClient());
    return blobServiceClientBuilder;
}
Also used : BlobServiceClientBuilder(com.azure.storage.blob.BlobServiceClientBuilder) HttpLogOptions(com.azure.core.http.policy.HttpLogOptions)

Example 5 with BlobServiceClientBuilder

use of com.azure.storage.blob.BlobServiceClientBuilder in project carina by qaprosoft.

the class AzureManager method getInstance.

public static synchronized AzureManager getInstance() {
    if (instance == null) {
        instance = new AzureManager();
        CryptoTool cryptoTool = new CryptoTool(Configuration.get(Configuration.Parameter.CRYPTO_KEY_PATH));
        Pattern CRYPTO_PATTERN = Pattern.compile(SpecialKeywords.CRYPT);
        String accountName = Configuration.get(Configuration.Parameter.AZURE_ACCOUNT_NAME);
        String endpoint = cryptoTool.decryptByPattern(Configuration.get(Configuration.Parameter.AZURE_BLOB_URL), CRYPTO_PATTERN);
        String secretKey = cryptoTool.decryptByPattern(Configuration.get(Configuration.Parameter.AZURE_ACCESS_KEY_TOKEN), CRYPTO_PATTERN);
        // Create a SharedKeyCredential
        StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, secretKey);
        // Create a blobServiceClient
        blobServiceClient = new BlobServiceClientBuilder().endpoint(endpoint).credential(credential).buildClient();
    }
    return instance;
}
Also used : Pattern(java.util.regex.Pattern) BlobServiceClientBuilder(com.azure.storage.blob.BlobServiceClientBuilder) CryptoTool(com.qaprosoft.carina.core.foundation.crypto.CryptoTool) StorageSharedKeyCredential(com.azure.storage.common.StorageSharedKeyCredential)

Aggregations

BlobServiceClientBuilder (com.azure.storage.blob.BlobServiceClientBuilder)5 StorageSharedKeyCredential (com.azure.storage.common.StorageSharedKeyCredential)3 TokenCredential (com.azure.core.credential.TokenCredential)1 HttpLogOptions (com.azure.core.http.policy.HttpLogOptions)1 BlobServiceClient (com.azure.storage.blob.BlobServiceClient)1 CryptoTool (com.qaprosoft.carina.core.foundation.crypto.CryptoTool)1 Pattern (java.util.regex.Pattern)1 BeforeClass (org.junit.BeforeClass)1