mirror of
https://github.com/bitwarden/server.git
synced 2025-07-09 11:54:41 -05:00
[SM-394] Secrets Manager (#2164)
Long lived feature branch for Secrets Manager Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> Co-authored-by: cd-bitwarden <106776772+cd-bitwarden@users.noreply.github.com> Co-authored-by: CarleyDiaz-Bitwarden <103955722+CarleyDiaz-Bitwarden@users.noreply.github.com> Co-authored-by: Thomas Avery <tavery@bitwarden.com> Co-authored-by: Colton Hurst <colton@coltonhurst.com>
This commit is contained in:
44
src/Infrastructure.Dapper/Repositories/ApiKeyRepository.cs
Normal file
44
src/Infrastructure.Dapper/Repositories/ApiKeyRepository.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Settings;
|
||||
using Dapper;
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class ApiKeyRepository : Repository<ApiKey, Guid>, IApiKeyRepository
|
||||
{
|
||||
public ApiKeyRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
||||
{ }
|
||||
|
||||
public ApiKeyRepository(string connectionString, string readOnlyConnectionString)
|
||||
: base(connectionString, readOnlyConnectionString)
|
||||
{ }
|
||||
|
||||
public async Task<ApiKeyDetails> GetDetailsByIdAsync(Guid id)
|
||||
{
|
||||
using var connection = new SqlConnection(ConnectionString);
|
||||
// When adding different key details, we should change the QueryAsync type to match the database data,
|
||||
// but cast it to the appropriate data model.
|
||||
var results = await connection.QueryAsync<ServiceAccountApiKeyDetails>(
|
||||
$"[{Schema}].[ApiKeyDetails_ReadById]",
|
||||
new { Id = id },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.SingleOrDefault();
|
||||
}
|
||||
|
||||
public async Task<ICollection<ApiKey>> GetManyByServiceAccountIdAsync(Guid serviceAccountId)
|
||||
{
|
||||
using var connection = new SqlConnection(ConnectionString);
|
||||
var results = await connection.QueryAsync<ApiKey>(
|
||||
$"[{Schema}].[ApiKey_ReadByServiceAccountId]",
|
||||
new { ServiceAccountId = serviceAccountId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user