|
|
|
|
@ -414,48 +414,111 @@ public class EventService : IEventService
@@ -414,48 +414,111 @@ public class EventService : IEventService
|
|
|
|
|
var orgAbilities = await _applicationCacheService.GetOrganizationAbilitiesAsync(); |
|
|
|
|
var eventMessages = new List<IEvent>(); |
|
|
|
|
|
|
|
|
|
foreach (var secret in secrets) |
|
|
|
|
if (IsBulkEventType(type)) |
|
|
|
|
{ |
|
|
|
|
if (!CanUseEvents(orgAbilities, secret.OrganizationId)) |
|
|
|
|
var secretsByOrg = secrets.GroupBy(s => s.OrganizationId); |
|
|
|
|
|
|
|
|
|
foreach (var group in secretsByOrg) |
|
|
|
|
{ |
|
|
|
|
continue; |
|
|
|
|
var orgId = group.Key; |
|
|
|
|
|
|
|
|
|
if (!CanUseEvents(orgAbilities, orgId)) |
|
|
|
|
{ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
IEnumerable<Guid> secretIds = group.Select(s => s.Id); |
|
|
|
|
|
|
|
|
|
var e = new EventMessage(_currentContext) |
|
|
|
|
{ |
|
|
|
|
OrganizationId = orgId, |
|
|
|
|
Type = type, |
|
|
|
|
SecretIds = string.Join(",", secretIds.Select(id => id.ToString())), |
|
|
|
|
UserId = userId, |
|
|
|
|
Date = date.GetValueOrDefault(DateTime.UtcNow) |
|
|
|
|
}; |
|
|
|
|
eventMessages.Add(e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var e = new EventMessage(_currentContext) |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
foreach (var secret in secrets) |
|
|
|
|
{ |
|
|
|
|
OrganizationId = secret.OrganizationId, |
|
|
|
|
Type = type, |
|
|
|
|
SecretId = secret.Id, |
|
|
|
|
UserId = userId, |
|
|
|
|
Date = date.GetValueOrDefault(DateTime.UtcNow) |
|
|
|
|
}; |
|
|
|
|
eventMessages.Add(e); |
|
|
|
|
if (!CanUseEvents(orgAbilities, secret.OrganizationId)) |
|
|
|
|
{ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var e = new EventMessage(_currentContext) |
|
|
|
|
{ |
|
|
|
|
OrganizationId = secret.OrganizationId, |
|
|
|
|
Type = type, |
|
|
|
|
SecretId = secret.Id, |
|
|
|
|
UserId = userId, |
|
|
|
|
Date = date.GetValueOrDefault(DateTime.UtcNow) |
|
|
|
|
}; |
|
|
|
|
eventMessages.Add(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await _eventWriteService.CreateManyAsync(eventMessages); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool IsBulkEventType(EventType type) |
|
|
|
|
{ |
|
|
|
|
return type == EventType.Secrets_Retrieved_Bulk || type == EventType.Secrets_Deleted_Bulk; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task LogServiceAccountSecretsEventAsync(Guid serviceAccountId, IEnumerable<Secret> secrets, EventType type, DateTime? date = null) |
|
|
|
|
{ |
|
|
|
|
var orgAbilities = await _applicationCacheService.GetOrganizationAbilitiesAsync(); |
|
|
|
|
var eventMessages = new List<IEvent>(); |
|
|
|
|
|
|
|
|
|
foreach (var secret in secrets) |
|
|
|
|
if (IsBulkEventType(type)) |
|
|
|
|
{ |
|
|
|
|
if (!CanUseEvents(orgAbilities, secret.OrganizationId)) |
|
|
|
|
var secretsByOrg = secrets.GroupBy(s => s.OrganizationId); |
|
|
|
|
|
|
|
|
|
foreach (var group in secretsByOrg) |
|
|
|
|
{ |
|
|
|
|
continue; |
|
|
|
|
var orgId = group.Key; |
|
|
|
|
|
|
|
|
|
if (!CanUseEvents(orgAbilities, orgId)) |
|
|
|
|
{ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
IEnumerable<Guid> secretIds = group.Select(s => s.Id); |
|
|
|
|
|
|
|
|
|
var e = new EventMessage(_currentContext) |
|
|
|
|
{ |
|
|
|
|
OrganizationId = orgId, |
|
|
|
|
Type = type, |
|
|
|
|
SecretIds = string.Join(",", secretIds.Select(id => id.ToString())), |
|
|
|
|
UserId = serviceAccountId, |
|
|
|
|
Date = date.GetValueOrDefault(DateTime.UtcNow) |
|
|
|
|
}; |
|
|
|
|
eventMessages.Add(e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var e = new EventMessage(_currentContext) |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
foreach (var secret in secrets) |
|
|
|
|
{ |
|
|
|
|
OrganizationId = secret.OrganizationId, |
|
|
|
|
Type = type, |
|
|
|
|
SecretId = secret.Id, |
|
|
|
|
ServiceAccountId = serviceAccountId, |
|
|
|
|
Date = date.GetValueOrDefault(DateTime.UtcNow) |
|
|
|
|
}; |
|
|
|
|
eventMessages.Add(e); |
|
|
|
|
if (!CanUseEvents(orgAbilities, secret.OrganizationId)) |
|
|
|
|
{ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var e = new EventMessage(_currentContext) |
|
|
|
|
{ |
|
|
|
|
OrganizationId = secret.OrganizationId, |
|
|
|
|
Type = type, |
|
|
|
|
SecretId = secret.Id, |
|
|
|
|
ServiceAccountId = serviceAccountId, |
|
|
|
|
Date = date.GetValueOrDefault(DateTime.UtcNow) |
|
|
|
|
}; |
|
|
|
|
eventMessages.Add(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await _eventWriteService.CreateManyAsync(eventMessages); |
|
|
|
|
|