public virtual DiskEncryptionSetUpdateOperation Update(DiskEncryptionSetUpdate diskEncryptionSet, bool waitForCompletion = true, CancellationToken cancellationToken = default) { if (diskEncryptionSet == null) { throw new ArgumentNullException(nameof(diskEncryptionSet)); } using var scope = _clientDiagnostics.CreateScope("DiskEncryptionSet.Update"); scope.Start(); try { var response = _restClient.Update(Id.ResourceGroupName, Id.Name, diskEncryptionSet, cancellationToken); var operation = new DiskEncryptionSetUpdateOperation(this, _clientDiagnostics, Pipeline, _restClient.CreateUpdateRequest(Id.ResourceGroupName, Id.Name, diskEncryptionSet).Request, response); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
protected void DiskEncryptionSet_CRUD_Execute(string methodName, string location = null) { using (MockContext context = MockContext.Start(this.GetType(), methodName)) { EnsureClientsInitialized(context); DiskRPLocation = location ?? DiskRPLocation; // Data var rgName = TestUtilities.GenerateName(TestPrefix); var desName = TestUtilities.GenerateName(DiskNamePrefix); DiskEncryptionSet des = GenerateDefaultDiskEncryptionSet(DiskRPLocation); try { m_ResourcesClient.ResourceGroups.CreateOrUpdate(rgName, new ResourceGroup { Location = DiskRPLocation }); // Put DiskEncryptionSet DiskEncryptionSet desOut = m_CrpClient.DiskEncryptionSets.CreateOrUpdate(rgName, desName, des); Validate(des, desOut, desName); // Get DiskEncryptionSet desOut = m_CrpClient.DiskEncryptionSets.Get(rgName, desName); Validate(des, desOut, desName); // Patch DiskEncryptionSet const string tagKey = "tageKey"; var updateDes = new DiskEncryptionSetUpdate(); updateDes.Tags = new Dictionary <string, string>() { { tagKey, "tagvalue" } }; desOut = m_CrpClient.DiskEncryptionSets.Update(rgName, desName, updateDes); Validate(des, desOut, desName); Assert.Equal(1, desOut.Tags.Count); // Delete DiskEncryptionSet m_CrpClient.DiskEncryptionSets.Delete(rgName, desName); try { // Ensure it was really deleted m_CrpClient.DiskEncryptionSets.Get(rgName, desName); Assert.False(true); } catch (CloudException ex) { Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode); } } finally { // Delete resource group m_ResourcesClient.ResourceGroups.Delete(rgName); } } }
private void BuildPatchObject() { if (this.IsParameterBound(c => c.KeyUrl)) { if (this.DiskEncryptionSetUpdate == null) { this.DiskEncryptionSetUpdate = new DiskEncryptionSetUpdate(); } if (this.DiskEncryptionSetUpdate.ActiveKey == null) { //this.DiskEncryptionSetUpdate.ActiveKey = new KeyVaultAndKeyReference(); this.DiskEncryptionSetUpdate.ActiveKey = new KeyForDiskEncryptionSet(); } this.DiskEncryptionSetUpdate.ActiveKey.KeyUrl = this.KeyUrl; } if (this.IsParameterBound(c => c.SourceVaultId)) { if (this.DiskEncryptionSetUpdate == null) { this.DiskEncryptionSetUpdate = new DiskEncryptionSetUpdate(); } if (this.DiskEncryptionSetUpdate.ActiveKey == null) { //this.DiskEncryptionSetUpdate.ActiveKey = new KeyVaultAndKeyReference(); this.DiskEncryptionSetUpdate.ActiveKey = new KeyForDiskEncryptionSet(); } if (this.DiskEncryptionSetUpdate.ActiveKey.SourceVault == null) { this.DiskEncryptionSetUpdate.ActiveKey.SourceVault = new SourceVault(); } this.DiskEncryptionSetUpdate.ActiveKey.SourceVault.Id = this.SourceVaultId; } if (this.IsParameterBound(c => c.Tag)) { if (this.DiskEncryptionSetUpdate == null) { this.DiskEncryptionSetUpdate = new DiskEncryptionSetUpdate(); } this.DiskEncryptionSetUpdate.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value); } if (this.IsParameterBound(c => c.RotationToLatestKeyVersionEnabled)) { if (this.DiskEncryptionSetUpdate == null) { this.DiskEncryptionSetUpdate = new DiskEncryptionSetUpdate(); } this.DiskEncryptionSetUpdate.RotationToLatestKeyVersionEnabled = this.RotationToLatestKeyVersionEnabled; } }
protected async Task DiskEncryptionSet_CRUD_Execute(string methodName, string location = null) { EnsureClientsInitialized(DefaultLocation); DiskRPLocation = location ?? DiskRPLocation; // Data var rgName = Recording.GenerateAssetName(TestPrefix); var desName = Recording.GenerateAssetName(DiskNamePrefix); DiskEncryptionSet des = GenerateDefaultDiskEncryptionSet(DiskRPLocation); await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(DiskRPLocation)); // Put DiskEncryptionSet DiskEncryptionSet desOut = await WaitForCompletionAsync(await DiskEncryptionSetsOperations.StartCreateOrUpdateAsync(rgName, desName, des)); Validate(des, desOut, desName); // Get DiskEncryptionSet desOut = await DiskEncryptionSetsOperations.GetAsync(rgName, desName); Validate(des, desOut, desName); // Patch DiskEncryptionSet const string tagKey = "tageKey"; var updateDes = new DiskEncryptionSetUpdate(); updateDes.Tags = new Dictionary <string, string>() { { tagKey, "tagvalue" } }; desOut = await WaitForCompletionAsync(await DiskEncryptionSetsOperations.StartUpdateAsync(rgName, desName, updateDes)); Validate(des, desOut, desName); Assert.AreEqual(1, desOut.Tags.Count); // Delete DiskEncryptionSet await WaitForCompletionAsync(await DiskEncryptionSetsOperations.StartDeleteAsync(rgName, desName)); try { // Ensure it was really deleted await DiskEncryptionSetsOperations.GetAsync(rgName, desName); Assert.False(true); } catch (Exception ex) { Assert.NotNull(ex); //Assert.AreEqual(HttpStatusCode.NotFound, ex.Response.StatusCode); } }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { if (ShouldProcess(this.Name, VerbsData.Update)) { string resourceGroupName; string diskEncryptionSetName; switch (this.ParameterSetName) { case "ResourceIdParameter": resourceGroupName = GetResourceGroupName(this.ResourceId); diskEncryptionSetName = GetResourceName(this.ResourceId, "Microsoft.Compute/diskEncryptionSets"); break; case "ObjectParameter": resourceGroupName = GetResourceGroupName(this.InputObject.Id); diskEncryptionSetName = GetResourceName(this.InputObject.Id, "Microsoft.Compute/diskEncryptionSets"); break; default: resourceGroupName = this.ResourceGroupName; diskEncryptionSetName = this.Name; break; } if (this.InputObject == null) { BuildPatchObject(); } else { BuildPutObject(); } DiskEncryptionSetUpdate diskEncryptionSetupdate = this.DiskEncryptionSetUpdate; DiskEncryptionSet parameter = new DiskEncryptionSet(); ComputeAutomationAutoMapperProfile.Mapper.Map <PSDiskEncryptionSet, DiskEncryptionSet>(this.InputObject, parameter); var result = (this.DiskEncryptionSetUpdate == null) ? DiskEncryptionSetsClient.CreateOrUpdate(resourceGroupName, diskEncryptionSetName, parameter) : DiskEncryptionSetsClient.Update(resourceGroupName, diskEncryptionSetName, diskEncryptionSetupdate); var psObject = new PSDiskEncryptionSet(); ComputeAutomationAutoMapperProfile.Mapper.Map <DiskEncryptionSet, PSDiskEncryptionSet>(result, psObject); WriteObject(psObject); } }); }
public Response Update(string resourceGroupName, string diskEncryptionSetName, DiskEncryptionSetUpdate diskEncryptionSet, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (diskEncryptionSetName == null) { throw new ArgumentNullException(nameof(diskEncryptionSetName)); } if (diskEncryptionSet == null) { throw new ArgumentNullException(nameof(diskEncryptionSet)); } using var message = CreateUpdateRequest(resourceGroupName, diskEncryptionSetName, diskEncryptionSet); _pipeline.Send(message, cancellationToken); switch (message.Response.Status) { case 200: case 202: return(message.Response); default: throw _clientDiagnostics.CreateRequestFailedException(message.Response); } }
internal HttpMessage CreateUpdateRequest(string resourceGroupName, string diskEncryptionSetName, DiskEncryptionSetUpdate diskEncryptionSet) { var message = _pipeline.CreateMessage(); var request = message.Request; request.Method = RequestMethod.Patch; var uri = new RawRequestUriBuilder(); uri.Reset(endpoint); uri.AppendPath("/subscriptions/", false); uri.AppendPath(subscriptionId, true); uri.AppendPath("/resourceGroups/", false); uri.AppendPath(resourceGroupName, true); uri.AppendPath("/providers/Microsoft.Compute/diskEncryptionSets/", false); uri.AppendPath(diskEncryptionSetName, true); uri.AppendQuery("api-version", "2020-12-01", true); request.Uri = uri; request.Headers.Add("Accept", "application/json"); request.Headers.Add("Content-Type", "application/json"); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(diskEncryptionSet); request.Content = content; message.SetProperty("UserAgentOverride", _userAgent); return(message); }
public virtual DiskEncryptionSetsUpdateOperation StartUpdate(string resourceGroupName, string diskEncryptionSetName, DiskEncryptionSetUpdate diskEncryptionSet, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (diskEncryptionSetName == null) { throw new ArgumentNullException(nameof(diskEncryptionSetName)); } if (diskEncryptionSet == null) { throw new ArgumentNullException(nameof(diskEncryptionSet)); } using var scope = _clientDiagnostics.CreateScope("DiskEncryptionSetsOperations.StartUpdate"); scope.Start(); try { var originalResponse = RestClient.Update(resourceGroupName, diskEncryptionSetName, diskEncryptionSet, cancellationToken); return(new DiskEncryptionSetsUpdateOperation(_clientDiagnostics, _pipeline, RestClient.CreateUpdateRequest(resourceGroupName, diskEncryptionSetName, diskEncryptionSet).Request, originalResponse)); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Updates (patches) a disk encryption set. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='diskEncryptionSetName'> /// The name of the disk encryption set that is being created. The name can't /// be changed after the disk encryption set is created. Supported characters /// for the name are a-z, A-Z, 0-9 and _. The maximum name length is 80 /// characters. /// </param> /// <param name='diskEncryptionSet'> /// disk encryption set object supplied in the body of the Patch disk /// encryption set operation. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <DiskEncryptionSetInner> UpdateAsync(this IDiskEncryptionSetsOperations operations, string resourceGroupName, string diskEncryptionSetName, DiskEncryptionSetUpdate diskEncryptionSet, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, diskEncryptionSetName, diskEncryptionSet, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
public async virtual Task <DiskEncryptionSetUpdateOperation> UpdateAsync(bool waitForCompletion, DiskEncryptionSetUpdate diskEncryptionSet, CancellationToken cancellationToken = default) { if (diskEncryptionSet == null) { throw new ArgumentNullException(nameof(diskEncryptionSet)); } using var scope = _diskEncryptionSetClientDiagnostics.CreateScope("DiskEncryptionSet.Update"); scope.Start(); try { var response = await _diskEncryptionSetRestClient.UpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, diskEncryptionSet, cancellationToken).ConfigureAwait(false); var operation = new DiskEncryptionSetUpdateOperation(ArmClient, _diskEncryptionSetClientDiagnostics, Pipeline, _diskEncryptionSetRestClient.CreateUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, diskEncryptionSet).Request, response); if (waitForCompletion) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Updates (patches) a disk encryption set. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='diskEncryptionSetName'> /// The name of the disk encryption set that is being created. The name can't /// be changed after the disk encryption set is created. Supported characters /// for the name are a-z, A-Z, 0-9 and _. The maximum name length is 80 /// characters. /// </param> /// <param name='diskEncryptionSet'> /// disk encryption set object supplied in the body of the Patch disk /// encryption set operation. /// </param> public static DiskEncryptionSet Update(this IDiskEncryptionSetsOperations operations, string resourceGroupName, string diskEncryptionSetName, DiskEncryptionSetUpdate diskEncryptionSet) { return(operations.UpdateAsync(resourceGroupName, diskEncryptionSetName, diskEncryptionSet).GetAwaiter().GetResult()); }
private void BuildPatchObject() { if (this.DiskEncryptionSetUpdate == null) { this.DiskEncryptionSetUpdate = new DiskEncryptionSetUpdate(); } if (this.IsParameterBound(c => c.KeyUrl)) { if (this.DiskEncryptionSetUpdate.ActiveKey == null) { //this.DiskEncryptionSetUpdate.ActiveKey = new KeyVaultAndKeyReference(); this.DiskEncryptionSetUpdate.ActiveKey = new KeyForDiskEncryptionSet(); } this.DiskEncryptionSetUpdate.ActiveKey.KeyUrl = this.KeyUrl; } if (this.IsParameterBound(c => c.SourceVaultId)) { if (this.DiskEncryptionSetUpdate.ActiveKey == null) { //this.DiskEncryptionSetUpdate.ActiveKey = new KeyVaultAndKeyReference(); this.DiskEncryptionSetUpdate.ActiveKey = new KeyForDiskEncryptionSet(); } if (this.DiskEncryptionSetUpdate.ActiveKey.SourceVault == null) { this.DiskEncryptionSetUpdate.ActiveKey.SourceVault = new SourceVault(); } this.DiskEncryptionSetUpdate.ActiveKey.SourceVault.Id = this.SourceVaultId; } if (this.IsParameterBound(c => c.Tag)) { this.DiskEncryptionSetUpdate.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value); } if (this.IsParameterBound(c => c.RotationToLatestKeyVersionEnabled)) { this.DiskEncryptionSetUpdate.RotationToLatestKeyVersionEnabled = this.RotationToLatestKeyVersionEnabled; } if (this.IsParameterBound(c => c.FederatedClientId)) { this.DiskEncryptionSetUpdate.FederatedClientId = this.FederatedClientId; } if (this.IsParameterBound(c => c.UserAssignedIdentity)) { if (this.DiskEncryptionSetUpdate.Identity == null) { this.DiskEncryptionSetUpdate.Identity = new EncryptionSetIdentity(); } if (this.DiskEncryptionSetUpdate.Identity.UserAssignedIdentities == null) { this.DiskEncryptionSetUpdate.Identity.UserAssignedIdentities = new Dictionary <string, EncryptionSetIdentityUserAssignedIdentitiesValue>(); } foreach (DictionaryEntry de in this.UserAssignedIdentity) { if (((Hashtable)de.Value).Count == 0) { this.DiskEncryptionSetUpdate.Identity.UserAssignedIdentities.Add(de.Key.ToString(), new EncryptionSetIdentityUserAssignedIdentitiesValue()); } else { string principalId = ((Hashtable)de.Value)["principalId"]?.ToString(); string clientId = ((Hashtable)de.Value)["clientId"]?.ToString(); this.DiskEncryptionSetUpdate.Identity.UserAssignedIdentities.Add(de.Key.ToString(), new EncryptionSetIdentityUserAssignedIdentitiesValue(principalId, clientId)); } } } }
public virtual ArmOperation <DiskEncryptionSet> Update(bool waitForCompletion, DiskEncryptionSetUpdate diskEncryptionSet, CancellationToken cancellationToken = default) { if (diskEncryptionSet == null) { throw new ArgumentNullException(nameof(diskEncryptionSet)); } using var scope = _diskEncryptionSetClientDiagnostics.CreateScope("DiskEncryptionSet.Update"); scope.Start(); try { var response = _diskEncryptionSetRestClient.Update(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, diskEncryptionSet, cancellationToken); var operation = new ComputeArmOperation <DiskEncryptionSet>(new DiskEncryptionSetOperationSource(Client), _diskEncryptionSetClientDiagnostics, Pipeline, _diskEncryptionSetRestClient.CreateUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, diskEncryptionSet).Request, response, OperationFinalStateVia.Location); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public async ValueTask <Response> UpdateAsync(string resourceGroupName, string diskEncryptionSetName, DiskEncryptionSetUpdate diskEncryptionSet, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (diskEncryptionSetName == null) { throw new ArgumentNullException(nameof(diskEncryptionSetName)); } if (diskEncryptionSet == null) { throw new ArgumentNullException(nameof(diskEncryptionSet)); } using var message = CreateUpdateRequest(resourceGroupName, diskEncryptionSetName, diskEncryptionSet); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 202: case 200: return(message.Response); default: throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); } }