Esempio n. 1
0
        private async Task Authenticate(IConnection connection)
        {
            var sasl          = new PlainSaslMechanism(_configuration.UserName, _configuration.Password);
            var authenticated = await sasl.AuthenticateAsync(connection).ConfigureAwait(false);

            if (authenticated)
            {
                var completionSource = new TaskCompletionSource <bool>();
                var selectBucketOp   = new SelectBucket
                {
                    Converter  = new DefaultConverter(),
                    Transcoder = new DefaultTranscoder(new DefaultConverter()),
                    Key        = Name,
                    Completed  = s =>
                    {
                        //Status will be Success if bucket select was bueno
                        completionSource.SetResult(s.Status == ResponseStatus.Success);
                        return(completionSource.Task);
                    }
                };

                await connection.SendAsync(selectBucketOp.Write(), selectBucketOp.Completed)
                .ConfigureAwait(false);
            }
            else
            {
                //cache exception for later use when op is used
            }
        }
Esempio n. 2
0
        public static async Task Authenticate(this IConnection connection, ClusterOptions clusterOptions, string bucketName)
        {
            var sasl          = new PlainSaslMechanism(clusterOptions.UserName, clusterOptions.Password);
            var authenticated = await sasl.AuthenticateAsync(connection).ConfigureAwait(false);

            if (!authenticated)
            {
                throw new AuthenticationException($"Cannot authenticate {bucketName}");
            }
        }