Skip to content

Commit

Permalink
mgmt Storage, support allowCrossTenantReplication and `defaultToOAu…
Browse files Browse the repository at this point in the history
…thAuthentication` for `StorageAccount` (#37460)

fix for support allowCrossTenantReplication and defaultToOAuthAuthentication for StorageAccount
  • Loading branch information
v-hongli1 authored Nov 1, 2023
1 parent 71281b6 commit 26d8d10
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes
- Supported `allowCrossTenantReplication` and `defaultToOAuthAuthentication` for `StorageAccount` in create and update.

## 2.32.0 (2023-10-27)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/resourcemanager/azure-resourcemanager-storage",
"Tag": "java/resourcemanager/azure-resourcemanager-storage_d0dd902bd0"
"Tag": "java/resourcemanager/azure-resourcemanager-storage_5816c875b5"
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,19 @@ public boolean isSharedKeyAccessAllowed() {
return this.innerModel().allowSharedKeyAccess();
}

@Override
public boolean isAllowCrossTenantReplication() {
if (this.innerModel().allowCrossTenantReplication() == null) {
return true;
}
return this.innerModel().allowCrossTenantReplication();
}

@Override
public boolean isDefaultToOAuthAuthentication() {
return ResourceManagerUtils.toPrimitiveBoolean(this.innerModel().defaultToOAuthAuthentication());
}

@Override
public List<StorageAccountKey> getKeys() {
return this.getKeysAsync().block();
Expand Down Expand Up @@ -565,6 +578,46 @@ public StorageAccountImpl disableSharedKeyAccess() {
return this;
}

@Override
public StorageAccountImpl allowCrossTenantReplication() {
if (isInCreateMode()) {
createParameters.withAllowCrossTenantReplication(true);
} else {
updateParameters.withAllowCrossTenantReplication(true);
}
return this;
}

@Override
public StorageAccountImpl disallowCrossTenantReplication() {
if (isInCreateMode()) {
createParameters.withAllowCrossTenantReplication(false);
} else {
updateParameters.withAllowCrossTenantReplication(false);
}
return this;
}

@Override
public StorageAccountImpl enableDefaultToOAuthAuthentication() {
if (isInCreateMode()) {
createParameters.withDefaultToOAuthAuthentication(true);
} else {
updateParameters.withDefaultToOAuthAuthentication(true);
}
return this;
}

@Override
public StorageAccountImpl disableDefaultToOAuthAuthentication() {
if (isInCreateMode()) {
createParameters.withDefaultToOAuthAuthentication(false);
} else {
updateParameters.withDefaultToOAuthAuthentication(false);
}
return this;
}

@Override
public StorageAccountImpl withAccessFromAllNetworks() {
this.networkRulesHelper.withAccessFromAllNetworks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ public interface StorageAccount
*/
Mono<List<StorageAccountKey>> regenerateKeyAsync(String keyName);

/**
* Checks whether cross tenant replication is allowed.
*
* @return true if cross tenant replication is enabled, false otherwise
*/
boolean isAllowCrossTenantReplication();

/**
* Checks whether default to oauth authentication is allowed.
*
* @return true if default to oauth authentication is enabled, false otherwise
*/
boolean isDefaultToOAuthAuthentication();

/** Container interface for all the definitions that need to be implemented. */
interface Definition
extends DefinitionStages.Blank,
Expand Down Expand Up @@ -547,6 +561,29 @@ interface WithHns {
WithCreate withHnsEnabled(boolean enabled);
}

/** The stage of storage account definition allowing to configure allow cross tenant replication. */
interface WithAllowCrossTenantReplication {
/**
* Disables allow cross tenant replication.
*
* Disabling in storage account overrides the allow cross tenant replication settings for individual containers.
*
* @return the next stage of storage account definition
*/
WithCreate disallowCrossTenantReplication();

}

/** The stage of storage account definition allowing to configure default to oauth authentication. */
interface WithDefaultToOAuthAuthentication {
/**
* Allows default to oauth authentication, configured by individual containers.
*
* @return the next stage of storage account definition
*/
WithCreate enableDefaultToOAuthAuthentication();
}

/**
* A storage account definition with sufficient inputs to create a new storage account in the cloud, but
* exposing additional optional inputs to specify.
Expand All @@ -567,6 +604,8 @@ interface WithCreate
DefinitionStages.WithLargeFileShares,
DefinitionStages.WithHns,
DefinitionStages.WithBlobAccess,
DefinitionStages.WithAllowCrossTenantReplication,
DefinitionStages.WithDefaultToOAuthAuthentication,
Resource.DefinitionWithTags<WithCreate> {
}

Expand Down Expand Up @@ -892,6 +931,45 @@ interface WithUpgrade {
*/
Update upgradeToGeneralPurposeAccountKindV2();
}

/** The stage of storage account update allowing to allow cross tenant replication. */
interface WithAllowCrossTenantReplication {
/**
* Allows to allow cross tenant replication, configured by individual containers.
*
* @return the next stage of storage account update
*/
Update allowCrossTenantReplication();

/**
* Disables cross tenant replication.
*
* Disabling in storage account overrides the cross tenant replication settings for individual containers.
*
* @return the next stage of storage account update
*/
Update disallowCrossTenantReplication();
}

/** The stage of storage account update allowing to configure default to oauth authentication. */
interface WithDefaultToOAuthAuthentication {
/**
* Allows default to oauth authentication, configured by individual containers.
*
* @return the next stage of storage account update
*/
Update enableDefaultToOAuthAuthentication();

/**
* Disables default to oauth authentication.
*
* Disabling in storage account overrides the default to oauth authentication settings for individual containers.
*
* @return the next stage of storage account update
*/
Update disableDefaultToOAuthAuthentication();
}

}

/** The template for a storage account update operation, containing all the settings that can be modified. */
Expand All @@ -906,6 +984,8 @@ interface Update
UpdateStages.WithNetworkAccess,
UpdateStages.WithUpgrade,
UpdateStages.WithBlobAccess,
UpdateStages.WithAllowCrossTenantReplication,
UpdateStages.WithDefaultToOAuthAuthentication,
Resource.UpdateWithTags<Update> {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,85 @@ public void storageAccountDefault() {
Assertions.assertFalse(storageAccount.isBlobPublicAccessAllowed());
Assertions.assertFalse(storageAccount.isSharedKeyAccessAllowed());
}

@Test
public void canAllowCrossTenantReplicationOnStorageAccount() {
StorageAccount storageAccount =
storageManager
.storageAccounts()
.define(saName)
.withRegion(Region.US_EAST2)
.withNewResourceGroup(rgName)
.withSku(StorageAccountSkuType.STANDARD_LRS)
.disallowCrossTenantReplication()
.create();

Assertions.assertFalse(storageAccount.isAllowCrossTenantReplication());

storageAccount.update()
.allowCrossTenantReplication()
.apply();

Assertions.assertTrue(storageAccount.isAllowCrossTenantReplication());
}

@Test
public void canDisallowCrossTenantReplicationOnStorageAccount() {
StorageAccount storageAccount =
storageManager
.storageAccounts()
.define(saName)
.withRegion(Region.US_EAST2)
.withNewResourceGroup(rgName)
.withSku(StorageAccountSkuType.STANDARD_LRS)
.create();

Assertions.assertTrue(storageAccount.isAllowCrossTenantReplication());

storageAccount.update()
.disallowCrossTenantReplication()
.apply();

Assertions.assertFalse(storageAccount.isAllowCrossTenantReplication());
}

@Test
public void canEnableDefaultToOAuthAuthenticationOnStorageAccount() {
StorageAccount storageAccount =
storageManager
.storageAccounts()
.define(saName)
.withRegion(Region.US_EAST2)
.withNewResourceGroup(rgName)
.withSku(StorageAccountSkuType.STANDARD_LRS)
.create();

Assertions.assertFalse(storageAccount.isDefaultToOAuthAuthentication());

storageAccount.update()
.enableDefaultToOAuthAuthentication()
.apply();

Assertions.assertTrue(storageAccount.isDefaultToOAuthAuthentication());
}
@Test
public void canDisableDefaultToOAuthAuthenticationOnStorageAccount() {
StorageAccount storageAccount =
storageManager
.storageAccounts()
.define(saName)
.withRegion(Region.US_EAST2)
.withNewResourceGroup(rgName)
.withSku(StorageAccountSkuType.STANDARD_LRS)
.enableDefaultToOAuthAuthentication()
.create();

Assertions.assertTrue(storageAccount.isDefaultToOAuthAuthentication());

storageAccount.update()
.disableDefaultToOAuthAuthentication()
.apply();

Assertions.assertFalse(storageAccount.isDefaultToOAuthAuthentication());
}
}

0 comments on commit 26d8d10

Please sign in to comment.