Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous bugfixs from release #155

Merged
merged 10 commits into from
Aug 13, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ public void setEffectiveOutboundIps(List<String> effectiveOutboundIps) {
* If set to ``true`` enables multiple standard load balancer. Defaults to ``false``.
*/
public Boolean getEnableMultipleStandardLoadBalancers() {
if (enableMultipleStandardLoadBalancers == null) {
enableMultipleStandardLoadBalancers = false;
}

return enableMultipleStandardLoadBalancers;
}

Expand Down Expand Up @@ -171,7 +167,9 @@ protected ManagedClusterLoadBalancerProfile toClusterLoadBalancerProfile() {
profile.withAllocatedOutboundPorts(getAllocatedOutboundPorts());
}

profile.withEnableMultipleStandardLoadBalancers(getEnableMultipleStandardLoadBalancers());
if (getEnableMultipleStandardLoadBalancers() != null) {
profile.withEnableMultipleStandardLoadBalancers(getEnableMultipleStandardLoadBalancers());
}

if (getIdleTimeoutInMinutes() != null) {
profile.withIdleTimeoutInMinutes(getIdleTimeoutInMinutes());
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/gyro/azure/network/NetworkResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void setAddressSpaces(Set<String> addressSpaces) {
*
* @subresource gyro.azure.network.SubnetResource
*/
@Required
public Set<SubnetResource> getSubnet() {
if (subnet == null) {
subnet = new HashSet<>();
Expand Down Expand Up @@ -273,12 +274,13 @@ public void create(GyroUI ui, State state) {
withAddressSpace = networkDefWithoutAddress.withAddressSpace(addressSpace);
}

withAddressSpace = withAddressSpace.withSubnets(getSubnet().stream()
.collect(Collectors.toMap(SubnetResource::getName, SubnetResource::getAddressPrefix)));

Network network = withAddressSpace
.withTags(getTags())
.create();

network = network.update().withoutSubnet("subnet1").apply();

copyFrom(network);
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/gyro/azure/network/SubnetResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public void copyFrom(Subnet subnet) {
RouteTableResource.class,
subnet.routeTableId()) : null);
setServiceEndpoints(toServiceEndpoints(subnet.servicesWithAccess()));
setId(subnet.innerModel().id());
}

@Override
Expand Down Expand Up @@ -186,6 +187,8 @@ public void create(GyroUI ui, State state) {

Network response = updateWithAttach.attach().apply();
setId(response.subnets().get(getName()).id());

parent.refresh();
}

@Override
Expand Down
45 changes: 40 additions & 5 deletions src/main/java/gyro/azure/storage/CloudBlobContainerResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import com.azure.resourcemanager.storage.models.StorageAccount;
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.BlobServiceClient;
import com.azure.storage.blob.BlobServiceClientBuilder;
import com.azure.storage.blob.models.BlobContainerAccessPolicies;
import com.azure.storage.blob.models.BlobErrorCode;
import com.azure.storage.blob.models.BlobStorageException;
import com.azure.storage.blob.models.PublicAccessType;
import gyro.azure.AzureResource;
import gyro.azure.Copyable;
import gyro.core.GyroException;
import gyro.core.GyroUI;
import gyro.core.Type;
import gyro.core.Wait;
Expand Down Expand Up @@ -77,7 +83,6 @@ public void setName(String name) {
/**
* The public access of the container.
*/
@Required
@ValidStrings({ "blob", "container" })
@Updatable
public String getPublicAccess() {
Expand Down Expand Up @@ -127,7 +132,8 @@ public void setId(String id) {

@Override
public void copyFrom(BlobContainerClient container) {
setPublicAccess(container.getAccessPolicy().getBlobAccessType().toString());
setPublicAccess(Optional.ofNullable(container).map(BlobContainerClient::getAccessPolicy).map(
BlobContainerAccessPolicies::getBlobAccessType).map(PublicAccessType::toString).orElse(null));
setName(container.getBlobContainerName());
setMetadata(container.getProperties().getMetadata());
setStorageAccount(findById(StorageAccountResource.class, container.getAccountName()));
Expand All @@ -150,16 +156,45 @@ public boolean refresh() {
public void create(GyroUI ui, State state) {
BlobContainerClient blobContainer = blobContainer();

blobContainer.create();
try {
blobContainer.create();

blobContainer = blobContainer();
} catch (BlobStorageException ex) {
throw new GyroException(
String.format("Could not create container [%s] as it already exists", getName()), ex);
}

blobContainer.setAccessPolicy(PublicAccessType.fromString(getPublicAccess()), null);
state.save();

if (!getMetadata().isEmpty()) {
blobContainer.setMetadata(getMetadata());
}

state.save();

if (getPublicAccess() != null) {
StorageAccount refreshedStorageAccount = getStorageAccount().getStorageAccount();

if (refreshedStorageAccount != null && refreshedStorageAccount.isBlobPublicAccessAllowed()) {
Wait.atMost(2, TimeUnit.MINUTES)
.prompt(false)
.checkEvery(10, TimeUnit.SECONDS)
.until(() -> {
try {
blobContainer.setAccessPolicy(PublicAccessType.fromString(getPublicAccess()), null);
return true;

} catch (BlobStorageException ex) {
if (BlobErrorCode.fromString("PublicAccessNotPermitted").equals(ex.getErrorCode())) {
// Retrying as the storage account has not transitioned to public yet
return false;
}
throw ex;
}
});
}
}

copyFrom(blobContainer);
}

Expand Down
Loading