async Task <string> IIamProvider.GetRequiredClaim(string policyName, IIamProviderCache cache) { string ret = cache.GetClaim(policyName); if (string.IsNullOrEmpty(ret)) { var policyId = await CreateOrGetPolicy(policyName); var policy = await _context.IamPolicyClaims .AsNoTracking() .FirstOrDefaultAsync(x => x.PolicyId.Equals(policyId)); ret = policy?.Claim; if (policy != null) { cache.AddOrUpdateClaim(policyName, ret); } } return(ret); }
async Task IIamProvider.AddClaim(string policyName, string claimValue, IIamProviderCache cache) { if (string.IsNullOrEmpty(cache.GetClaim(policyName))) { var policyId = await CreateOrGetPolicy(policyName); if (!(await _context.IamPolicyClaims.AnyAsync(x => x.PolicyId.Equals(policyId) && x.Claim == claimValue))) { var policyClaim = new Model.PolicyClaim <TKey>() { PolicyId = policyId, Claim = claimValue }; _context.IamPolicyClaims.Add(policyClaim); await _context.SaveChangesAsync(); cache.AddOrUpdateClaim(policyName, claimValue); } } }
Task <string> IIamProvider.GetRequiredClaim(string policyName, IIamProviderCache cache) { var ret = cache.GetClaim(policyName); return(Task.FromResult(ret)); }
public void AddOrUpdateClaimTest() { cache.AddOrUpdateClaim("resouce:operation", "resouce:operation"); Assert.AreEqual("resouce:operation", cache.GetClaim("resouce:operation")); }