Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR To support DbDataSource for Postgresql #1832

Merged
merged 10 commits into from
Jun 30, 2023

Conversation

michaelmairegger
Copy link
Contributor

@michaelmairegger michaelmairegger commented May 31, 2023

This PR adds DbDataSource support for postgresql to allow password rotation using UsePeriodicPasswordProvider

This PR allows the following:

var dataSourceBuilder = new NpgsqlDataSourceBuilder(connectionString);

dataSourceBuilder.UsePeriodicPasswordProvider(async (settings, cancellationToken) =>
{
    var sqlServerTokenProvider = new DefaultAzureCredential();
    var tokenAsync = await sqlServerTokenProvider.GetTokenAsync(new TokenRequestContext(scopes: new[] { "https://ossrdbms-aad.database.windows.net/.default" }), cancellationToken);
    return tokenAsync.Token;
},
TimeSpan.FromMinutes(55), // Interval for refreshing the token
TimeSpan.FromSeconds(5));
        
var dbDataSource = dataSourceBuilder.Build();


builder.Services.AddHealthChecks()
    .AddNpgSql(e => dbDataSource);

closes #1813

@michaelmairegger
Copy link
Contributor Author

@dotnet-policy-service agree

@codecov-commenter
Copy link

Codecov Report

Merging #1832 (75642cd) into master (5325c5d) will decrease coverage by 0.02%.
The diff coverage is 80.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master    #1832      +/-   ##
==========================================
- Coverage   66.98%   66.96%   -0.02%     
==========================================
  Files         212      212              
  Lines        7744     7750       +6     
  Branches      527      529       +2     
==========================================
+ Hits         5187     5190       +3     
- Misses       2422     2425       +3     
  Partials      135      135              
Flag Coverage Δ
Npgsql 28.90% <80.00%> (+0.75%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rc/HealthChecks.NpgSql/NpgSqlHealthCheckOptions.cs 66.66% <33.33%> (-33.34%) ⬇️
...ncyInjection/NpgSqlHealthCheckBuilderExtensions.cs 72.72% <100.00%> (+2.72%) ⬆️
src/HealthChecks.NpgSql/NpgSqlHealthCheck.cs 86.36% <100.00%> (-4.12%) ⬇️

@sungam3r
Copy link
Collaborator

@michaelmairegger Thanks.

@sungam3r sungam3r merged commit ad6d0e4 into Xabaril:master Jun 30, 2023
@michaelmairegger michaelmairegger deleted the feature/npgsql/dbdatasource branch June 30, 2023 14:42
@sungam3r sungam3r mentioned this pull request Jul 30, 2023
@michaelmairegger
Copy link
Contributor Author

@sungam3r when can we expect to get this released?

@sungam3r
Copy link
Collaborator

sungam3r commented Dec 3, 2023

It was released in https://www.nuget.org/packages/AspNetCore.HealthChecks.NpgSql/7.0.0 4 months ago.

@michaelmairegger
Copy link
Contributor Author

@sungam3r Oops, my bad. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AspNetCore.HealthChecks.NpgSql (Postgres) health check and Managed Identity on Azure
4 participants