public AuthenticatedRequest ( string path ) : |
||
path | string | Path, NOT including the leading slash. |
Résultat |
internal static uint CountResources(Client client, string kind, string query = null) { string pathCountResourceQuery = $"resources/{client.GetAccountName()}/{kind}?count=true" + ((query != null) ? $"&search={query}" : string.Empty); CountResult countJsonObj = JsonSerializer <CountResult> .Read(client.AuthenticatedRequest(pathCountResourceQuery)); return(Convert.ToUInt32(countJsonObj.Count)); }
/// <summary> /// Loading a Conjur policy MAML stream structure /// into given policy name, over REST POST request. /// </summary> /// <param name="policyContent">Stream valid MAML Conjur policy strature.</param> /// <returns>Policy creation response as a stream.</returns> public Stream LoadPolicy(Stream policyContent) { WebRequest loadPolicyRequest = Client.AuthenticatedRequest(this.path); loadPolicyRequest.Method = WebRequestMethods.Http.Post; loadPolicyRequest.ContentLength = policyContent.Length; policyContent.Seek(0, SeekOrigin.Begin); using (Stream reqStream = loadPolicyRequest.GetRequestStream()) { policyContent.CopyTo(reqStream); WebResponse loadPolicyResponse = loadPolicyRequest.GetResponse(); return(loadPolicyResponse.GetResponseStream()); } }
internal static IEnumerable <T> ListResources <T, TResult>(Client client, string kind, Func <TResult, T> newT, string query = null, uint limit = 10000, uint offset = 0) { List <TResult> resultList; do { string pathListResourceQuery = $"resources/{client.GetAccountName()}/{kind}?offset={offset}&limit={limit}" + ((query != null) ? $"&search={query}" : string.Empty); resultList = JsonSerializer <List <TResult> > .Read(client.AuthenticatedRequest(pathListResourceQuery)); foreach (TResult searchResult in resultList) { yield return(newT(searchResult)); } offset += (uint)resultList.Count; } while (resultList.Count > 0 && offset % limit == 0); }
/// <summary> /// List or Search for resources. Generic method that can be adapted to various kinds of resources. /// To reduce overhead, list is retrieved in chunks behind the scenes. /// </summary> /// <param name="newT">A method that gets as arguments TResult and returns new instance of type T.</param> /// <param name="client">Conjur client to query.</param> /// <param name="kind">Resource kind to query.</param> /// <param name="query">Query for search.</param> /// <returns>Returns IEnumerable<T>.</returns> internal static IEnumerable <T> ListResources <T, TResult>(Client client, string kind, Func <TResult, T> newT, string query = null) { uint offset = 0; List <TResult> resultList; do { string urlWithParams = $"authz/{WebUtility.UrlEncode(client.GetAccountName())}/resources/{kind}?offset={offset}" + $"&limit={LIMIT_SEARCH_VAR_LIST_RETURNED}" + ((query != null) ? $"&search={query}" : string.Empty) + ((client.ActingAs != null) ? $"&acting_as={client.ActingAs}" : string.Empty); resultList = JsonSerializer <List <TResult> > .Read(client.AuthenticatedRequest(urlWithParams)); foreach (TResult searchVarResult in resultList) { yield return(newT(searchVarResult)); } offset += (uint)resultList.Count; } while (resultList.Count > 0); }