|
21 | 21 | using Microsoft.Rest.Azure.OData;
|
22 | 22 | using RestAzureNS = Microsoft.Rest.Azure;
|
23 | 23 | using System;
|
24 |
| -using Newtonsoft.Json; |
25 | 24 | using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
|
26 | 25 |
|
27 | 26 | namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS
|
@@ -106,8 +105,23 @@ public BackupResourceConfigResource GetVaultStorageType(string resouceGroupName,
|
106 | 105 | /// <returns>Azure Resource Encryption response object.</returns>
|
107 | 106 | public BackupResourceEncryptionConfigExtendedResource GetVaultEncryptionConfig(string resouceGroupName, string vaultName)
|
108 | 107 | {
|
109 |
| - return BmsAdapter.Client.BackupResourceEncryptionConfigs.GetWithHttpMessagesAsync( |
110 |
| - vaultName, resouceGroupName).Result.Body; |
| 108 | + ARSVault vault = GetVault(resouceGroupName, vaultName); |
| 109 | + |
| 110 | + var vaultEncryptionProperty = vault.Properties.EncryptionProperty; |
| 111 | + BackupResourceEncryptionConfigExtendedResource encryptionConfig = new BackupResourceEncryptionConfigExtendedResource(); |
| 112 | + |
| 113 | + if (vaultEncryptionProperty != null) |
| 114 | + { |
| 115 | + encryptionConfig.Properties = new BackupResourceEncryptionConfigExtended |
| 116 | + { |
| 117 | + KeyUri = vaultEncryptionProperty.KeyVaultProperties?.KeyUri, |
| 118 | + InfrastructureEncryptionState = vaultEncryptionProperty.InfrastructureEncryption, |
| 119 | + UseSystemAssignedIdentity = vaultEncryptionProperty.KekIdentity?.UseSystemAssignedIdentity, |
| 120 | + UserAssignedIdentity = vaultEncryptionProperty.KekIdentity?.UserAssignedIdentity |
| 121 | + }; |
| 122 | + } |
| 123 | + |
| 124 | + return encryptionConfig; |
111 | 125 | }
|
112 | 126 |
|
113 | 127 | /// <summary>
|
@@ -156,13 +170,55 @@ public ARSVault GetVault(string resouceGroupName, string vaultName)
|
156 | 170 | /// <summary>
|
157 | 171 | /// Method to create or update Recovery Services Vault.
|
158 | 172 | /// </summary>
|
159 |
| - /// <param name="resouceGroupName">Name of the resouce group</param> |
| 173 | + /// <param name="resourceGroupName">Name of the resouce group</param> |
160 | 174 | /// <param name="vaultName">Name of the vault</param>
|
161 | 175 | /// <param name="patchVault">patch vault object to patch the recovery services Vault</param>
|
| 176 | + /// <param name="auxiliaryAccessToken">Auxiliary access token for authorization</param> |
| 177 | + /// <param name="isMUAProtected">Flag indicating if the operation is MUA protected</param> |
162 | 178 | /// <returns>Azure Recovery Services Vault.</returns>
|
163 |
| - public Vault UpdateRSVault(string resouceGroupName, string vaultName, PatchVault patchVault) |
| 179 | + public Vault UpdateRSVault(string resourceGroupName, string vaultName, PatchVault patchVault, string auxiliaryAccessToken = null, bool isMUAProtected = false) |
164 | 180 | {
|
165 |
| - var response = RSAdapter.Client.Vaults.UpdateWithHttpMessagesAsync(resouceGroupName, vaultName, patchVault).Result; |
| 181 | + Dictionary<string, List<string>> customHeaders = new Dictionary<string, List<string>>(); |
| 182 | + if (isMUAProtected) |
| 183 | + { |
| 184 | + List<ResourceGuardProxyBaseResource> resourceGuardMapping = ListResourceGuardMapping(vaultName, resourceGroupName); |
| 185 | + string operationRequest = null; |
| 186 | + |
| 187 | + if (resourceGuardMapping != null && resourceGuardMapping.Count != 0) |
| 188 | + { |
| 189 | + // todo: CMK_MUA - check the op value correctly |
| 190 | + string criticalOp = "Microsoft.RecoveryServices/vaults/write#reduceImmutabilityState"; |
| 191 | + |
| 192 | + foreach (ResourceGuardOperationDetail operationDetail in resourceGuardMapping[0].Properties.ResourceGuardOperationDetails) |
| 193 | + { |
| 194 | + if (operationDetail.VaultCriticalOperation == criticalOp) |
| 195 | + { |
| 196 | + operationRequest = operationDetail.DefaultResourceRequest; |
| 197 | + } |
| 198 | + } |
| 199 | + |
| 200 | + if (operationRequest != null) |
| 201 | + { |
| 202 | + patchVault.Properties.ResourceGuardOperationRequests = new List<string>(); |
| 203 | + patchVault.Properties.ResourceGuardOperationRequests.Add(operationRequest); |
| 204 | + } |
| 205 | + } |
| 206 | + |
| 207 | + if (auxiliaryAccessToken != null && auxiliaryAccessToken != "") |
| 208 | + { |
| 209 | + if (operationRequest != null) |
| 210 | + { |
| 211 | + customHeaders.Add("x-ms-authorization-auxiliary", new List<string> { "Bearer " + auxiliaryAccessToken }); |
| 212 | + } |
| 213 | + else |
| 214 | + { |
| 215 | + // resx |
| 216 | + throw new ArgumentException(String.Format(Resources.UnexpectedParameterToken, "modify encryption settings for recovery services vault")); |
| 217 | + } |
| 218 | + } |
| 219 | + } |
| 220 | + |
| 221 | + var response = RSAdapter.Client.Vaults.UpdateWithHttpMessagesAsync(resourceGroupName, vaultName, patchVault, default(string), customHeaders).Result; |
166 | 222 | return response.Body;
|
167 | 223 | }
|
168 | 224 |
|
|
0 commit comments