Skip to content

Commit

Permalink
feat : isolation (#530)
Browse files Browse the repository at this point in the history
* feat : isolation

* chore : global using

* chore : Modifying Environment Variable Configuration

* fix : Failed to process image construction

* reactor : User search using Auth sdk
  • Loading branch information
wzh425 authored Jul 3, 2023
1 parent c8cde1d commit 6800b17
Show file tree
Hide file tree
Showing 31 changed files with 56 additions and 161 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<MasaFrameworkPackageVersion>1.0.0-rc.2.1</MasaFrameworkPackageVersion>
<MasaFrameworkPackageVersion>1.0.0-rc.3.2</MasaFrameworkPackageVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<PackageReference Include="FluentValidation" Version="11.4.0" />
<PackageReference Include="Magicodes.IE.Csv" Version="2.6.4" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Masa.BuildingBlocks.StackSdks.Auth.Contracts" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.BuildingBlocks.StackSdks.Auth.Contracts" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.BuildingBlocks.SearchEngine.AutoComplete" Version="$(MasaFrameworkPackageVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/Contracts/Masa.Mc.Contracts.Admin/_Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
global using Masa.Mc.Infrastructure.Common.Utils;
global using System.Collections.Concurrent;
global using Masa.Mc.Contracts.Admin.Enums.WebsiteMessages;
global using Masa.Mc.Contracts.Admin.Scheduler;
global using Masa.Mc.Contracts.Admin.Scheduler;
global using Masa.BuildingBlocks.SearchEngine.AutoComplete;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Masa.Mc.Service.Admin.Infrastructure.EntityFrameworkCore;

[ConnectionStringName("DefaultConnection")]
public class McDbContext : MasaDbContext<McDbContext>
{
public DbSet<IntegrationEventLog> EventLogs { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ public class McDbContextFactory : IDesignTimeDbContextFactory<McDbContext>
{
public McDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new MasaDbContextOptionsBuilder<McDbContext>()
{
};
var optionsBuilder = new MasaDbContextOptionsBuilder<McDbContext>();

var configurationBuilder = new ConfigurationBuilder();
var configuration = configurationBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Masa.Mc.Service.Admin.Infrastructure.EntityFrameworkCore;

[ConnectionStringName("QueryConnection")]
public class McQueryContext : MasaDbContext<McQueryContext>, IMcQueryContext
{
public IQueryable<MessageTaskQueryModel> MessageTaskQueries => Set<MessageTaskQueryModel>().AsQueryable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<Guid> RegisterJobAsync(Guid jobId, Guid messageTaskId, string
var mcUrl = _masaStackConfig.GetMcServiceDomain();
var request = new UpsertSchedulerJobRequest
{
ProjectIdentity = MasaStackConstant.MC,
ProjectIdentity = MasaStackProject.MC.Name,
Name = jobName,
JobType = JobTypes.JobApp,
CronExpression = cronExpression,
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Masa.Mc.Service/Jobs/MessageTaskExecuteJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class MessageTaskExecuteJob : SchedulerJob
//{
// configurationBuilder.UseDcc();
//});
await builder.Services.AddMasaStackConfigAsync();
await builder.Services.AddMasaStackConfigAsync(MasaStackProject.MC, MasaStackApp.Service);
var masaStackConfig = builder.Services.GetMasaStackConfig();
var configuration = builder.Services.GetMasaConfiguration().ConfigurationApi.GetDefault();
var redisOptions = new RedisConfigurationOptions
Expand Down
2 changes: 2 additions & 0 deletions src/Services/Masa.Mc.Service/Masa.Mc.Service.Admin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<PackageReference Include="Masa.Contrib.StackSdks.Dcc" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.StackSdks.Scheduler" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.StackSdks.Tsc" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.StackSdks.Pm" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.Configuration" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.Configuration.ConfigurationApi.Dcc" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.Data.Contracts" Version="$(MasaFrameworkPackageVersion)" />
Expand Down Expand Up @@ -53,6 +54,7 @@
<PackageReference Include="Masa.Contrib.StackSdks.Caller" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.Globalization.I18n.AspNetCore" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.Extensions.BackgroundJobs.Memory" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.StackSdks.Isolation" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.1">
Expand Down
25 changes: 11 additions & 14 deletions src/Services/Masa.Mc.Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
ValidatorOptions.Global.LanguageManager = new MasaLanguageManager();
GlobalValidationOptions.SetDefaultCulture("zh-CN");

await builder.Services.AddMasaStackConfigAsync();
await builder.Services.AddMasaStackConfigAsync(MasaStackProject.MC, MasaStackApp.Service);
var masaStackConfig = builder.Services.GetMasaStackConfig();

var publicConfiguration = builder.Services.GetMasaConfiguration().ConfigurationApi.GetPublic();
Expand All @@ -24,22 +24,15 @@
builder.Services.AddAutoInject();
builder.Services.AddDaprClient();

var ossOptions = publicConfiguration.GetSection("$public.OSS").Get<OssOptions>();
builder.Services.AddObjectStorage(option => option.UseAliyunStorage(new AliyunStorageOptions(ossOptions.AccessId, ossOptions.AccessSecret, ossOptions.Endpoint, ossOptions.RoleArn, ossOptions.RoleSessionName)
{
Sts = new AliyunStsOptions()
{
RegionId = ossOptions.RegionId
}
}));
builder.Services.AddObjectStorage(option => option.UseAliyunStorage());

builder.Services.AddObservable(builder.Logging, () =>
{
return new MasaObservableOptions
{
ServiceNameSpace = builder.Environment.EnvironmentName,
ServiceVersion = masaStackConfig.Version,
ServiceName = masaStackConfig.GetServiceId(MasaStackConstant.MC),
ServiceName = masaStackConfig.GetServiceId(MasaStackProject.MC),
Layer = masaStackConfig.Namespace,
ServiceInstanceId = builder.Configuration.GetValue<string>("HOSTNAME")
};
Expand Down Expand Up @@ -95,8 +88,9 @@
var configuration = builder.Services.GetMasaConfiguration().ConfigurationApi.GetDefault();
builder.Services.AddAuthClient(masaStackConfig.GetAuthServiceDomain(), redisOptions);
builder.Services.AddMcClient(masaStackConfig.GetMcServiceDomain());
builder.Services.AddPmClient(masaStackConfig.GetPmServiceDomain());
builder.Services.AddSchedulerClient(masaStackConfig.GetSchedulerServiceDomain());
builder.Services.AddMultilevelCache(options => options.UseStackExchangeRedisCache(redisOptions));
builder.Services.AddMultilevelCache(options => options.UseStackExchangeRedisCache());
builder.Services.AddAliyunSms();
builder.Services.AddMailKit();
builder.Services.AddAppNotification();
Expand Down Expand Up @@ -154,12 +148,12 @@
})
.AddMasaDbContext<McDbContext>(builder =>
{
builder.UseSqlServer(masaStackConfig.GetConnectionString(MasaStackConstant.MC));
builder.UseSqlServer();
builder.UseFilter(options => options.EnableSoftDelete = true);
})
.AddMasaDbContext<McQueryContext>(builder =>
{
builder.UseSqlServer(masaStackConfig.GetConnectionString(MasaStackConstant.MC));
builder.UseSqlServer();
builder.UseFilter(options => options.EnableSoftDelete = true);
})
.AddScoped<IMcQueryContext, McQueryContext>()
Expand All @@ -173,7 +167,9 @@
})
.UseUoW<McDbContext>()
.UseRepository<McDbContext>();
}).AddIsolation(isolationBuilder => isolationBuilder.UseMultiEnvironment("env_key"));
});

await builder.Services.AddStackIsolationAsync(MasaStackProject.MC.Name);

builder.Services.AddStackMiddleware();
await builder.MigrateDbContextAsync<McDbContext>();
Expand Down Expand Up @@ -204,6 +200,7 @@

app.UseAuthentication();
app.UseAuthorization();
app.UseStackIsolation();
app.UseStackMiddleware();
app.UseCloudEvents();
app.UseMasaCloudEvents();
Expand Down
11 changes: 6 additions & 5 deletions src/Services/Masa.Mc.Service/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DAPR_GRPC_PORT": "20601",
"DAPR_HTTP_PORT": "20602",
"CLUSTER": "Default",
"MASA_CLUSTER": "Default",
"DOMAIN_NAME": "masastack.com",
"NAMESPACE": "masastack.com",
"MASA_NAMESPACE": "masastack.com",
"TLS_NAME": "",
"VERSION": "1.0-Preview1",
"MASA_VERSION": "1.0-Preview1",
"IS_DEMO": "false",
"OTLP_URL": "http://otel-collector.masastack:9013",
"ELASTIC": "{\"ESNode\": \"http://10.10.90.189\",\"Index\": \"user_dev\",\"ESPort\":30200}",
"ELASTIC": "{\"Nodes\": [\"http://es-ydy-new.lonsid.cn:9200\"],\"Index\": \"auth_user_development\"}",
"REDIS": "{\"RedisHost\": \"10.130.0.235\", \"RedisPort\": 24615, \"RedisDb\": 0,\"RedisPassword\": \"Hzss@123\"}",
"CONNECTIONSTRING": "{\"Server\": \"10.175.171.201\", \"Port\": 32679,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}",
"MASA_STACK": "[{\"id\":\"pm\",\"name\":\"PM\",\"service\":{\"name\":\"PM.Service\",\"id\":\"pm-service\",\"domain\":\"http://pm-service-develop.masastack.com\"},\"web\":{\"name\":\"PM.Web\",\"id\":\"pm-develop\",\"domain\":\"\"}},{\"id\":\"dcc\",\"name\":\"DCC\",\"service\":{\"name\":\"Dcc.Service\",\"id\":\"dcc-service\",\"domain\":\"http://dcc-service-develop.masastack.com\"},\"web\":{\"name\":\"DCC.Web\",\"id\":\"dcc-develop\",\"domain\":\"\"}},{\"id\":\"tsc\",\"name\":\"TSC\",\"service\":{\"name\":\"TSC.Service\",\"id\":\"tsc-service\",\"domain\":\"http://tsc-service-develop.masastack.com\"},\"web\":{\"name\":\"TSC.Web\",\"id\":\"tsc-develop\",\"domain\":\"\"}},{\"id\":\"alert\",\"name\":\"Alert\",\"service\":{\"name\":\"Alert.Service\",\"id\":\"alert-service\",\"domain\":\"http://alert-service-develop.masastack.com\"},\"web\":{\"name\":\"Alert.Web\",\"id\":\"alert-develop\",\"domain\":\"\"}},{\"id\":\"scheduler\",\"name\":\"Scheduler\",\"service\":{\"name\":\"Scheduler.Service\",\"id\":\"scheduler-service\",\"domain\":\"http://scheduler-service-develop.masastack.com\"},\"worker\":{\"name\":\"Scheduler.Worker\",\"id\":\"scheduler-worker\",\"domain\":\"\"},\"web\":{\"name\":\"Scheduler.Web\",\"id\":\"scheduler-develop\",\"domain\":\"\"}},{\"id\":\"mc\",\"name\":\"MC\",\"service\":{\"name\":\"MC.Service\",\"id\":\"mc-service\",\"domain\":\"http://mc-service-develop.masastack.com\"},\"web\":{\"name\":\"MC.Web\",\"id\":\"mc-develop\",\"domain\":\"\"}},{\"id\":\"auth\",\"name\":\"Auth\",\"service\":{\"name\":\"Auth.Service\",\"id\":\"auth-service-develop \",\"domain\":\"http://auth-service-develop.masastack.com\"},\"web\":{\"name\":\"Auth.Web\",\"id\":\"auth-develop\",\"domain\":\"\"},\"sso\":{\"name\":\"Auth.SSO\",\"id\":\"auth-sso\",\"domain\":\"https://sso-develop.masastack.com\"}}]",
"MASA_STACK": "[{\"id\":\"pm\",\"service\":{\"id\":\"pm-service-dev\",\"domain\":\"http://pm-service-dev.masastack.com\"},\"web\":{\"id\":\"pm-web-dev\",\"domain\":\"https://pm-dev.masastack.com\"}},{\"id\":\"dcc\",\"service\":{\"id\":\"dcc-service-dev\",\"domain\":\"http://dcc-service-dev.masastack.com\"},\"web\":{\"id\":\"dcc-web-dev\",\"domain\":\"https://dcc-dev.masastack.com\"}},{\"id\":\"tsc\",\"service\":{\"id\":\"tsc-service-dev\",\"domain\":\"http://tsc-service-dev.masastack.com\"},\"web\":{\"id\":\"tsc-web-dev\",\"domain\":\"https://tsc-dev.masastack.com\"}},{\"id\":\"alert\",\"service\":{\"id\":\"alert-service-dev\",\"domain\":\"http://alert-service-dev.masastack.com\"},\"web\":{\"id\":\"alert-web-dev\",\"domain\":\"https://alert-dev.masastack.com\"}},{\"id\":\"scheduler\",\"service\":{\"id\":\"scheduler-service-dev\",\"domain\":\"http://scheduler-service-dev.masastack.com\"},\"worker\":{\"id\":\"scheduler-worker-dev\",\"domain\":\"http://scheduler-worker-dev.masastack.com\"},\"web\":{\"id\":\"scheduler-web-dev\",\"domain\":\"https://scheduler-dev.masastack.com\"}},{\"id\":\"mc\",\"service\":{\"id\":\"mc-service-dev\",\"domain\":\"http://mc-service-dev.masastack.com\"},\"web\":{\"id\":\"mc-web-dev\",\"domain\":\"https://mc-dev.masastack.com\"}},{\"id\":\"auth\",\"service\":{\"id\":\"auth-service-dev\",\"domain\":\"http://auth-service-dev.masastack.com\"},\"web\":{\"id\":\"auth-web-dev\",\"domain\":\"https://auth-dev.masastack.com\"},\"sso\":{\"id\":\"auth-sso-dev\",\"domain\":\"https://auth-sso-dev.masastack.com\"}}]",
"MASA_ENVIRONMENT": "Development",
"ADMIN_PWD": "admin_pwd",
"DCC_SECRET": "masastack.com",
"SUFFIX_IDENTITY": "dev"
Expand Down
5 changes: 3 additions & 2 deletions src/Services/Masa.Mc.Service/_Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
global using Masa.Mc.Service.Admin.Application.QueryContext;
global using Masa.BuildingBlocks.Ddd.Domain.Values;
global using Masa.Mc.Service.Admin.Infrastructure.ChannelUserFinder.Provider.Auth;
global using Masa.BuildingBlocks.Ddd.Domain.SeedWork;
global using Masa.BuildingBlocks.Data.Contracts;
global using Masa.Mc.Service.Admin.Infrastructure.MessageTaskJobService;
global using Masa.Mc.Infrastructure.AppNotification;
global using Masa.Mc.Infrastructure.AppNotification.Infrastructure.OptionsResolve;
Expand Down Expand Up @@ -207,4 +207,5 @@
global using Microsoft.Extensions.DependencyInjection.Extensions;
global using Masa.Mc.Service.Admin.Infrastructure.Mock;
global using Masa.BuildingBlocks.Extensions.BackgroundJobs;
global using Masa.Mc.Service.Admin.Application.MessageTasks.Jobs;
global using Masa.Mc.Service.Admin.Application.MessageTasks.Jobs;
global using Masa.Contrib.StackSdks.Isolation;
16 changes: 0 additions & 16 deletions src/Services/Masa.Mc.Service/appsettings.Develop.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=10.175.171.201,32679;Database=mc_dev;User Id=ss;Password=Hzss@123;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
Expand All @@ -15,19 +12,6 @@
"AccessKeyId": "",
"EndPoint": "dysmsapi.aliyuncs.com"
},
"DccOptions": {
"ManageServiceAddress": "https://dcc-service-develop.masastack.com/",
"RedisOptions": {
"Servers": [
{
"Host": "10.175.207.202",
"Port": "30260"
}
],
"DefaultDatabase": 0,
"Password": "Hzss@123redis"
}
},
"AppId": "masa-mc-service-admin",
"Environment": "Develop",
"Secret": "",
Expand Down
15 changes: 1 addition & 14 deletions src/Services/Masa.Mc.Service/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=10.175.171.201,32679;Database=mc_dev;User Id=ss;Password=Hzss@123;"
"DefaultConnection": "Server=10.130.0.235,24878;Database=mc_dev;User Id=ss;Password=Hzss@123;"
},
"Logging": {
"LogLevel": {
Expand All @@ -15,19 +15,6 @@
"AccessKeyId": "",
"EndPoint": "dysmsapi.aliyuncs.com"
},
"DccOptions": {
"ManageServiceAddress": "https://dcc-service-develop.masastack.com/",
"RedisOptions": {
"Servers": [
{
"Host": "10.175.207.202",
"Port": "30260"
}
],
"DefaultDatabase": 0,
"Password": "Hzss@123redis"
}
},
"AppId": "masa-mc-service-admin",
"Environment": "Development",
"Secret": "",
Expand Down
16 changes: 0 additions & 16 deletions src/Services/Masa.Mc.Service/appsettings.Staging.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=10.175.171.201,32679;Database=mc_staging;User Id=ss;Password=Hzss@123;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
Expand All @@ -15,19 +12,6 @@
"AccessKeyId": "",
"EndPoint": "dysmsapi.aliyuncs.com"
},
"DccOptions": {
"ManageServiceAddress": "https://dcc-staging-develop.masastack.com/",
"RedisOptions": {
"Servers": [
{
"Host": "10.175.207.202",
"Port": "30260"
}
],
"DefaultDatabase": 1,
"Password": "Hzss@123redis"
}
},
"AppId": "masa-mc-service-admin",
"Environment": "Staging",
"Secret": "",
Expand Down
3 changes: 0 additions & 3 deletions src/Services/Masa.Mc.Service/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=10.175.171.201,32679;Database=mc_dev;User Id=ss;Password=Hzss@123;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down
8 changes: 4 additions & 4 deletions src/Web/Masa.Mc.Web.Admin.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
ValidatorOptions.Global.LanguageManager = new MasaLanguageManager();
GlobalValidationOptions.SetDefaultCulture("zh-CN");

await builder.Services.AddMasaStackConfigAsync();
await builder.Services.AddMasaStackConfigAsync(MasaStackProject.MC, MasaStackApp.WEB);
var masaStackConfig = builder.Services.GetMasaStackConfig();

if (!builder.Environment.IsDevelopment())
Expand All @@ -26,7 +26,7 @@
{
ServiceNameSpace = builder.Environment.EnvironmentName,
ServiceVersion = masaStackConfig.Version,
ServiceName = masaStackConfig.GetWebId(MasaStackConstant.MC),
ServiceName = masaStackConfig.GetWebId(MasaStackProject.MC),
Layer = masaStackConfig.Namespace,
ServiceInstanceId = builder.Configuration.GetValue<string>("HOSTNAME")
};
Expand All @@ -52,7 +52,7 @@
mcBaseAddress = masaStackConfig.GetMcServiceDomain();
}

builder.AddMasaStackComponentsForServer("wwwroot/i18n", authBaseAddress, mcBaseAddress);
await builder.Services.AddMasaStackComponentsAsync(MasaStackProject.MC, "wwwroot/i18n", authBaseAddress);

builder.Services.AddHttpContextAccessor();
builder.Services.AddGlobalForServer();
Expand All @@ -62,7 +62,7 @@
MasaOpenIdConnectOptions masaOpenIdConnectOptions = new MasaOpenIdConnectOptions
{
Authority = masaStackConfig.GetSsoDomain(),
ClientId = masaStackConfig.GetWebId(MasaStackConstant.MC),
ClientId = masaStackConfig.GetWebId(MasaStackProject.MC),
Scopes = new List<string> { "offline_access" }
}; ;

Expand Down
Loading

0 comments on commit 6800b17

Please sign in to comment.