Skip to content

Commit

Permalink
Merge pull request #20 from devlead/feature/dependencies
Browse files Browse the repository at this point in the history
Update dependencies & Migrate to Azure Identity
  • Loading branch information
devlead authored Aug 29, 2023
2 parents ffcab67 + e84fe35 commit cf71ed6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.101",
"version": "7.0.400",
"rollForward": "latestFeature",
"allowPrerelease": false
}
Expand Down
2 changes: 1 addition & 1 deletion src/SqlBulkSyncFunction/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
(settings, configuration) => configuration.GetSection(nameof(SyncJobsConfig)).Bind(settings));
configure
.AddSingleton<Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProvider>()
.AddSingleton<Azure.Identity.DefaultAzureCredential>()
.AddSingleton<IAzureSqlTokenService, AzureSqlTokenService>()
.AddSingleton<IProcessSyncJobService, ProcessSyncJobService>()
.AddSingleton<ITokenCacheService, TokenCacheService>();
Expand Down
35 changes: 24 additions & 11 deletions src/SqlBulkSyncFunction/Services/AzureSqlTokenService.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
using System.Threading.Tasks;
using Microsoft.Azure.Services.AppAuthentication;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;

namespace SqlBulkSyncFunction.Services
namespace SqlBulkSyncFunction.Services;

public record AzureSqlTokenService(DefaultAzureCredential DefaultAzureCredential) : IAzureSqlTokenService
{
// ReSharper disable once UnusedMember.Global
public record AzureSqlTokenService(AzureServiceTokenProvider AzureServiceTokenProvider) : IAzureSqlTokenService
{
private const string AzureSqlResourceId = "https://database.windows.net/";

public async Task<string> GetAccessToken(string tenantId)
=> await AzureServiceTokenProvider.GetAccessTokenAsync(AzureSqlResourceId, string.IsNullOrWhiteSpace(tenantId) ? null : tenantId);
}
private const string AzureSqlResourceId = "https://database.windows.net/";
private static AccessToken? AccessToken = default;


public async Task<string> GetAccessToken(string tenantId)
=> (
AccessToken is { } validToken && validToken.ExpiresOn < DateTimeOffset.UtcNow.AddMinutes(5)
? validToken
: (AccessToken = await DefaultAzureCredential.GetTokenAsync(
new TokenRequestContext(
new[] { AzureSqlResourceId },
tenantId: string.IsNullOrWhiteSpace(tenantId) ? null : tenantId
)
)
).Value
).Token;
}

22 changes: 11 additions & 11 deletions src/SqlBulkSyncFunction/SqlBulkSyncFunction.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AsyncEnumerator" Version="4.0.2" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="5.0.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.10.0" />
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.6.2" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" />
<PackageReference Include="Dapper" Version="2.0.151" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="6.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.14.1" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.19.0" />
<PackageReference Include="Azure.Identity" Version="1.10.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
Expand Down Expand Up @@ -49,8 +49,8 @@
</PackageReference>
<PackageReference Include="NuGetizer" Version="0.9.1" PrivateAssets="all" />
<PackageFile Include="**/*.cs" Exclude="obj/**;bin/**" PackagePath="$(ContentTargetFolders)\cs\$(TargetFramework)\WCOM\%(RelativeDir)%(Filename)%(Extension)" />
<None Include="../../LICENSE" Pack="true" PackagePath="$(PackageLicenseFile)"/>
<None Include="../../README.md" Pack="true" PackagePath=""/>
<None Include="../WCOM128x128_squares.png" Pack="true" PackagePath=""/>
<None Include="../../LICENSE" Pack="true" PackagePath="$(PackageLicenseFile)" />
<None Include="../../README.md" Pack="true" PackagePath="" />
<None Include="../WCOM128x128_squares.png" Pack="true" PackagePath="" />
</ItemGroup>
</Project>

0 comments on commit cf71ed6

Please sign in to comment.