-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into renovate/lock-file-maintenance
- Loading branch information
Showing
57 changed files
with
9,625 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
bitwarden_license/src/Commercial.Core/SecretsManager/Queries/Secrets/SecretsSyncQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#nullable enable | ||
using Bit.Core.Exceptions; | ||
using Bit.Core.SecretsManager.Entities; | ||
using Bit.Core.SecretsManager.Models.Data; | ||
using Bit.Core.SecretsManager.Queries.Secrets.Interfaces; | ||
using Bit.Core.SecretsManager.Repositories; | ||
|
||
namespace Bit.Commercial.Core.SecretsManager.Queries.Secrets; | ||
|
||
public class SecretsSyncQuery : ISecretsSyncQuery | ||
{ | ||
private readonly ISecretRepository _secretRepository; | ||
private readonly IServiceAccountRepository _serviceAccountRepository; | ||
|
||
public SecretsSyncQuery( | ||
ISecretRepository secretRepository, | ||
IServiceAccountRepository serviceAccountRepository) | ||
{ | ||
_secretRepository = secretRepository; | ||
_serviceAccountRepository = serviceAccountRepository; | ||
} | ||
|
||
public async Task<(bool HasChanges, IEnumerable<Secret>? Secrets)> GetAsync(SecretsSyncRequest syncRequest) | ||
{ | ||
if (syncRequest.LastSyncedDate == null) | ||
{ | ||
return await GetSecretsAsync(syncRequest); | ||
} | ||
|
||
var serviceAccount = await _serviceAccountRepository.GetByIdAsync(syncRequest.ServiceAccountId); | ||
if (serviceAccount == null) | ||
{ | ||
throw new NotFoundException(); | ||
} | ||
|
||
if (syncRequest.LastSyncedDate.Value <= serviceAccount.RevisionDate) | ||
{ | ||
return await GetSecretsAsync(syncRequest); | ||
} | ||
|
||
return (HasChanges: false, null); | ||
} | ||
|
||
private async Task<(bool HasChanges, IEnumerable<Secret>? Secrets)> GetSecretsAsync(SecretsSyncRequest syncRequest) | ||
{ | ||
var secrets = await _secretRepository.GetManyByOrganizationIdAsync(syncRequest.OrganizationId, | ||
syncRequest.ServiceAccountId, syncRequest.AccessClientType); | ||
return (HasChanges: true, Secrets: secrets); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.