< Summary

Information
Class: dotnet_etcd.DependencyInjection.EtcdClientOptions
Assembly: dotnet-etcd
File(s): /home/runner/work/dotnet-etcd/dotnet-etcd/dotnet-etcd/DependencyInjection/EtcdClientOptions.cs
Line coverage
76%
Covered lines: 16
Uncovered lines: 5
Coverable lines: 21
Total lines: 84
Line coverage: 76.1%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_ConnectionString()100%11100%
get_Port()100%11100%
get_ServerName()100%11100%
get_ConfigureChannel()100%11100%
get_Interceptors()100%11100%
get_UseInsecureChannel()100%11100%
get_CallCredentials()100%11100%
get_ConfigureSslOptions()100%210%
get_EnableRetryPolicy()100%11100%
ApplyTo(...)66.66%7666.66%

File(s)

/home/runner/work/dotnet-etcd/dotnet-etcd/dotnet-etcd/DependencyInjection/EtcdClientOptions.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Net.Http;
 6using System.Net.Security;
 7using Grpc.Core;
 8using Grpc.Core.Interceptors;
 9using Grpc.Net.Client;
 10
 11namespace dotnet_etcd.DependencyInjection;
 12
 13/// <summary>
 14///     Options for configuring an EtcdClient instance.
 15/// </summary>
 16public class EtcdClientOptions
 17{
 18    /// <summary>
 19    ///     Gets or sets the connection string for the etcd server.
 20    /// </summary>
 5221    public string ConnectionString { get; set; }
 22
 23    /// <summary>
 24    ///     Gets or sets the port to connect to. Default is 2379.
 25    /// </summary>
 4926    public int Port { get; set; } = 2379;
 27
 28    /// <summary>
 29    ///     Gets or sets the server name. Default is "my-etcd-server".
 30    /// </summary>
 2631    public string ServerName { get; set; } = "my-etcd-server";
 32
 33    /// <summary>
 34    ///     Gets or sets the action to configure the gRPC channel options.
 35    /// </summary>
 636    public Action<GrpcChannelOptions> ConfigureChannel { get; set; }
 37
 38    /// <summary>
 39    ///     Gets or sets the interceptors to apply to gRPC calls.
 40    /// </summary>
 641    public Interceptor[] Interceptors { get; set; }
 42
 43    /// <summary>
 44    ///     Gets or sets a value indicating whether to use insecure credentials (no SSL).
 45    ///     Setting this to true will automatically configure the channel with ChannelCredentials.Insecure.
 46    /// </summary>
 947    public bool UseInsecureChannel { get; set; }
 48
 49    /// <summary>
 50    ///     Gets or sets the authorization credentials. If set, this will be used to create the channel credentials.
 51    /// </summary>
 152    public CallCredentials CallCredentials { get; set; }
 53
 54    /// <summary>
 55    ///     Gets or sets the action to configure SSL client authentication options.
 56    ///     Use this to configure custom SSL certificates for self-signed certificates.
 57    /// </summary>
 058    public Action<SslClientAuthenticationOptions> ConfigureSslOptions { get; set; }
 59
 60    /// <summary>
 61    ///     Gets or sets a value indicating whether to enable retry policy.
 62    /// </summary>
 1463    public bool EnableRetryPolicy { get; set; } = true;
 64
 65    /// <summary>
 66    ///     Applies the options to the channel options.
 67   /// </summary>
 68    /// <param name="options">The gRPC channel options to configure.</param>
 69    internal void ApplyTo(GrpcChannelOptions options)
 570    {
 571        if (UseInsecureChannel)
 472        {
 473            options.Credentials = ChannelCredentials.Insecure;
 474        }
 175        else if (CallCredentials != null)
 076        {
 077            ChannelCredentials channelCredentials = ChannelCredentials.Create(new SslCredentials(), CallCredentials);
 078            options.Credentials = channelCredentials;
 079        }
 80
 81        // Apply custom configuration if provided
 582        ConfigureChannel?.Invoke(options);
 583    }
 84}