public async Task <Result> CreateAsync(Action <UserPermissionsCreateAction> action, CancellationToken cancellationToken = new CancellationToken()) { cancellationToken.RequestCanceled(LogInfo); var impl = new UserPermissionsCreateActionImpl(); action(impl); DefinedUserPermissions settings = impl.Settings.Value; string username = impl.Username.Value; string vhost = impl.VirtualHost.Value; if (string.IsNullOrWhiteSpace(username)) { throw new UserCredentialsMissingException("The username and/or password is missing."); } if (string.IsNullOrWhiteSpace(vhost)) { throw new VirtualHostMissingException("The name of the virtual host is missing."); } string sanitizedVHost = vhost.SanitizeVirtualHostName(); string url = $"api/permissions/{sanitizedVHost}/{username}"; HttpResponseMessage response = await HttpPut(url, settings, cancellationToken); Result result = response.GetResponse(); LogInfo($"Sent request to RabbitMQ server to create user '{username}'"); return(result); }
public async Task <Result> Create(Action <UserPermissionsCreateAction> action, CancellationToken cancellationToken = default) { cancellationToken.RequestCanceled(); var impl = new UserPermissionsCreateActionImpl(); action(impl); DefinedUserPermissions definition = impl.Definition.Value; Debug.Assert(definition != null); string username = impl.Username.Value; string vhost = impl.VirtualHost.Value; var errors = new List <Error>(); if (string.IsNullOrWhiteSpace(username)) { errors.Add(new ErrorImpl("The username and/or password is missing.")); } if (string.IsNullOrWhiteSpace(vhost)) { errors.Add(new ErrorImpl("The name of the virtual host is missing.")); } if (errors.Any()) { return(new FaultedResult(errors)); } string url = $"api/permissions/{SanitizeVirtualHostName(vhost)}/{username}"; Result result = await Put(url, definition, cancellationToken); return(result); }