From a7b85f4550744c001a6743d53fc06005d17b4a58 Mon Sep 17 00:00:00 2001 From: Harshil Sanjay Jain Date: Tue, 9 Jul 2024 08:25:14 -0400 Subject: [PATCH 1/4] 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(); } From 661a94896acbe6400e80d4a9481b71d4cb4b1f6c Mon Sep 17 00:00:00 2001 From: Harshil Sanjay Jain Date: Tue, 9 Jul 2024 13:09:35 -0400 Subject: [PATCH 2/4] Dont update for null publicAccess --- src/main/java/gyro/azure/storage/StorageAccountResource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gyro/azure/storage/StorageAccountResource.java b/src/main/java/gyro/azure/storage/StorageAccountResource.java index 2ef6b356..ee2ff6ac 100644 --- a/src/main/java/gyro/azure/storage/StorageAccountResource.java +++ b/src/main/java/gyro/azure/storage/StorageAccountResource.java @@ -266,7 +266,7 @@ public void create(GyroUI ui, State state) throws URISyntaxException, InvalidKey if (Boolean.TRUE.equals(getBlobPublicAccess())) { update = update.enableBlobPublicAccess(); - } else { + } else if (Boolean.FALSE.equals(getBlobPublicAccess())) { update = update.disableBlobPublicAccess(); } From 4c493cc0e46f1a02b53f7c293bd445175e3e417e Mon Sep 17 00:00:00 2001 From: Harshil Sanjay Jain Date: Wed, 10 Jul 2024 10:59:26 -0400 Subject: [PATCH 3/4] Add docs for the field --- src/main/java/gyro/azure/storage/StorageAccountResource.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/gyro/azure/storage/StorageAccountResource.java b/src/main/java/gyro/azure/storage/StorageAccountResource.java index ee2ff6ac..179bc0cb 100644 --- a/src/main/java/gyro/azure/storage/StorageAccountResource.java +++ b/src/main/java/gyro/azure/storage/StorageAccountResource.java @@ -204,6 +204,9 @@ public void setUpgradeAccountV2(Boolean upgradeAccountV2) { this.upgradeAccountV2 = upgradeAccountV2; } + /** + * When set to ``true``, allows blob public access, configured by individual containers. + */ @Updatable @Required public Boolean getBlobPublicAccess() { From 396d980d22fb17727ec7517e4e9ba176daebc4f7 Mon Sep 17 00:00:00 2001 From: Harshil Sanjay Jain Date: Wed, 10 Jul 2024 11:30:12 -0400 Subject: [PATCH 4/4] Blob public access should not be required --- src/main/java/gyro/azure/storage/StorageAccountResource.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/gyro/azure/storage/StorageAccountResource.java b/src/main/java/gyro/azure/storage/StorageAccountResource.java index 179bc0cb..4fbe61af 100644 --- a/src/main/java/gyro/azure/storage/StorageAccountResource.java +++ b/src/main/java/gyro/azure/storage/StorageAccountResource.java @@ -208,7 +208,6 @@ public void setUpgradeAccountV2(Boolean upgradeAccountV2) { * When set to ``true``, allows blob public access, configured by individual containers. */ @Updatable - @Required public Boolean getBlobPublicAccess() { return blobPublicAccess; }