public async virtual Task <Response <JitRequest> > RemoveTagAsync(string key, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrWhiteSpace(key, nameof(key)); using var scope = _jitRequestClientDiagnostics.CreateScope("JitRequest.RemoveTag"); scope.Start(); try { var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.Properties.TagsValue.Remove(key); await TagResource.CreateOrUpdateAsync(true, originalTags.Value.Data, cancellationToken : cancellationToken).ConfigureAwait(false); var originalResponse = await _jitRequestRestClient.GetAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, cancellationToken).ConfigureAwait(false); return(Response.FromValue(new JitRequest(ArmClient, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual async Task <Response <DeploymentScript> > RemoveTagAsync(string key, CancellationToken cancellationToken = default) { Argument.AssertNotNull(key, nameof(key)); using var scope = _deploymentScriptClientDiagnostics.CreateScope("DeploymentScript.RemoveTag"); scope.Start(); try { var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.TagValues.Remove(key); await TagResource.CreateOrUpdateAsync(WaitUntil.Completed, originalTags.Value.Data, cancellationToken : cancellationToken).ConfigureAwait(false); var originalResponse = await _deploymentScriptRestClient.GetAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, cancellationToken).ConfigureAwait(false); return(Response.FromValue(new DeploymentScript(Client, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task <Response <TemplateSpecVersion> > AddTagAsync(string key, string value, CancellationToken cancellationToken = default) { Argument.AssertNotNull(key, nameof(key)); Argument.AssertNotNull(value, nameof(value)); using var scope = _templateSpecVersionClientDiagnostics.CreateScope("TemplateSpecVersion.AddTag"); scope.Start(); try { var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.TagValues[key] = value; await TagResource.CreateOrUpdateAsync(true, originalTags.Value.Data, cancellationToken : cancellationToken).ConfigureAwait(false); var originalResponse = await _templateSpecVersionRestClient.GetAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, cancellationToken).ConfigureAwait(false); return(Response.FromValue(new TemplateSpecVersion(Client, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <GenericResource> RemoveTag(string key, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key), $"{nameof(key)} provided cannot be null or a whitespace."); } using var scope = _clientDiagnostics.CreateScope("GenericResource.RemoveTag"); scope.Start(); try { var apiVersion = GetApiVersion(cancellationToken); var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagValues.Remove(key); TagResource.CreateOrUpdate(true, originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _resourcesRestClient.GetById(Id, apiVersion, cancellationToken); return(Response.FromValue(new GenericResource(Client, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <JitRequest> SetTags(IDictionary <string, string> tags, CancellationToken cancellationToken = default) { if (tags == null) { throw new ArgumentNullException(nameof(tags), $"{nameof(tags)} provided cannot be null."); } using var scope = _jitRequestClientDiagnostics.CreateScope("JitRequest.SetTags"); scope.Start(); try { TagResource.Delete(true, cancellationToken: cancellationToken); var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue.ReplaceWith(tags); TagResource.CreateOrUpdate(true, originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _jitRequestRestClient.Get(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, cancellationToken); return(Response.FromValue(new JitRequest(ArmClient, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Removes a tag by key from the resource. /// </summary> /// <param name="key"> The key of the tag to remove. </param> /// <param name="cancellationToken"> A token to allow the caller to cancel the call to the service. The default value is <see cref="CancellationToken.None" />. </param> /// <returns> The updated resource with the tag added. </returns> public virtual Response <ResourceGroup> RemoveTag(string key, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentException($"{nameof(key)} provided cannot be null or a whitespace.", nameof(key)); } using var scope = _clientDiagnostics.CreateScope("ResourceGroup.RemoveTag"); scope.Start(); try { var originalTags = TagResource.Get(cancellationToken).Value; originalTags.Data.Properties.TagsValue.Remove(key); TagContainer.CreateOrUpdate(originalTags.Data, cancellationToken: cancellationToken); var originalResponse = _restClient.Get(Id.Name, cancellationToken); return(Response.FromValue(new ResourceGroup(this, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task <Response <Deployment> > AddTagAsync(string key, string value, CancellationToken cancellationToken = default) { Argument.AssertNotNull(key, nameof(key)); Argument.AssertNotNull(value, nameof(value)); using var scope = _deploymentClientDiagnostics.CreateScope("Deployment.AddTag"); scope.Start(); try { var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.Properties.TagsValue[key] = value; await TagResource.CreateOrUpdateAsync(true, originalTags.Value.Data, cancellationToken : cancellationToken).ConfigureAwait(false); var originalResponse = await _deploymentRestClient.GetAtScopeAsync(Id.Parent, Id.Name, cancellationToken).ConfigureAwait(false); return(Response.FromValue(new Deployment(Client, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }