Compare commits

..

No commits in common. "55cbbffba6087e8cd135491da72cadfa4d5f3301" and "0582390b2c96a3e2defc86b4ec4ebfca096326d5" have entirely different histories.

3 changed files with 61 additions and 82 deletions

View File

@ -143,49 +143,44 @@ namespace IRaCIS.Api.Controllers
if (Enum.TryParse<ObjectStoreUse>(serviceOption.ObjectStoreUse, out var parsedEnum) && parsedEnum == ObjectStoreUse.AliyunOSS) if (Enum.TryParse<ObjectStoreUse>(serviceOption.ObjectStoreUse, out var parsedEnum) && parsedEnum == ObjectStoreUse.AliyunOSS)
{ {
var ossOptions = serviceOption.AliyunOSS; var ossOptions = serviceOption.AliyunOSS;
return ResponseOutput.Ok(new ObjectStoreDTO() { ObjectStoreUse = serviceOption.ObjectStoreUse, MinIO = serviceOption.MinIO ,AliyunOSS= serviceOption.AliyunOSS }); IClientProfile profile = DefaultProfile.GetProfile(ossOptions.RegionId, ossOptions.AccessKeyId, ossOptions.AccessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile);
#region 临时token 屏蔽
//IClientProfile profile = DefaultProfile.GetProfile(ossOptions.RegionId, ossOptions.AccessKeyId, ossOptions.AccessKeySecret);
//DefaultAcsClient client = new DefaultAcsClient(profile);
//// 创建一个STS请求 // 创建一个STS请求
//AssumeRoleRequest request = new AssumeRoleRequest AssumeRoleRequest request = new AssumeRoleRequest
//{ {
// RoleArn = ossOptions.RoleArn, // 角色ARN需要替换为你的角色ARN RoleArn = ossOptions.RoleArn, // 角色ARN需要替换为你的角色ARN
// RoleSessionName = $"session-name-{NewId.NextGuid()}", // 角色会话名称,可自定义 RoleSessionName = $"session-name-{NewId.NextGuid()}", // 角色会话名称,可自定义
// DurationSeconds = 900, // 令牌有效期单位这里设置为1小时 DurationSeconds = 900, // 令牌有效期单位这里设置为1小时
//}; };
//AssumeRoleResponse response = client.GetAcsResponse(request); AssumeRoleResponse response = client.GetAcsResponse(request);
//// 返回STS令牌信息给前端 // 返回STS令牌信息给前端
//var stsToken = new ObjectStoreDTO() var stsToken = new ObjectStoreDTO()
//{ {
// ObjectStoreUse = serviceOption.ObjectStoreUse, ObjectStoreUse = serviceOption.ObjectStoreUse,
// AliyunOSS = new AliyunOSSTempToken() AliyunOSS = new AliyunOSSTempToken()
// { {
// AccessKeyId = response.Credentials.AccessKeyId, AccessKeyId = response.Credentials.AccessKeyId,
// AccessKeySecret = response.Credentials.AccessKeySecret, AccessKeySecret = response.Credentials.AccessKeySecret,
// SecurityToken = response.Credentials.SecurityToken, SecurityToken = response.Credentials.SecurityToken,
// Expiration = response.Credentials.Expiration, Expiration = response.Credentials.Expiration,
// Region = ossOptions.Region, Region = ossOptions.Region,
// BucketName = ossOptions.BucketName, BucketName = ossOptions.BucketName,
// ViewEndpoint = ossOptions.ViewEndpoint, ViewEndpoint = ossOptions.ViewEndpoint,
// }, },
// MinIO = serviceOption.MinIO MinIO = serviceOption.MinIO
//}; }
//return ResponseOutput.Ok(stsToken); ;
#endregion
return ResponseOutput.Ok(stsToken);
} }
else if (Enum.TryParse<ObjectStoreUse>(serviceOption.ObjectStoreUse, out var parsedValue) && parsedValue == ObjectStoreUse.MinIO) else if (Enum.TryParse<ObjectStoreUse>(serviceOption.ObjectStoreUse, out var parsedValue) && parsedValue == ObjectStoreUse.MinIO)
{ {
@ -204,14 +199,14 @@ namespace IRaCIS.Api.Controllers
var ossOptions = options.CurrentValue; var ossOptions = options.CurrentValue;
IClientProfile profile = DefaultProfile.GetProfile(ossOptions.regionId, ossOptions.accessKeyId, ossOptions.accessKeySecret); IClientProfile profile = DefaultProfile.GetProfile(ossOptions.RegionId, ossOptions.AccessKeyId, ossOptions.AccessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile); DefaultAcsClient client = new DefaultAcsClient(profile);
// 创建一个STS请求 // 创建一个STS请求
AssumeRoleRequest request = new AssumeRoleRequest AssumeRoleRequest request = new AssumeRoleRequest
{ {
RoleArn = ossOptions.roleArn, // 角色ARN需要替换为你的角色ARN RoleArn = ossOptions.RoleArn, // 角色ARN需要替换为你的角色ARN
RoleSessionName = $"session-name-{NewId.NextGuid()}", // 角色会话名称,可自定义 RoleSessionName = $"session-name-{NewId.NextGuid()}", // 角色会话名称,可自定义
DurationSeconds = 900, // 令牌有效期单位这里设置为1小时 DurationSeconds = 900, // 令牌有效期单位这里设置为1小时
}; };
@ -227,9 +222,9 @@ namespace IRaCIS.Api.Controllers
SecurityToken = response.Credentials.SecurityToken, SecurityToken = response.Credentials.SecurityToken,
Expiration = response.Credentials.Expiration, Expiration = response.Credentials.Expiration,
Region = ossOptions.region , Region = ossOptions.Region,
BucketName = ossOptions.bucketName , BucketName = ossOptions.BucketName,
ViewEndpoint = ossOptions.viewEndpoint , ViewEndpoint = ossOptions.ViewEndpoint,
}; };

View File

@ -6,31 +6,16 @@
"Microsoft.Hosting.Lifetime": "Information" "Microsoft.Hosting.Lifetime": "Information"
} }
}, },
"ObjectStoreService": {
"ObjectStoreUse": "AliyunOSS",
"AliyunOSS": { "AliyunOSS": {
"regionId": "cn-shanghai", "regionId": "cn-shanghai",
"region": "oss-cn-shanghai",
"endpoint": "https://oss-cn-shanghai.aliyuncs.com", "endpoint": "https://oss-cn-shanghai.aliyuncs.com",
"accessKeyId": "LTAI5tKvzs7ed3UfSpNk3xwQ", "accessKeyId": "LTAI5tKvzs7ed3UfSpNk3xwQ",
"accessKeySecret": "zTIceGEShlZDGnLrCFfIGFE7TXVRio", "accessKeySecret": "zTIceGEShlZDGnLrCFfIGFE7TXVRio",
"bucketName": "zy-sir-test-store", "bucketName": "zy-sir-test-store",
"roleArn": "acs:ram::1899121822495495:role/oss-upload", "RoleArn": "acs:ram::1899121822495495:role/oss-upload",
"viewEndpoint": "https://zy-sir-test-store.oss-cn-shanghai.aliyuncs.com", "viewEndpoint": "https://zy-sir-test-store.oss-cn-shanghai.aliyuncs.com"
"region": "oss-cn-shanghai"
}, },
"MinIO": {
"endpoint": "http://192.168.3.68",
"port": "8001",
"useSSL": false,
"accessKey": "IDFkwEpWej0b4DtiuThL",
"secretKey": "Lhuu83yMhVwu7c1SnjvGY6lq74jzpYqifK6Qtj4h",
"bucketName": "test"
}
},
"ConnectionStrings": { "ConnectionStrings": {
"RemoteNew": "Server=123.56.94.154,1433\\MSSQLSERVER;Database=Test.Study;User ID=sa;Password=dev123456DEV;TrustServerCertificate=true", "RemoteNew": "Server=123.56.94.154,1433\\MSSQLSERVER;Database=Test.Study;User ID=sa;Password=dev123456DEV;TrustServerCertificate=true",
"Hangfire": "Server=123.56.94.154,1433\\MSSQLSERVER;Database=Test.Study.hangfire;User ID=sa;Password=dev123456DEV;TrustServerCertificate=true" "Hangfire": "Server=123.56.94.154,1433\\MSSQLSERVER;Database=Test.Study.hangfire;User ID=sa;Password=dev123456DEV;TrustServerCertificate=true"

View File

@ -18,27 +18,27 @@ namespace IRaCIS.Core.Application.Helper
{ {
public class MinIOOptions public class MinIOOptions
{ {
public string endpoint { get; set; } public string Endpoint { get; set; }
public string port { get; set; } public string Port { get; set; }
public bool useSSL { get; set; } public bool UseSSL { get; set; }
public string accessKey { get; set; } public string AccessKey { get; set; }
public string secretKey { get; set; } public string SecretKey { get; set; }
public string bucketName { get; set; } public string BucketName { get; set; }
} }
public class AliyunOSSOptions public class AliyunOSSOptions
{ {
public string regionId { get; set; } public string RegionId { get; set; }
public string accessKeyId { get; set; } public string AccessKeyId { get; set; }
public string accessKeySecret { get; set; } public string AccessKeySecret { get; set; }
public string endPoint { get; set; } public string EndPoint { get; set; }
public string bucketName { get; set; } public string BucketName { get; set; }
public string roleArn { get; set; } public string RoleArn { get; set; }
public string region { get; set; } public string Region { get; set; }
public string viewEndpoint { get; set; } public string ViewEndpoint { get; set; }
} }
@ -53,8 +53,7 @@ namespace IRaCIS.Core.Application.Helper
public class ObjectStoreDTO public class ObjectStoreDTO
{ {
public string ObjectStoreUse { get; set; } public string ObjectStoreUse { get; set; }
public AliyunOSSTempToken AliyunOSS { get; set; }
public AliyunOSSOptions AliyunOSS { get; set; }
public MinIOOptions MinIO { get; set; } public MinIOOptions MinIO { get; set; }
@ -110,7 +109,7 @@ namespace IRaCIS.Core.Application.Helper
_OSSConfig = ossOptions; _OSSConfig = ossOptions;
_ossClient = new OssClient(_OSSConfig.endPoint, _OSSConfig.accessKeyId, _OSSConfig.accessKeySecret); _ossClient = new OssClient(_OSSConfig.EndPoint, _OSSConfig.AccessKeyId, _OSSConfig.AccessKeySecret);
} }
@ -138,7 +137,7 @@ namespace IRaCIS.Core.Application.Helper
memoryStream.Seek(0, SeekOrigin.Begin); memoryStream.Seek(0, SeekOrigin.Begin);
// 上传文件 // 上传文件
var result = _ossClient.PutObject(_OSSConfig.bucketName, ossRelativePath, memoryStream); var result = _ossClient.PutObject(_OSSConfig.BucketName, ossRelativePath, memoryStream);
} }
@ -168,7 +167,7 @@ namespace IRaCIS.Core.Application.Helper
try try
{ {
// 上传文件 // 上传文件
var result = _ossClient.PutObject(_OSSConfig.bucketName, ossRelativePath, localFilePath); var result = _ossClient.PutObject(_OSSConfig.BucketName, ossRelativePath, localFilePath);
return ossRelativePath; return ossRelativePath;
} }
@ -183,7 +182,7 @@ namespace IRaCIS.Core.Application.Helper
{ {
try try
{ {
var result = _ossClient.GetObject(_OSSConfig.bucketName, ossRelativePath); var result = _ossClient.GetObject(_OSSConfig.BucketName, ossRelativePath);
// 将下载的文件流保存到本地文件 // 将下载的文件流保存到本地文件
using (var fs = File.OpenWrite(localFilePath)) using (var fs = File.OpenWrite(localFilePath))