Skip to content

Commit 9b588f7

Browse files
authored
Merge pull request #52 from GarageGroup/feature/use-managed-identity
Feature/use managed identity
2 parents db68996 + c322a12 commit 9b588f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+330
-302
lines changed

.github/workflows/publish.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,18 @@ jobs:
110110
package: ./publish/${{ vars.AZURE_ARTIFACT_NAME }}-${{ steps.get_version.outputs.version }}.zip
111111

112112
- name: Log out of Azure
113-
run: az logout
113+
run: az logout
114+
115+
ping-test:
116+
runs-on: ubuntu-latest
117+
needs: deploy-to-test
118+
119+
steps:
120+
- name: Ping Health Check URL
121+
uses: jtalk/url-health-check-action@v3
122+
with:
123+
url: https://${{ vars.TEST_WEBAPP_NAME }}.azurewebsites.net/api/health?code=${{ secrets.TEST_BOTFUNC_KEY }}
124+
follow-redirect: false
125+
max-attempts: 3
126+
retry-delay: 5s
127+
retry-all: false

.github/workflows/web-deploy-prod.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,18 @@ jobs:
3939
package: ./publish/${{ vars.AZURE_ARTIFACT_NAME }}-${{ steps.get_version.outputs.version }}.zip
4040

4141
- name: Log out of Azure
42-
run: az logout
42+
run: az logout
43+
44+
ping:
45+
runs-on: ubuntu-latest
46+
needs: deploy
47+
48+
steps:
49+
- name: Ping Health Check URL
50+
uses: jtalk/url-health-check-action@v3
51+
with:
52+
url: https://${{ vars.PROD_WEBAPP_NAME }}.azurewebsites.net/api/health?code=${{ secrets.PROD_BOTFUNC_KEY }}
53+
follow-redirect: false
54+
max-attempts: 3
55+
retry-delay: 5s
56+
retry-all: false

.github/workflows/web-deploy-test.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,18 @@ jobs:
3939
package: ./publish/${{ vars.AZURE_ARTIFACT_NAME }}-${{ steps.get_version.outputs.version }}.zip
4040

4141
- name: Log out of Azure
42-
run: az logout
42+
run: az logout
43+
44+
ping:
45+
runs-on: ubuntu-latest
46+
needs: deploy
47+
48+
steps:
49+
- name: Ping Health Check URL
50+
uses: jtalk/url-health-check-action@v3
51+
with:
52+
url: https://${{ vars.TEST_WEBAPP_NAME }}.azurewebsites.net/api/health?code=${{ secrets.TEST_BOTFUNC_KEY }}
53+
follow-redirect: false
54+
max-attempts: 3
55+
retry-delay: 5s
56+
retry-all: false
Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
using System;
2-
using System.Text;
3-
using GarageGroup.Infra;
1+
using GarageGroup.Infra;
2+
using GarageGroup.Infra.Bot.Builder;
43
using Microsoft.Azure.Functions.Worker;
5-
using Microsoft.Data.SqlClient;
6-
using Microsoft.Extensions.Configuration;
74
using Microsoft.Extensions.DependencyInjection;
85
using PrimeFuncPack;
96

@@ -13,36 +10,32 @@ partial class Application
1310
{
1411
internal static void Configure(IFunctionsWorkerApplicationBuilder builder)
1512
=>
16-
builder.Services.RegisterDataverseApi().RegisterSqlApi();
13+
builder.Services.RegisterCosmosStorage().RegisterDataverseApi().RegisterSqlApi();
14+
15+
private static IServiceCollection RegisterCosmosStorage(this IServiceCollection services)
16+
=>
17+
PrimaryHandler.UseStandardSocketsHttpHandler()
18+
.UseLogging("CosmosStorage")
19+
.UseTokenCredentialResource()
20+
.UsePollyStandard()
21+
.UseCosmosStorage("CosmosDb")
22+
.ToRegistrar(services)
23+
.RegisterScoped();
1724

1825
private static IServiceCollection RegisterDataverseApi(this IServiceCollection services)
1926
=>
20-
UseHttpMessageHandlerStandard("DataverseApi")
27+
PrimaryHandler.UseStandardSocketsHttpHandler()
28+
.UseLogging("DataverseApi")
29+
.UseTokenCredentialStandard()
30+
.UsePollyStandard()
2131
.UseDataverseApiClient(DataverseSectionName)
2232
.ToRegistrar(services)
2333
.RegisterScoped();
2434

2535
private static IServiceCollection RegisterSqlApi(this IServiceCollection services)
2636
=>
27-
MicrosoftDbProvider.Configure(ResolveDataverseDbProviderOption)
37+
DataverseDbProvider.Configure(DataverseSectionName)
2838
.UseSqlApi()
2939
.ToRegistrar(services)
3040
.RegisterScoped();
31-
32-
private static MicrosoftDbProviderOption ResolveDataverseDbProviderOption(IServiceProvider serviceProvider)
33-
{
34-
var configuration = serviceProvider.GetConfiguration();
35-
var option = configuration.GetDataverseApiClientAuthOption(DataverseSectionName);
36-
37-
var connectionStringBuilder = new StringBuilder()
38-
.Append("Server=").Append(new Uri(option.ServiceUrl).Host).Append(",5558;")
39-
.Append("Initial Catalog=").Append(configuration[$"{DataverseSectionName}:EnvironmentId"]).Append(';')
40-
.Append("Authentication=ActiveDirectoryServicePrincipal;")
41-
.Append("User ID=").Append(option.AuthClientId).Append(';')
42-
.Append("Password=").Append(option.AuthClientSecret).Append(';');
43-
44-
return new(
45-
connectionString: connectionStringBuilder.ToString(),
46-
retryOption: configuration.GetSection($"{DataverseSectionName}:DatabaseRetryPolicy").Get<SqlRetryLogicOption>());
47-
}
4841
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using GarageGroup.Infra;
2+
using PrimeFuncPack;
3+
4+
namespace GarageGroup.Internal.Support;
5+
6+
partial class Application
7+
{
8+
[HttpFunction("HealthCheck", HttpMethodName.Get, Route = "health", AuthLevel = HttpAuthorizationLevel.Function)]
9+
internal static Dependency<IHealthCheckHandler> UseHealthCheck()
10+
=>
11+
HealthCheck.UseServices(
12+
UseCosmosStorage().UseServiceHealthCheckApi("CosmosStorage"),
13+
UseSqlApi().UseServiceHealthCheckApi("DataverseDb"),
14+
UseDataverseApi().UseServiceHealthCheckApi("DataverseApi"))
15+
.UseHealthCheckHandler();
16+
}

src/app/AzureFunc/Applicaton/App.Storage.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/app/AzureFunc/Applicaton/Applicaton.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
using System;
2-
using System.Net;
3-
using System.Net.Http;
42
using GarageGroup.Infra;
5-
using Microsoft.Azure.Functions.Worker;
3+
using GarageGroup.Infra.Bot.Builder;
64
using Microsoft.Extensions.Configuration;
75
using Microsoft.Extensions.DependencyInjection;
86
using PrimeFuncPack;
97

108
namespace GarageGroup.Internal.Support;
119

12-
[HealthCheckFunc("HealthCheck", AuthLevel = AuthorizationLevel.Function)]
1310
internal static partial class Application
1411
{
1512
private const string DataverseSectionName = "Dataverse";
@@ -22,12 +19,6 @@ internal static partial class Application
2219

2320
private const string BotEntityName = "BotRequest";
2421

25-
private static Dependency<HttpMessageHandler> UseHttpMessageHandlerStandard(string loggerCategoryName)
26-
=>
27-
PrimaryHandler.UseStandardSocketsHttpHandler()
28-
.UseLogging(loggerCategoryName)
29-
.UsePollyStandard(HttpStatusCode.TooManyRequests);
30-
3122
private static Dependency<IDataverseApiClient> UseDataverseApi()
3223
=>
3324
Dependency.From(
@@ -38,6 +29,11 @@ private static Dependency<ISqlApi> UseSqlApi()
3829
Dependency.From(
3930
ServiceProviderServiceExtensions.GetRequiredService<ISqlApi>);
4031

32+
private static Dependency<ICosmosStorage> UseCosmosStorage()
33+
=>
34+
Dependency.From(
35+
ServiceProviderServiceExtensions.GetRequiredService<ICosmosStorage>);
36+
4137
private static IConfiguration GetConfiguration(this IServiceProvider serviceProvider)
4238
=>
4339
serviceProvider.GetRequiredService<IConfiguration>();

src/app/AzureFunc/Applicaton/BotFlow/Flow.Authorization.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ internal static IBotBuilder UseAuthorizationFlow(this IBotBuilder botBuilder)
1515

1616
private static IAzureUserApi GetAzureUserApi(IBotContext botContext)
1717
=>
18-
UseHttpMessageHandlerStandard("AzureUserApi").UseAzureUserApi().Resolve(botContext.ServiceProvider);
18+
PrimaryHandler.UseStandardSocketsHttpHandler()
19+
.UseLogging("AzureUserApi")
20+
.UsePollyStandard()
21+
.UseAzureUserApi()
22+
.Resolve(botContext.ServiceProvider);
1923

2024
private static IDataverseUserApi GetDataverseUserApi(IBotContext botContext)
2125
=>

src/app/AzureFunc/Applicaton/BotFlow/Flow.IncidentCreate.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Text;
4+
using GarageGroup.Infra;
45
using GarageGroup.Infra.Bot.Builder;
56
using Microsoft.Extensions.Configuration;
67
using PrimeFuncPack;
@@ -22,9 +23,17 @@ private static IBotBuilder UseIncidentCreateFlow(this IBotBuilder botBuilder)
2223
.With(
2324
UseDataverseApi().UseCrmIncidentApi())
2425
.With(
25-
UseHttpMessageHandlerStandard("SupportGptApi").With(ResolveSupportGptApiOption).UseSupportGptApi())
26+
UseSupportGptApi())
2627
.MapIncidentCreateFlow(botBuilder);
2728

29+
private static Dependency<ISupportGptApi> UseSupportGptApi()
30+
=>
31+
PrimaryHandler.UseStandardSocketsHttpHandler()
32+
.UseLogging("SupportGptApi")
33+
.UsePollyStandard()
34+
.With(ResolveSupportGptApiOption)
35+
.UseSupportGptApi();
36+
2837
private static IncidentCreateFlowOption ResolveIncidentCreateFlowOption(IServiceProvider serviceProvider)
2938
{
3039
var configuration = serviceProvider.GetConfiguration();
@@ -71,6 +80,7 @@ private static SupportGptApiOption ResolveSupportGptApiOption(IServiceProvider s
7180
}
7281

7382
var azureSection = gptApiSection.GetRequiredSection(GptApiAzureSectionName);
83+
7484
return new(
7585
apiKey: azureSection["Key"].OrEmpty(),
7686
azureGpt: new(

src/app/AzureFunc/AzureFunc.csproj

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="GarageGroup.Infra.Azure.DurableTask" Version="0.3.0" />
31-
<PackageReference Include="GarageGroup.Infra.Azure.HealthCheck" Version="0.6.0" />
32-
<PackageReference Include="GarageGroup.Infra.Azure.Hosting" Version="0.4.0" />
30+
<PackageReference Include="GarageGroup.Infra.Azure.DurableTask" Version="0.5.1" />
31+
<PackageReference Include="GarageGroup.Infra.Azure.Hosting" Version="0.6.1" />
3332
<PackageReference Include="GarageGroup.Infra.Azure.Services.AzureUser.Api" Version="0.1.1" />
3433
<PackageReference Include="GarageGroup.Infra.Bot.Builder.Authorization.Dataverse" Version="0.4.0" />
3534
<PackageReference Include="GarageGroup.Infra.Bot.Builder.Command.Info" Version="0.2.0" />
3635
<PackageReference Include="GarageGroup.Infra.Bot.Builder.Command.Stop" Version="0.2.0" />
37-
<PackageReference Include="GarageGroup.Infra.Bot.Builder.Integration.CosmosStorage" Version="0.2.0" />
3836
<PackageReference Include="GarageGroup.Infra.Bot.Builder.Integration.Handler" Version="0.4.0" />
39-
<PackageReference Include="GarageGroup.Infra.Dataverse.Api" Version="3.12.0" />
37+
<PackageReference Include="GarageGroup.Infra.Bot.Builder.Integration.Storage.CosmosDb" Version="0.5.0" />
38+
<PackageReference Include="GarageGroup.Infra.Dataverse.Api" Version="3.15.0" />
4039
<PackageReference Include="GarageGroup.Infra.Dataverse.DataverseUser.Api" Version="1.3.0" />
41-
<PackageReference Include="GarageGroup.Infra.Http.Polly" Version="1.1.1" />
42-
<PackageReference Include="GarageGroup.Infra.Sql.Api" Version="2.1.0" />
43-
<PackageReference Include="GarageGroup.Infra.Sql.Api.Provider.Microsoft" Version="2.1.0" />
44-
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.14.1" OutputItemType="Analyzer" />
45-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
46-
<PackageReference Include="PrimeFuncPack.DependencyRegistry" Version="1.2.1" />
40+
<PackageReference Include="GarageGroup.Infra.HealthCheck.Handler" Version="0.0.1" />
41+
<PackageReference Include="GarageGroup.Infra.Http.Polly" Version="1.2.0" />
42+
<PackageReference Include="GarageGroup.Infra.Sql.Api" Version="2.4.0" />
43+
<PackageReference Include="GarageGroup.Infra.Sql.Api.Provider.Dataverse" Version="0.0.1" />
44+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
45+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" OutputItemType="Analyzer" />
46+
<PackageReference Include="PrimeFuncPack.DependencyRegistry" Version="2.1.0" />
4747
</ItemGroup>
4848

4949
</Project>

0 commit comments

Comments
 (0)