public IBucket CreateBucket(string bucketName, IClusterCredentials credentials = null)
        {
            var password = string.Empty;

            if (credentials == null)
            {
                //try to find a password in configuration
                BucketConfiguration bucketConfig;
                if (_clientConfig.BucketConfigs.TryGetValue(bucketName, out bucketConfig) &&
                    bucketConfig.Password != null)
                {
                    bucketName = bucketConfig.BucketName;
                    password   = bucketConfig.Password;
                }
            }
            else
            {
                var bucketCreds = credentials.GetCredentials(AuthContext.BucketKv, bucketName);
                if (bucketCreds.ContainsKey(bucketName))
                {
                    password = bucketCreds[bucketName];
                }
                else
                {
                    throw new BucketNotFoundException(string.Format("Could not find credentials for bucket: {0}", bucketName));
                }
            }
            return(CreateBucket(bucketName, password, credentials));
        }
Пример #2
0
        /// <summary>
        /// Creates a <see cref="IClusterManager" /> object that uses the current <see cref="ICluster" /> configuration settings
        /// and <see cref="IClusterCredentials" /> for authentication.
        /// </summary>
        /// <returns>
        /// A <see cref="IClusterManager" /> instance that uses the current <see cref="ICluster" /> configuration settings
        /// and <see cref="IClusterCredentials" /> for authentication.
        /// </returns>
        /// <exception cref="AuthenticationException">
        /// No credentials found. Please add them via <see cref="ICluster.Authenticate"/>.
        /// </exception>
        public IClusterManager CreateManager()
        {
            if (_credentials == null)
            {
                throw new AuthenticationException("No credentials found.");
            }

            var clusterCreds = _credentials.GetCredentials(AuthContext.ClusterMgmt).FirstOrDefault();

            if (clusterCreds.Key == null || clusterCreds.Value == null)
            {
                throw new AuthenticationException("No credentials found.");
            }
            return(CreateManager(clusterCreds.Key, clusterCreds.Value));
        }
 public IBucket CreateBucket(string bucketName, IClusterCredentials credentials = null)
 {
     var password = string.Empty;
     if (credentials == null)
     {
         //try to find a password in configuration
         BucketConfiguration bucketConfig;
         if (_clientConfig.BucketConfigs.TryGetValue(bucketName, out bucketConfig)
             && bucketConfig.Password != null)
         {
             bucketName = bucketConfig.BucketName;
             password = bucketConfig.Password;
         }
     }
     else
     {
         var bucketCreds = credentials.GetCredentials(AuthContext.BucketKv, bucketName);
         if (bucketCreds.ContainsKey(bucketName))
         {
             password = bucketCreds[bucketName];
         }
         else
         {
             throw new BucketNotFoundException(string.Format("Could not find credentials for bucket: {0}", bucketName));
         }
     }
     return CreateBucket(bucketName, password, credentials);
 }