public static IKuduClient KuduClient( this ICakeContext context, KuduClientSettings settings) { return(new KuduClient( context ?? throw new ArgumentNullException(nameof(context)), settings ?? throw new ArgumentNullException(nameof(settings)))); }
/// <summary> /// Initializes a new instance of the <see cref="KuduClient"/> class. /// </summary> /// <param name="context">The Cake context.</param> /// <param name="settings">The provider settings.</param> internal KuduClient( ICakeContext context, KuduClientSettings settings) { Context = context ?? throw new ArgumentNullException(nameof(context)); Settings = settings ?? throw new ArgumentNullException(nameof(settings)); if (string.IsNullOrWhiteSpace(settings.BaseUri)) { throw new ArgumentNullException(nameof(settings), "Invalid base uri specified."); } if (string.IsNullOrWhiteSpace(settings.UserName)) { throw new ArgumentNullException(nameof(settings), "Invalid user name specified."); } if (string.IsNullOrWhiteSpace(settings.Password)) { throw new ArgumentNullException(nameof(settings), "Invalid password specified."); } HttpClient GetDefaultHttpClient() { var credentials = new NetworkCredential(settings.UserName, settings.Password); var handler = new HttpClientHandler { Credentials = credentials }; return(new HttpClient(handler) { Timeout = settings.Timeout, DefaultRequestHeaders = { { "If-Match", "*" }, }, }); } HttpClient = settings.HttpClientCustomization == null ? GetDefaultHttpClient() : settings.HttpClientCustomization(settings, GetDefaultHttpClient()) ?? throw new NullReferenceException("KuduClientSettings HttpClientCustomization returned null."); }