-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(summary): Add key vault and fusion sql token support (#666)
- [x] New feature - [ ] Bug fix - [ ] High impact **Description of work:** <!--- Please give a description of the work ---> [AB#55619](https://statoil-proview.visualstudio.com/787035c2-8cf2-4d73-a83e-bb0e6d937eec/_workitems/edit/55619) This adds the keyvault support and azure sql token support. I've tested connecting to the Summary CI database which works. **Testing:** - [ ] Can be tested - [ ] Automatic tests created / updated - [x] Local tests are passing <!--- Please give a description of how this can be tested ---> **Checklist:** - [ ] Considered automated tests - [ ] Considered updating specification / documentation - [x] Considered work items - [x] Considered security - [x] Performed developer testing - [x] Checklist finalized / ready for review <!--- Other comments --->
- Loading branch information
1 parent
1008b27
commit 9bc94fd
Showing
4 changed files
with
68 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Azure.Identity; | ||
|
||
namespace Fusion.Summary.Api; | ||
|
||
public static class ConfigurationExtensions | ||
{ | ||
public static void AddKeyVault(this WebApplicationBuilder builder) | ||
{ | ||
var configuration = builder.Configuration; | ||
var clientId = configuration["AzureAd:ClientId"]; | ||
var tenantId = configuration["AzureAd:TenantId"]; | ||
var clientSecret = configuration["AzureAd:ClientSecret"]; | ||
var keyVaultUrl = configuration["KEYVAULT_URL"]; | ||
|
||
if (string.IsNullOrWhiteSpace(keyVaultUrl)) | ||
{ | ||
Console.WriteLine("Skipping key vault as url is null, empty or whitespace."); | ||
return; | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(clientSecret)) | ||
{ | ||
Console.WriteLine("Skipping key vault as clientSecret is null, empty or whitespace."); | ||
return; | ||
} | ||
|
||
var credential = new ClientSecretCredential(tenantId, clientId, clientSecret); | ||
configuration.AddAzureKeyVault(new Uri(keyVaultUrl), credential); | ||
} | ||
} |
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,19 @@ | ||
using Fusion.Infrastructure.Database; | ||
using Fusion.Integration.Configuration; | ||
|
||
namespace Fusion.Summary.Api.Database; | ||
|
||
public class SqlTokenProvider : ISqlTokenProvider | ||
{ | ||
private readonly IFusionTokenProvider fusionTokenProvider; | ||
|
||
public SqlTokenProvider(IFusionTokenProvider fusionTokenProvider) | ||
{ | ||
this.fusionTokenProvider = fusionTokenProvider; | ||
} | ||
|
||
public Task<string> GetAccessTokenAsync() | ||
{ | ||
return fusionTokenProvider.GetApplicationTokenAsync("https://database.windows.net/"); | ||
} | ||
} |
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