Skip to content

Commit

Permalink
mgmt, bug fix for storage ImmutabilityPolicy (Azure#23791)
Browse files Browse the repository at this point in the history
* use PATCH in GenericResource update

* use TagOperations for tagging resource

* bug fix on ImmutabilityPolicy
  • Loading branch information
weidongxu-microsoft authored Aug 30, 2021
1 parent 00e54b1 commit 37c8cc3
Show file tree
Hide file tree
Showing 22 changed files with 1,353 additions and 600 deletions.
2 changes: 1 addition & 1 deletion sdk/resourcemanager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ azure.storageAccounts().define("<storage-account-name>")
.createAsync()
.flatMap(storageAccount -> azure.storageBlobContainers()
.defineContainer("container")
.withExistingBlobService(rgName, storageAccount.name())
.withExistingStorageAccount(storageAccount)
.withPublicAccess(PublicAccess.NONE)
.createAsync()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ private Mono<Indexable> createContainerIfNotExistsAsync(final StorageAccount sto
.cast(Indexable.class)
.onErrorResume(throwable -> storageManager.blobContainers()
.defineContainer(containerName)
.withExistingBlobService(storageAccount.resourceGroupName(), storageAccount.name())
.withExistingStorageAccount(storageAccount.resourceGroupName(), storageAccount.name())
.withPublicAccess(PublicAccess.NONE)
.createAsync());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 2.8.0-beta.1 (Unreleased)

### Other Changes

- Updated to use `PATCH` HTTP method for the update flow of `GenericResource`. For tagging resource, it is advised to use `TagOperations` instead.

## 2.7.0 (2021-08-12)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ final class GenericResourceImpl
private String resourceType;
private String apiVersion;

private GenericResourceInner createUpdateParameter = new GenericResourceInner();

GenericResourceImpl(String key,
GenericResourceInner innerModel,
final ResourceManager resourceManager) {
Expand Down Expand Up @@ -119,32 +121,38 @@ protected Mono<GenericResourceInner> getInnerAsync() {
this.apiVersion());
}

@Override
public GenericResourceImpl update() {
this.createUpdateParameter = new GenericResourceInner();
return super.update();
}

public GenericResourceImpl withProperties(Object properties) {
innerModel().withProperties(properties);
createUpdateParameter.withProperties(properties);
return this;
}

@Override
public GenericResourceImpl withKind(String kind) {
innerModel().withKind(kind);
createUpdateParameter.withKind(kind);
return this;
}

@Override
public GenericResourceImpl withSku(Sku sku) {
innerModel().withSku(sku);
createUpdateParameter.withSku(sku);
return this;
}

@Override
public GenericResourceImpl withIdentity(Identity identity) {
innerModel().withIdentity(identity);
createUpdateParameter.withIdentity(identity);
return this;
}

@Override
public GenericResourceImpl withoutIdentity() {
innerModel().withIdentity(new Identity().withType(ResourceIdentityType.NONE));
this.withIdentity(new Identity().withType(ResourceIdentityType.NONE));
return this;
}

Expand All @@ -160,7 +168,7 @@ public GenericResourceImpl withParentResourcePath(String parentResourcePath) {
}

public GenericResourceImpl withPlan(String name, String publisher, String product, String promotionCode) {
innerModel().withPlan(
this.withPlan(
new Plan()
.withName(name)
.withPublisher(publisher)
Expand All @@ -170,13 +178,13 @@ public GenericResourceImpl withPlan(String name, String publisher, String produc
}

public GenericResourceImpl withPlan(Plan plan) {
innerModel().withPlan(plan);
createUpdateParameter.withPlan(plan);
return this;
}

@Override
public GenericResourceImpl withoutPlan() {
innerModel().withPlan(null);
createUpdateParameter.withPlan(null);
return this;
}

Expand All @@ -202,6 +210,8 @@ public GenericResourceImpl withApiVersion(String apiVersion) {
public Accepted<GenericResource> beginCreate() {
String apiVersion = this.getApiVersionAsync().block();
String name = isInCreateMode() ? this.name() : ResourceUtils.nameFromResourceId(innerModel().id());
createUpdateParameter.withLocation(innerModel().location());
createUpdateParameter.withTags(innerModel().tags());

return AcceptedImpl.newAccepted(logger,
this.manager().serviceClient().getHttpPipeline(),
Expand All @@ -214,7 +224,7 @@ public Accepted<GenericResource> beginCreate() {
resourceType,
name,
apiVersion,
innerModel()).block(),
createUpdateParameter).block(),
inner -> new GenericResourceImpl(inner.id(), inner, this.manager()),
GenericResourceInner.class,
null,
Expand All @@ -230,22 +240,42 @@ public Mono<GenericResource> createResourceAsync() {
return observable
.flatMap(api -> {
String name = this.name();
if (!isInCreateMode()) {
name = ResourceUtils.nameFromResourceId(innerModel().id());
}
createUpdateParameter.withLocation(innerModel().location());
createUpdateParameter.withTags(innerModel().tags());
return resourceClient.createOrUpdateAsync(
resourceGroupName(),
resourceProviderNamespace,
parentResourcePath(),
resourceType,
name,
api,
innerModel())
createUpdateParameter)
.subscribeOn(ResourceManagerUtils.InternalRuntimeContext.getReactorScheduler())
.map(innerToFluentMap(this));
});
}

@Override
public Mono<GenericResource> updateResourceAsync() {
Mono<String> observable = this.getApiVersionAsync();
final ResourcesClient resourceClient = this.manager().serviceClient().getResources();
return observable
.flatMap(api -> {
String name = ResourceUtils.nameFromResourceId(innerModel().id());
createUpdateParameter.withTags(innerModel().tags());
return resourceClient.updateAsync(
resourceGroupName(),
resourceProviderNamespace,
parentResourcePath(),
resourceType,
name,
api,
createUpdateParameter)
.subscribeOn(ResourceManagerUtils.InternalRuntimeContext.getReactorScheduler())
.map(innerToFluentMap(this));
});
}

private Mono<String> getApiVersionAsync() {
Mono<String> apiVersion;
if (this.apiVersion != null) {
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit 37c8cc3

Please sign in to comment.