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 IIamProvider.AddClaim(string policyName, string claimValue, IIamProviderCache cache) { cache.AddOrUpdateClaim(policyName, claimValue); return(Task.CompletedTask); }
public void AddOrUpdateClaimTest() { cache.AddOrUpdateClaim("resouce:operation", "resouce:operation"); Assert.AreEqual("resouce:operation", cache.GetClaim("resouce:operation")); }