/// <summary> /// Initializes a new instance of the <see cref="Conjur.Resource"/> class. /// </summary> /// <param name="client">Conjur client used to manipulate this resource.</param> /// <param name="kind">Resource kind.</param> /// <param name="name">Resource name.</param> internal Resource(Client client, string kind, string name) { this.Client = client; this.kind = kind; this.Name = name; this.Id = $"{client.GetAccountName()}:{kind}:{Name}"; }
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)); }
internal Policy(Client client, string name) : base(client, Constants.KIND_POLICY, name) { this.path = string.Join("/", new string[] { "policies", Uri.EscapeDataString(client.GetAccountName()), Constants.KIND_POLICY, Uri.EscapeDataString(name) }); }
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); }
/// <summary> /// Initializes a new instance of the <see cref="Conjur.Role"/> class. /// </summary> /// <param name="client">Conjur client to use to connect.</param> /// <param name="kind">Kind of the role, for example 'group' or 'layer'.</param> /// <param name="name">The Role name.</param> internal Role(Client client, string kind, string name) : base(client, kind, name) { this.path = $"authz/{WebUtility.UrlEncode(client.GetAccountName())}/roles/{WebUtility.UrlEncode(kind)}/{WebUtility.UrlEncode(name)}"; }
internal static IEnumerable <Variable> List(Client client, string query = null, uint limit = 10000, uint offset = 0) { Func <ResourceMetadata, Variable> newInst = (searchRes) => new Variable(client, IdToName(searchRes.Id, client.GetAccountName(), Constants.KIND_VARIABLE)); return(ListResources <Variable, ResourceMetadata>(client, Constants.KIND_VARIABLE, newInst, query, limit, offset)); }
/// <summary> /// Initializes a new instance of the <see cref="Conjur.Variable"/> class. /// </summary> /// <param name="client">Conjur client to use to connect.</param> /// <param name="name">The variable name.</param> /// <seealso cref="Extensions.Variable"/> internal Variable(Client client, string name) : base(client, Constants.KIND_VARIABLE, name) { this.path = $"secrets/{Uri.EscapeDataString(client.GetAccountName())}/{Constants.KIND_VARIABLE}/{Uri.EscapeDataString(name)}"; }
/// <summary> /// List of Users. /// </summary> /// <param name="client">Conjur Client to query.</param> /// <param name="query">Query to search.</param> /// <returns>Returns IEnumerable to User.</returns> internal static IEnumerable <User> List(Client client, string query = null, uint limit = 10000, uint offset = 0) { Func <ResourceMetadata, User> newInst = (searchRes) => new User(client, IdToName(searchRes.Id, client.GetAccountName(), Constants.KIND_USER)); return(ListResources <User, ResourceMetadata>(client, Constants.KIND_USER, newInst, query, limit, offset)); }