Skip to content

Commit

Permalink
reactor : EnvironmentCallerMiddleware (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzh425 authored Jul 12, 2023
1 parent eeb3ad8 commit 819eeaf
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ItemGroup>
<ProjectReference Include="..\..\..\Authentication\Masa.BuildingBlocks.Authentication.Identity\Masa.BuildingBlocks.Authentication.Identity.csproj" />
<ProjectReference Include="..\..\..\Exception\Masa.BuildingBlocks.Exceptions\Masa.BuildingBlocks.Exceptions.csproj" />
<ProjectReference Include="..\..\Masa.BuildingBlocks.StackSdks.Isolation\Masa.BuildingBlocks.StackSdks.Isolation.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

global using Masa.BuildingBlocks.Authentication.Identity;
global using Masa.BuildingBlocks.StackSdks.Auth.Contracts.Enum;
global using Masa.BuildingBlocks.StackSdks.Isolation.Models;
global using System.ComponentModel;
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;
namespace Masa.BuildingBlocks.StackSdks.Isolation.Models;

public interface IEnvironmentModel
{
public string Environment { get; set; }
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ProjectReference Include="..\..\..\BuildingBlocks\StackSdks\Masa.BuildingBlocks.StackSdks.Alert\Masa.BuildingBlocks.StackSdks.Alert.csproj" />
<ProjectReference Include="..\..\Service\Caller\Masa.Contrib.Service.Caller.HttpClient\Masa.Contrib.Service.Caller.HttpClient.csproj" />
<ProjectReference Include="..\Masa.Contrib.StackSdks.Caller\Masa.Contrib.StackSdks.Caller.csproj" />
<ProjectReference Include="..\Masa.Contrib.StackSdks.Isolation\Masa.Contrib.StackSdks.Isolation.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public static IServiceCollection AddAlertClient(this IServiceCollection services
callerBuilder.UseHttpClient(builder =>
{
builder.Configure = opt => opt.BaseAddress = new Uri(alertServiceBaseAddress);
}).UseAuthentication();
})
.AddMiddleware<EnvironmentCallerMiddleware>()
.UseAuthentication();
});
}

Expand All @@ -28,7 +30,9 @@ public static IServiceCollection AddAlertClient(this IServiceCollection services
.UseHttpClient(builder =>
{
builder.BaseAddress = alertServiceBaseAddressFunc.Invoke();
}).UseAuthentication();
})
.AddMiddleware<EnvironmentCallerMiddleware>()
.UseAuthentication();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@
global using Masa.BuildingBlocks.StackSdks.Alert.Service;
global using Masa.Contrib.StackSdks.Alert;
global using Masa.Contrib.StackSdks.Alert.Service;
global using System.Collections.Concurrent;
global using System.ComponentModel;
global using System.Diagnostics.CodeAnalysis;
global using System.Globalization;
global using System.Reflection;
global using Masa.Contrib.StackSdks.Isolation;
global using static Masa.Contrib.StackSdks.Alert.Constants;
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<ProjectReference Include="..\..\Caching\Masa.Contrib.Caching.MultilevelCache\Masa.Contrib.Caching.MultilevelCache.csproj" />
<ProjectReference Include="..\..\Service\Caller\Masa.Contrib.Service.Caller.HttpClient\Masa.Contrib.Service.Caller.HttpClient.csproj" />
<ProjectReference Include="..\Masa.Contrib.StackSdks.Caller\Masa.Contrib.StackSdks.Caller.csproj" />
<ProjectReference Include="..\Masa.Contrib.StackSdks.Isolation\Masa.Contrib.StackSdks.Isolation.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static IServiceCollection AddAuthClient(this IServiceCollection services,
{
callerBuilder
.UseHttpClient(builder => builder.BaseAddress = authServiceBaseAddress)
.AddMiddleware<EnvironmentMiddleware>()
.AddMiddleware<EnvironmentCallerMiddleware>()
.UseAuthentication();
}, redisOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
global using Masa.Contrib.StackSdks.Auth;
global using Masa.Contrib.StackSdks.Auth.Model;
global using Masa.Contrib.StackSdks.Auth.Service;
global using Masa.Contrib.StackSdks.Isolation;
global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.Logging;
global using System.Text.Json;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.StackSdks.Auth;
namespace Masa.Contrib.StackSdks.Isolation;

public class EnvironmentMiddleware : ICallerMiddleware
public class EnvironmentCallerMiddleware : ICallerMiddleware
{
readonly ILogger<EnvironmentMiddleware>? _logger;
readonly ILogger<EnvironmentCallerMiddleware>? _logger;

public EnvironmentMiddleware(ILoggerFactory? loggerFactory = null)
public EnvironmentCallerMiddleware(ILoggerFactory? loggerFactory = null)
{
_logger = loggerFactory?.CreateLogger<EnvironmentMiddleware>();
_logger = loggerFactory?.CreateLogger<EnvironmentCallerMiddleware>();
}

public async Task HandleAsync(MasaHttpContext masaHttpContext, CallerHandlerDelegate next, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -40,3 +40,4 @@ public async Task HandleAsync(MasaHttpContext masaHttpContext, CallerHandlerDele
}
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.StackSdks.Auth.Model;
namespace Masa.Contrib.StackSdks.Isolation;

internal class EnvironmentModel : IEnvironmentModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
global using Masa.BuildingBlocks.Configuration.Options;
global using Masa.BuildingBlocks.Data;
global using Masa.BuildingBlocks.Isolation;
global using Masa.BuildingBlocks.Service.Caller;
global using Masa.BuildingBlocks.StackSdks.Config;
global using Masa.BuildingBlocks.StackSdks.Config.Models;
global using Masa.BuildingBlocks.StackSdks.Isolation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ProjectReference Include="..\..\..\BuildingBlocks\StackSdks\Masa.BuildingBlocks.StackSdks.Mc\Masa.BuildingBlocks.StackSdks.Mc.csproj" />
<ProjectReference Include="..\Masa.Contrib.StackSdks.Caller\Masa.Contrib.StackSdks.Caller.csproj" />
<ProjectReference Include="..\..\Service\Caller\Masa.Contrib.Service.Caller.HttpClient\Masa.Contrib.Service.Caller.HttpClient.csproj" />
<ProjectReference Include="..\Masa.Contrib.StackSdks.Isolation\Masa.Contrib.StackSdks.Isolation.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public static IServiceCollection AddMcClient(this IServiceCollection services, s
callerBuilder.UseHttpClient(builder =>
{
builder.Configure = opt => opt.BaseAddress = new Uri(mcServiceBaseAddress);
}).UseAuthentication();
})
.AddMiddleware<EnvironmentCallerMiddleware>()
.UseAuthentication();
});
}

Expand All @@ -30,7 +32,9 @@ public static IServiceCollection AddMcClient(this IServiceCollection services, F
.UseHttpClient(builder =>
{
builder.BaseAddress = mcServiceBaseAddressFunc.Invoke();
}).UseAuthentication();
})
.AddMiddleware<EnvironmentCallerMiddleware>()
.UseAuthentication();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
global using Masa.Contrib.StackSdks.Mc;
global using Masa.Contrib.StackSdks.Mc.Infrastructure.Helper;
global using Masa.Contrib.StackSdks.Mc.Service;
global using Masa.Contrib.StackSdks.Isolation;
global using System.Collections.Concurrent;
global using System.ComponentModel;
global using System.Diagnostics.CodeAnalysis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ProjectReference Include="..\..\..\BuildingBlocks\StackSdks\Masa.BuildingBlocks.StackSdks.Scheduler\Masa.BuildingBlocks.StackSdks.Scheduler.csproj" />
<ProjectReference Include="..\Masa.Contrib.StackSdks.Caller\Masa.Contrib.StackSdks.Caller.csproj" />
<ProjectReference Include="..\..\Service\Caller\Masa.Contrib.Service.Caller.HttpClient\Masa.Contrib.Service.Caller.HttpClient.csproj" />
<ProjectReference Include="..\Masa.Contrib.StackSdks.Isolation\Masa.Contrib.StackSdks.Isolation.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public static IServiceCollection AddSchedulerClient(this IServiceCollection serv
.UseHttpClient(builder =>
{
builder.Configure = opt => opt.BaseAddress = new Uri(schedulerServiceBaseAddress);
}).UseAuthentication();
})
.AddMiddleware<EnvironmentCallerMiddleware>()
.UseAuthentication();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
global using Masa.BuildingBlocks.StackSdks.Scheduler.Model;
global using Masa.BuildingBlocks.StackSdks.Scheduler.Request;
global using Masa.BuildingBlocks.StackSdks.Scheduler.Service;
global using Masa.Contrib.StackSdks.Isolation;
global using Masa.Contrib.StackSdks.Scheduler;
global using Masa.Contrib.StackSdks.Scheduler.Logger;
global using Masa.Contrib.StackSdks.Scheduler.Services;
Expand All @@ -17,4 +18,4 @@
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Logging;
global using static Masa.Contrib.StackSdks.Scheduler.Constants;
global using IAuthenticationService = Masa.BuildingBlocks.Service.Caller.IAuthenticationService;

0 comments on commit 819eeaf

Please sign in to comment.