public virtual Response <JitRequestDefinition> RemoveTag(string key, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException($"{nameof(key)} provided cannot be null or a whitespace.", nameof(key)); } using var scope = _clientDiagnostics.CreateScope("JitRequestDefinition.RemoveTag"); scope.Start(); try { var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue.Remove(key); TagResource.CreateOrUpdate(originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _jitRequestsRestClient.Get(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, cancellationToken); return(Response.FromValue(new JitRequestDefinition(this, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <JitRequestDefinition> SetTags(IDictionary <string, string> tags, CancellationToken cancellationToken = default) { if (tags == null) { throw new ArgumentNullException($"{nameof(tags)} provided cannot be null.", nameof(tags)); } using var scope = _clientDiagnostics.CreateScope("JitRequestDefinition.SetTags"); scope.Start(); try { TagResource.Delete(cancellationToken: cancellationToken); var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue.ReplaceWith(tags); TagResource.CreateOrUpdate(originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _restClient.Get(Id.ResourceGroupName, Id.Name, cancellationToken); return(Response.FromValue(new JitRequestDefinition(this, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Add a tag to the current resource. /// </summary> /// <param name="key"> The key for the tag. </param> /// <param name="value"> The value for the tag. </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> AddTag(string key, string value, 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.AddTag"); scope.Start(); try { var originalTags = TagResource.Get(cancellationToken).Value; originalTags.Data.Properties.TagsValue[key] = value; TagResource.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 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; } }