mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 00:52:49 -05:00
[PM-5645] Cosmos DB Grant Storage (#3634)
* table storage grants * simple shard on storage accounts * use is not * cosmos grant repo * remove single storage connection string * some fixes to dapper grant repo * pattern matching * add fallback to base PersistedGrantStore * service collection extension cleanup * cleanup * remove unused Id * empty string rowkey * fix sharding method logic * ttl for cosmos * make ttl an int * fixes to cosmos implementation * fix partition key values * catch notfound exceptions * indenting * update grantitem with custom serialization * use new transform helpers * grantloader perf test tool * ref * remove grant loader project * remove table storage implementation * remove table storage stuff * all redis fallback to build to null * revert sln file change * EOF new line * remove trailing comma * lint fixes * add grant to names * move cosmos serilaizer to utils * add some .net 8 keyed service comments * EnableContentResponseOnWrite * Fix type in EF grant repository
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using AutoMapper;
|
||||
using Bit.Core.Auth.Models.Data;
|
||||
using Bit.Core.Auth.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Auth.Models;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
@ -42,7 +43,7 @@ public class GrantRepository : BaseEntityFrameworkRepository, IGrantRepository
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Core.Auth.Entities.Grant> GetByKeyAsync(string key)
|
||||
public async Task<IGrant> GetByKeyAsync(string key)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
@ -55,7 +56,7 @@ public class GrantRepository : BaseEntityFrameworkRepository, IGrantRepository
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<Core.Auth.Entities.Grant>> GetManyAsync(string subjectId, string sessionId, string clientId, string type)
|
||||
public async Task<ICollection<IGrant>> GetManyAsync(string subjectId, string sessionId, string clientId, string type)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
@ -67,26 +68,31 @@ public class GrantRepository : BaseEntityFrameworkRepository, IGrantRepository
|
||||
g.Type == type
|
||||
select g;
|
||||
var grants = await query.ToListAsync();
|
||||
return (ICollection<Core.Auth.Entities.Grant>)grants;
|
||||
return (ICollection<IGrant>)grants;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SaveAsync(Core.Auth.Entities.Grant obj)
|
||||
public async Task SaveAsync(IGrant obj)
|
||||
{
|
||||
if (obj is not Core.Auth.Entities.Grant gObj)
|
||||
{
|
||||
throw new ArgumentException(null, nameof(obj));
|
||||
}
|
||||
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var existingGrant = await (from g in dbContext.Grants
|
||||
where g.Key == obj.Key
|
||||
where g.Key == gObj.Key
|
||||
select g).FirstOrDefaultAsync();
|
||||
if (existingGrant != null)
|
||||
{
|
||||
obj.Id = existingGrant.Id;
|
||||
dbContext.Entry(existingGrant).CurrentValues.SetValues(obj);
|
||||
gObj.Id = existingGrant.Id;
|
||||
dbContext.Entry(existingGrant).CurrentValues.SetValues(gObj);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = Mapper.Map<Grant>(obj);
|
||||
var entity = Mapper.Map<Grant>(gObj);
|
||||
await dbContext.AddAsync(entity);
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
Reference in New Issue
Block a user