Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface ITeamService
{
Task<TeamDetailModel?> GetDetailAsync(Guid id);

Task<List<TeamModel>> GetAllAsync();
Task<List<TeamModel>> GetAllAsync(string environment);

Task<List<TeamModel>> GetUserTeamsAsync();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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;

public class EnvironmentMiddleware : ICallerMiddleware
{
public async Task HandleAsync(MasaHttpContext masaHttpContext, CallerHandlerDelegate next, CancellationToken cancellationToken = default)
{

try
{
if (masaHttpContext.RequestMessage.Content != null && masaHttpContext.RequestMessage.Content.Headers.ContentType?.MediaType == "application/json")
{
var body = await masaHttpContext.RequestMessage.Content.ReadAsStringAsync(CancellationToken.None);
var obj = JsonSerializer.Deserialize<EnvironmentModel>(body, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});
if (!string.IsNullOrEmpty(obj?.Environment))
{
masaHttpContext.RequestMessage.Headers.Add(IsolationConsts.ENVIRONMENT, obj?.Environment);
}
}
}
finally
{
await next();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public async Task<List<TeamModel>> GetListAsync(Guid userId = default)
return await _caller.GetAsync<List<TeamModel>>(requestUri) ?? new();
}

public async Task<List<TeamModel>> GetAllAsync()
public async Task<List<TeamModel>> GetAllAsync(string environment)
{
var requestUri = $"{_party}list";
var requestUri = $"{_party}list?{IsolationConsts.ENVIRONMENT}={environment}";
return await _caller.GetAsync<List<TeamModel>>(requestUri) ?? new();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static IServiceCollection AddAuthClient(this IServiceCollection services,
{
callerBuilder
.UseHttpClient(builder => builder.BaseAddress = authServiceBaseAddress)
.AddMiddleware<EnvironmentMiddleware>()
.UseAuthentication();
}, redisOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
global using Masa.Contrib.StackSdks.Auth.Model;
global using Masa.Contrib.StackSdks.Auth.Service;
global using Microsoft.Extensions.Configuration;
global using System.Net.Http.Json;
global using System.Text.Json;
global using static Masa.Contrib.StackSdks.Auth.Constants;
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public async Task TestGetDetailAsync()
public async Task TestGetAllAsync()
{
var data = new List<TeamModel>();
var requestUri = $"api/team/list";
var requestUri = $"api/team/list?{IsolationConsts.ENVIRONMENT}=test";
var caller = new Mock<ICaller>();
caller.Setup(provider => provider.GetAsync<List<TeamModel>>(requestUri, default)).ReturnsAsync(data).Verifiable();
var userContext = new Mock<IUserContext>();
var teamService = new Mock<TeamService>(caller.Object, userContext.Object);
var result = await teamService.Object.GetAllAsync();
var result = await teamService.Object.GetAllAsync("test");
caller.Verify(provider => provider.GetAsync<List<TeamModel>>(requestUri, default), Times.Once);
Assert.IsTrue(result is not null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
global using Masa.BuildingBlocks.Caching;
global using Masa.BuildingBlocks.Service.Caller;
global using Masa.BuildingBlocks.StackSdks.Auth;
global using Masa.BuildingBlocks.StackSdks.Auth.Contracts.Consts;
global using Masa.BuildingBlocks.StackSdks.Auth.Contracts.Enum;
global using Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;
global using Masa.BuildingBlocks.StackSdks.Isolation;
global using Masa.Contrib.StackSdks.Auth.Service;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.VisualStudio.TestTools.UnitTesting;
global using Moq;
global using System.Text.Json;
global using IdentityModel.Client;
global using Moq.Protected;
global using System.Net;
global using Masa.BuildingBlocks.StackSdks.Auth.Contracts.Consts;
global using System.Text.Json;