mirror of
https://github.com/bitwarden/server.git
synced 2025-07-16 15:17:33 -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:
77
src/Core/Auth/Models/Data/GrantItem.cs
Normal file
77
src/Core/Auth/Models/Data/GrantItem.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Bit.Core.Auth.Repositories.Cosmos;
|
||||
using Duende.IdentityServer.Models;
|
||||
|
||||
namespace Bit.Core.Auth.Models.Data;
|
||||
|
||||
public class GrantItem : IGrant
|
||||
{
|
||||
public GrantItem() { }
|
||||
|
||||
public GrantItem(PersistedGrant pGrant)
|
||||
{
|
||||
Key = pGrant.Key;
|
||||
Type = pGrant.Type;
|
||||
SubjectId = pGrant.SubjectId;
|
||||
SessionId = pGrant.SessionId;
|
||||
ClientId = pGrant.ClientId;
|
||||
Description = pGrant.Description;
|
||||
CreationDate = pGrant.CreationTime;
|
||||
ExpirationDate = pGrant.Expiration;
|
||||
ConsumedDate = pGrant.ConsumedTime;
|
||||
Data = pGrant.Data;
|
||||
SetTtl();
|
||||
}
|
||||
|
||||
public GrantItem(IGrant g)
|
||||
{
|
||||
Key = g.Key;
|
||||
Type = g.Type;
|
||||
SubjectId = g.SubjectId;
|
||||
SessionId = g.SessionId;
|
||||
ClientId = g.ClientId;
|
||||
Description = g.Description;
|
||||
CreationDate = g.CreationDate;
|
||||
ExpirationDate = g.ExpirationDate;
|
||||
ConsumedDate = g.ConsumedDate;
|
||||
Data = g.Data;
|
||||
SetTtl();
|
||||
}
|
||||
|
||||
[JsonPropertyName("id")]
|
||||
[JsonConverter(typeof(Base64IdStringConverter))]
|
||||
public string Key { get; set; }
|
||||
[JsonPropertyName("typ")]
|
||||
public string Type { get; set; }
|
||||
[JsonPropertyName("sub")]
|
||||
public string SubjectId { get; set; }
|
||||
[JsonPropertyName("sid")]
|
||||
public string SessionId { get; set; }
|
||||
[JsonPropertyName("cid")]
|
||||
public string ClientId { get; set; }
|
||||
[JsonPropertyName("des")]
|
||||
public string Description { get; set; }
|
||||
[JsonPropertyName("cre")]
|
||||
public DateTime CreationDate { get; set; } = DateTime.UtcNow;
|
||||
[JsonPropertyName("exp")]
|
||||
public DateTime? ExpirationDate { get; set; }
|
||||
[JsonPropertyName("con")]
|
||||
public DateTime? ConsumedDate { get; set; }
|
||||
[JsonPropertyName("data")]
|
||||
public string Data { get; set; }
|
||||
// https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/how-to-time-to-live?tabs=dotnet-sdk-v3#set-time-to-live-on-an-item-using-an-sdk
|
||||
[JsonPropertyName("ttl")]
|
||||
public int Ttl { get; set; } = -1;
|
||||
|
||||
public void SetTtl()
|
||||
{
|
||||
if (ExpirationDate != null)
|
||||
{
|
||||
var sec = (ExpirationDate.Value - DateTime.UtcNow).TotalSeconds;
|
||||
if (sec > 0)
|
||||
{
|
||||
Ttl = (int)sec;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
15
src/Core/Auth/Models/Data/IGrant.cs
Normal file
15
src/Core/Auth/Models/Data/IGrant.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace Bit.Core.Auth.Models.Data;
|
||||
|
||||
public interface IGrant
|
||||
{
|
||||
string Key { get; set; }
|
||||
string Type { get; set; }
|
||||
string SubjectId { get; set; }
|
||||
string SessionId { get; set; }
|
||||
string ClientId { get; set; }
|
||||
string Description { get; set; }
|
||||
DateTime CreationDate { get; set; }
|
||||
DateTime? ExpirationDate { get; set; }
|
||||
DateTime? ConsumedDate { get; set; }
|
||||
string Data { get; set; }
|
||||
}
|
Reference in New Issue
Block a user