Exemplo n.º 1
0
        private static async Task <HttpApiTransport> GetTransportAsync(ArangoDbOptions options)
        {
            if (!string.IsNullOrWhiteSpace(options.JwtToken))
            {
                return(HttpApiTransport.UsingJwtAuth(new Uri(options.HostUri), options.Database, options.JwtToken));
            }

            if (options.IsGenerateJwtTokenBasedOnUserNameAndPassword)
            {
                if (string.IsNullOrWhiteSpace(options.UserName))
                {
                    throw new ArgumentNullException(nameof(options.UserName));
                }
                if (string.IsNullOrWhiteSpace(options.Password))
                {
                    throw new ArgumentNullException(nameof(options.Password));
                }

                var transport        = HttpApiTransport.UsingNoAuth(new Uri(options.HostUri), options.Database);
                var authClient       = new AuthApiClient(transport);
                var jwtTokenResponse = await authClient.GetJwtTokenAsync(options.UserName, options.Password);

                transport.SetJwtToken(jwtTokenResponse.Jwt);
                return(transport);
            }

            if (!string.IsNullOrWhiteSpace(options.UserName) && !string.IsNullOrWhiteSpace(options.Password))
            {
                return(HttpApiTransport.UsingBasicAuth(new Uri(options.HostUri), options.Database, options.UserName, options.Password));
            }

            return(HttpApiTransport.UsingNoAuth(new Uri(options.HostUri), options.Database));
        }
Exemplo n.º 2
0
 public ArangoDbHealthCheck(ArangoDbOptions options)
 {
     _options = options ?? throw new ArgumentNullException(nameof(options));
 }