internal static IEnumerable <T> ParseGetSearchResponse <T>(HttpResponseMessage response) { if (response == null) { throw new ArgumentNullException("response", "The http response message to parse cannot be null."); } if (response.IsSuccessStatusCode) { CommandHelpers.UpdateSessionDataCookieFromResponse(response); return(JsonConvert.DeserializeObject <IEnumerable <T> >(response.Content.ReadAsStringAsync().Result)); } else { throw new InfobloxCustomException(response); } }
internal static string ParsePostPutDeleteResponse(HttpResponseMessage response) { if (response == null) { throw new ArgumentNullException("response", "The http response message to parse cannot be null."); } if (response.IsSuccessStatusCode) { CommandHelpers.UpdateSessionDataCookieFromResponse(response); return(response.Content.ReadAsStringAsync().Result.Replace("\"", "")); } else { throw new InfobloxCustomException(response); } }
internal static object ParseGetResponse(HttpResponseMessage response, Type type) { if (response == null) { throw new ArgumentNullException("response", "The http response message to parse cannot be null."); } if (type == null) { throw new ArgumentNullException("type", "The type to parse the response message to cannot be null"); } if (response.IsSuccessStatusCode) { CommandHelpers.UpdateSessionDataCookieFromResponse(response); return(JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result.Trim(_charsToTrim), type)); } else { throw new InfobloxCustomException(response); } }
public static async Task <HttpClient> BuildHttpClient(string gridMaster, string apiVersion, TimeSpan?timeout = null) { if (!String.IsNullOrEmpty(gridMaster)) { if (!String.IsNullOrEmpty(apiVersion)) { if (await CommandHelpers.CheckConnection(gridMaster)) { if (InfobloxSessionData.UseSessionData) { if (InfobloxSessionData.Cookie != null && !InfobloxSessionData.Cookie.Expired) { HttpClientHandler Handler = new HttpClientHandler() { CookieContainer = new CookieContainer() }; if (!apiVersion.StartsWith("v")) { apiVersion = $"v{apiVersion}"; } Uri Address = new Uri("https://" + gridMaster + "/wapi/" + apiVersion + "/"); Handler.CookieContainer.Add(Address, InfobloxSessionData.Cookie); Handler.ServerCertificateCustomValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; HttpClient Client = new HttpClient(Handler) { BaseAddress = Address }; //The actual default is 100 seconds if (timeout != null) { Client.Timeout = (TimeSpan)timeout; } return(Client); } else { throw new Exception("There is not a valid cookie to utilize, you must specify a credential."); } } else { throw new Exception("There is not a valid cookie to utilize, you must specify a credential."); } } else { throw new WebException("The grid master could not be contacted."); } } else { throw new ArgumentNullException("apiVersion", "The api version parameter cannot be null or empty."); } } else { throw new ArgumentNullException("gridMaster", "The value for the grid master cannot be null or empty."); } }
/// <summary> /// Builds a full URL search request including the object type, the query, and the fields to return /// </summary> /// <typeparam name="T">An actual infoblox object class type.</typeparam> /// <param name="search">The type of search to be performed.</param> /// <param name="searchField">The field to search on.</param> /// <param name="recordValue">The value to search for.</param> /// <returns></returns> internal static string BuildGetSearchRequest <T>(SearchType search, string searchField, string recordValue, IEnumerable <string> fieldsToReturn) { return(CommandHelpers.BuildGetSearchRequest(typeof(T), search, searchField, recordValue, fieldsToReturn)); }
public static async Task <HttpClient> BuildHttpClient(string gridMaster, string apiVersion, string username, SecureString password, TimeSpan?timeout = null) { if (!String.IsNullOrEmpty(gridMaster)) { if (!String.IsNullOrEmpty(apiVersion)) { if (!String.IsNullOrEmpty(username)) { if (password != null) { if (await CommandHelpers.CheckConnection(gridMaster)) { HttpClientHandler Handler = new HttpClientHandler(); Handler.ServerCertificateCustomValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; if (!apiVersion.StartsWith("v")) { apiVersion = $"v{apiVersion}"; } HttpClient Client = new HttpClient(Handler) { BaseAddress = new Uri("https://" + gridMaster + "/wapi/" + apiVersion + "/") }; //The actual default is 100 seconds if (timeout != null) { Client.Timeout = (TimeSpan)timeout; } Client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(username + ":" + SecureStringHelper.ToReadableString(password)))); return(Client); } else { throw new WebException("The grid master could not be contacted."); } } else { throw new ArgumentNullException("password", "The provided password cannot be null."); } } else { throw new ArgumentNullException("username", "The username used to connect to the grid master cannot be null or empty."); } } else { throw new ArgumentNullException("apiVersion", "The api version parameter cannot be null or empty."); } } else { throw new ArgumentNullException("gridMaster", "The value for the grid master cannot be null or empty."); } }
public static async Task <HttpClient> BuildHttpClient(string gridMaster, string apiVersion, Cookie cookie, TimeSpan?timeout = null) { if (!String.IsNullOrEmpty(gridMaster)) { if (!String.IsNullOrEmpty(apiVersion)) { if (cookie != null) { if (!cookie.Expired) { if (await CommandHelpers.CheckConnection(gridMaster)) { HttpClientHandler Handler = new HttpClientHandler() { CookieContainer = new CookieContainer() }; if (!apiVersion.StartsWith("v")) { apiVersion = $"v{apiVersion}"; } Uri Address = new Uri("https://" + gridMaster + "/wapi/" + apiVersion + "/"); Handler.CookieContainer.Add(Address, cookie); Handler.ServerCertificateCustomValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; HttpClient Client = new HttpClient(Handler) { BaseAddress = Address }; //The actual default timeout is 100 seconds if (timeout != null) { Client.Timeout = (TimeSpan)timeout; } return(Client); } else { throw new WebException("The grid master could not be contacted."); } } else { throw new ArgumentException($"The provided cookie is expired, it expired on {cookie.Expires.ToUniversalTime().ToString()} UTC"); } } else { throw new ArgumentNullException("cookie", "Cookie cannot be null"); } } else { throw new ArgumentNullException("apiVersion", "The api version parameter cannot be null or empty."); } } else { throw new ArgumentNullException("gridMaster", "The value for the grid master cannot be null or empty."); } }