-
Notifications
You must be signed in to change notification settings - Fork 48
Add a license status check to ensure the RavenDB license is correctly applied after the database is created before configuring expiration #5235
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
Merged
mauroservienti
merged 9 commits into
master
from
check-license-status-before-configuring-expiration
Dec 19, 2025
+86
−0
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5ea391c
Add a license status check to ensure the RavenDB licence is correctly…
mauroservienti 40e0258
record type
ramonsmits e7456ff
Using `/` would override BaseAddress path value
ramonsmits 9120804
ReadFromJsonAsync
ramonsmits 36fd29e
fix
ramonsmits 903539f
As we are not re-using HttpClient it can be immediately disposed
ramonsmits 1fa9f5d
Forward cancellation token
ramonsmits dbd04c6
Improve license validation logic and exception handling
ramonsmits d8d206e
Add a comment for posterity
mauroservienti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
41 changes: 41 additions & 0 deletions
41
src/ServiceControl.Audit.Persistence.RavenDB/LicenseStatusCheck.cs
This file contains hidden or 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,41 @@ | ||
| namespace ServiceControl.Audit.Persistence.RavenDB; | ||
|
|
||
| using System; | ||
| using System.Net.Http; | ||
| using System.Net.Http.Json; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| static class LicenseStatusCheck | ||
| { | ||
| record LicenseStatusFragment(string Id, string LicensedTo, string Status, bool Expired); | ||
|
|
||
| public static async Task WaitForLicenseOrThrow(DatabaseConfiguration configuration, CancellationToken cancellationToken) | ||
| { | ||
| using var client = new HttpClient | ||
| { | ||
| BaseAddress = new Uri(configuration.ServerConfiguration.ConnectionString ?? configuration.ServerConfiguration.ServerUrl) | ||
| }; | ||
|
|
||
| // Not linking to the incoming cancellationToken to ensure no OperationCancelledException prevents the last InvalidOperationException to be thrown | ||
| using var cts = new CancellationTokenSource(30_000); | ||
| while (!cts.IsCancellationRequested) | ||
| { | ||
| var httpResponse = await client.GetAsync("license/status", cancellationToken); | ||
| var licenseStatus = await httpResponse.Content.ReadFromJsonAsync<LicenseStatusFragment>(cancellationToken); | ||
| if (licenseStatus.Expired) | ||
| { | ||
| throw new InvalidOperationException("The current RavenDB license is expired. Please, contact support"); | ||
| } | ||
|
|
||
| if (licenseStatus.LicensedTo != null && licenseStatus.Id != null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| await Task.Delay(200, cancellationToken); | ||
| } | ||
|
|
||
| throw new InvalidOperationException("Cannot validate the current RavenDB license. Please, contact support"); | ||
| } | ||
| } | ||
This file contains hidden or 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
41 changes: 41 additions & 0 deletions
41
src/ServiceControl.Persistence.RavenDB/LicenseStatusCheck.cs
This file contains hidden or 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,41 @@ | ||
| namespace ServiceControl.Persistence.RavenDB; | ||
|
|
||
| using System; | ||
| using System.Net.Http; | ||
| using System.Net.Http.Json; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| static class LicenseStatusCheck | ||
| { | ||
| record LicenseStatusFragment(string Id, string LicensedTo, string Status, bool Expired); | ||
|
|
||
| public static async Task WaitForLicenseOrThrow(RavenPersisterSettings configuration, CancellationToken cancellationToken) | ||
| { | ||
| using var client = new HttpClient | ||
| { | ||
| BaseAddress = new Uri(configuration.ConnectionString ?? configuration.ServerUrl) | ||
| }; | ||
|
|
||
| // Not linking to the incoming cancellationToken to ensure no OperationCancelledException prevents the last InvalidOperationException to be thrown | ||
| using var cts = new CancellationTokenSource(30_000); | ||
| while (!cts.IsCancellationRequested) | ||
| { | ||
| var httpResponse = await client.GetAsync("license/status", cancellationToken); | ||
| var licenseStatus = await httpResponse.Content.ReadFromJsonAsync<LicenseStatusFragment>(cancellationToken); | ||
| if (licenseStatus.Expired) | ||
| { | ||
| throw new InvalidOperationException("The current RavenDB license is expired. Please, contact support"); | ||
| } | ||
|
|
||
| if (licenseStatus.LicensedTo != null && licenseStatus.Id != null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| await Task.Delay(200, cancellationToken); | ||
| } | ||
|
|
||
| throw new InvalidOperationException("Cannot validate the current RavenDB license. Please, contact support"); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.