public async Task DropUserAsync(string username, DropUserOptions?options = null)
        {
            options ??= DropUserOptions.Default;
            var uri = GetUsersUri(options.DomainNameValue, username);

            _logger.LogInformation("Attempting to drop user with username {username} - {uri}",
                                   _redactor.UserData(username), _redactor.SystemData(uri));

            try
            {
                // drop user
                var result = await _client.DeleteAsync(uri, options.TokenValue).ConfigureAwait(false);

                if (result.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new UserNotFoundException(username);
                }

                result.EnsureSuccessStatusCode();
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, $"Error trying to drop user with username {username} - {uri}",
                                 _redactor.UserData(username), _redactor.SystemData(uri));
                throw;
            }
        }
        public async Task DropCollectionAsync(CollectionSpec spec, DropCollectionOptions?options = null)
        {
            options ??= DropCollectionOptions.Default;
            var uri = GetUri(RestApi.DeleteCollections(_bucketName, spec.ScopeName, spec.Name));

            _logger.LogInformation("Attempting drop collection {spec.ScopeName}/{spec.Name} - {uri}", spec.ScopeName,
                                   spec.Name, _redactor.SystemData(uri));

            try
            {
                // drop collection
                var createResult = await _client.DeleteAsync(uri, options.TokenValue).ConfigureAwait(false);

                if (createResult.StatusCode != HttpStatusCode.OK)
                {
                    var contentBody = await createResult.Content.ReadAsStringAsync();

                    if (contentBody.Contains("collection_not_found"))
                    {
                        throw new CollectionNotFoundException(spec.ScopeName, spec.Name);
                    }
                    throw new CouchbaseException(contentBody);
                }
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "Failed to drop collection {spec.ScopeName}/{spec.Name} - {uri}", spec.ScopeName,
                                 spec.Name, _redactor.SystemData(uri));
                throw;
            }
        }
Exemplo n.º 3
0
        public async Task DropIndexAsync(string indexName, DropSearchIndexOptions?options = null)
        {
            options ??= DropSearchIndexOptions.Default;
            var baseUri = GetIndexUri(indexName);

            _logger.LogInformation("Trying to drop index with name {indexName} - {baseUri}",
                                   _redactor.MetaData(indexName), _redactor.SystemData(baseUri));

            try
            {
                var result = await _client.DeleteAsync(baseUri, options.TokenValue).ConfigureAwait(false);

                if (result.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new SearchIndexNotFound(indexName);
                }

                result.EnsureSuccessStatusCode();
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "Failed to drop index with name {indexName} - {baseUri}",
                                 _redactor.MetaData(indexName), _redactor.SystemData(baseUri));
                throw;
            }
        }
        public async Task DropBucketAsync(string bucketName, DropBucketOptions?options = null)
        {
            options ??= new DropBucketOptions();
            var uri = GetUri(bucketName);

            _logger.LogInformation("Attempting to drop bucket with name {bucketName} - {uri}",
                                   _redactor.MetaData(bucketName), _redactor.SystemData(uri));

            try
            {
                // perform drop
                var result = await _client.DeleteAsync(uri, options.TokenValue).ConfigureAwait(false);

                if (result.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new BucketNotFoundException(bucketName);
                }

                result.EnsureSuccessStatusCode();
            }
            catch (BucketNotFoundException)
            {
                _logger.LogError("Unable to drop bucket with name {bucketName} because it does not exist",
                                 _redactor.MetaData(bucketName));
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "Failed to drop bucket with name {bucketName}",
                                 _redactor.MetaData(bucketName));
                throw;
            }
        }
Exemplo n.º 5
0
        public async Task DropDesignDocumentAsync(string designDocName, DesignDocumentNamespace @namespace, DropDesignDocumentOptions?options = null)
        {
            options ??= DropDesignDocumentOptions.Default;
            var uri = GetUri(designDocName, @namespace);

            _logger.LogInformation($"Attempting to drop design document {_bucketName}/{designDocName} - {uri}");

            try
            {
                var result = await _client.DeleteAsync(uri, options.TokenValue).ConfigureAwait(false);

                if (result.StatusCode == HttpStatusCode.NotFound)
                {
                    _logger.LogError($"Failed to drop design document {_bucketName}/{designDocName} because it does not exist - {uri}");
                    throw new DesignDocumentNotFound(_bucketName, designDocName);
                }

                result.EnsureSuccessStatusCode();
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, $"Failed to drop design document {_bucketName}/{designDocName} - {uri}");
                throw;
            }
        }
Exemplo n.º 6
0
        public async Task DropCollectionAsync(CollectionSpec spec, DropCollectionOptions?options = null)
        {
            options ??= DropCollectionOptions.Default;
            var uri = GetUri(spec.ScopeName, spec.Name);

            _logger.LogInformation($"Attempting drop collection {spec.ScopeName}/{spec.Name} - {uri}");

            try
            {
                // drop collection
                var createResult = await _client.DeleteAsync(uri, options.TokenValue).ConfigureAwait(false);

                createResult.EnsureSuccessStatusCode();
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, $"Failed to drop collection {spec.ScopeName}/{spec.Name} - {uri}");
                throw;
            }
        }
Exemplo n.º 7
0
 public async Task DropLinkAsync(string linkName, string dataverseName, DropAnalyticsLinkOptions?options = null)
 {
     _ = linkName ?? throw new ArgumentNullException(nameof(linkName));
     _ = dataverseName ?? throw new ArgumentNullException(nameof(dataverseName));
     options ??= new();
     try
     {
         var dummy   = new GeneralAnalyticsLinkResponse(linkName, dataverseName);
         var builder = new UriBuilder(_serviceUriProvider.GetRandomAnalyticsUri());
         builder.Path = dummy.ManagementPath;
         var uri    = builder.Uri;
         var result = await _couchbaseHttpClient.DeleteAsync(uri, options.CancellationToken).ConfigureAwait(false);
         await HandleLinkManagementResultErrors(result, linkName, dataverseName);
     }
     catch (Exception exception)
     {
         _logger.LogError(exception, "Failed to delete link.");
         throw;
     }
 }