From a7b85f4550744c001a6743d53fc06005d17b4a58 Mon Sep 17 00:00:00 2001 From: Harshil Sanjay Jain Date: Tue, 9 Jul 2024 08:25:14 -0400 Subject: [PATCH] Storage account public access --- .../azure/storage/StorageAccountResource.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/gyro/azure/storage/StorageAccountResource.java b/src/main/java/gyro/azure/storage/StorageAccountResource.java index 6eebb73b..2ef6b356 100644 --- a/src/main/java/gyro/azure/storage/StorageAccountResource.java +++ b/src/main/java/gyro/azure/storage/StorageAccountResource.java @@ -101,6 +101,7 @@ public class StorageAccountResource extends AzureResource implements Copyable tags; private StorageLifeCycle lifecycle; private Boolean upgradeAccountV2; + private Boolean blobPublicAccess; /** * The cors rules associated with the Storage Account. @@ -203,6 +204,16 @@ public void setUpgradeAccountV2(Boolean upgradeAccountV2) { this.upgradeAccountV2 = upgradeAccountV2; } + @Updatable + @Required + public Boolean getBlobPublicAccess() { + return blobPublicAccess; + } + + public void setBlobPublicAccess(Boolean blobPublicAccess) { + this.blobPublicAccess = blobPublicAccess; + } + @Override public void copyFrom(StorageAccount storageAccount) { setId(storageAccount.id()); @@ -211,6 +222,7 @@ public void copyFrom(StorageAccount storageAccount) { setResourceGroup(findById(ResourceGroupResource.class, storageAccount.resourceGroupName())); setId(storageAccount.id()); setUpgradeAccountV2(storageAccount.kind().equals(Kind.STORAGE_V2)); + setBlobPublicAccess(storageAccount.isBlobPublicAccessAllowed()); getTags().clear(); storageAccount.tags().forEach((key, value) -> getTags().put(key, value)); @@ -250,6 +262,16 @@ public void create(GyroUI ui, State state) throws URISyntaxException, InvalidKey setId(storageAccount.id()); + StorageAccount.Update update = storageAccount.update(); + + if (Boolean.TRUE.equals(getBlobPublicAccess())) { + update = update.enableBlobPublicAccess(); + } else { + update = update.disableBlobPublicAccess(); + } + + update.apply(); + // TODO lifecycle and cors } @@ -271,6 +293,14 @@ public void update(GyroUI ui, State state, Resource current, Set changed } } + if (changedFieldNames.contains("blob-public-access")) { + if (Boolean.TRUE.equals(getBlobPublicAccess())) { + update = update.enableBlobPublicAccess(); + } else { + update = update.disableBlobPublicAccess(); + } + } + update.apply(); }