use of com.azure.resourcemanager.storage.models.StorageAccount in project azure-vm-agents-plugin by jenkinsci.
the class IntegrationTest method downloadFromAzure.
protected String downloadFromAzure(String resourceGroup, String storageAccountName, String containerName, String fileName) throws IOException {
StorageAccount storageAccount = azureClient.storageAccounts().getByResourceGroup(resourceGroup, storageAccountName);
List<StorageAccountKey> storageKeys = storageAccount.getKeys();
String storageAccountKey = storageKeys.get(0).value();
BlobServiceClient account = new BlobServiceClientBuilder().credential(new StorageSharedKeyCredential(storageAccountName, storageAccountKey)).endpoint(storageAccount.endPoints().primary().blob()).buildClient();
BlobContainerClient blobClient = account.getBlobContainerClient(containerName);
if (!blobClient.exists()) {
blobClient.create();
}
BlobClient blob = blobClient.getBlobClient(fileName);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
blob.download(byteArrayOutputStream);
return byteArrayOutputStream.toString(StandardCharsets.UTF_8.name());
}
use of com.azure.resourcemanager.storage.models.StorageAccount in project azure-vm-agents-plugin by jenkinsci.
the class IntegrationTest method blobExists.
protected boolean blobExists(String storageURI) {
try {
BlobUrlParts blobUrlParts = BlobUrlParts.parse(storageURI);
String storageAccountName = blobUrlParts.getAccountName();
final String containerName = blobUrlParts.getBlobContainerName();
final String blobName = blobUrlParts.getBlobName();
StorageAccount storageAccount = azureClient.storageAccounts().getByResourceGroup(testEnv.azureResourceGroup, storageAccountName);
List<StorageAccountKey> storageKeys = storageAccount.getKeys();
if (storageKeys.isEmpty()) {
return false;
} else {
String storageAccountKey = storageKeys.get(0).value();
BlobServiceClient account = new BlobServiceClientBuilder().credential(new StorageSharedKeyCredential(storageAccountName, storageAccountKey)).endpoint(storageAccount.endPoints().primary().blob()).buildClient();
BlobContainerClient blobClient = account.getBlobContainerClient(containerName);
return blobClient.getBlobClient(blobName).exists();
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
return false;
}
}
Aggregations