Compare commits
No commits in common. "f14d4bf373c9872ca87dd42677d153a94d4b359a" and "9c447dbd68022354a1c55f3337397fc8c64edcb0" have entirely different histories.
f14d4bf373
...
9c447dbd68
|
|
@ -304,43 +304,45 @@ namespace IRaCIS.Api.Controllers
|
||||||
|
|
||||||
var ossOptions = serviceOption.AliyunOSS;
|
var ossOptions = serviceOption.AliyunOSS;
|
||||||
|
|
||||||
var client = new Client(new AlibabaCloud.OpenApiClient.Models.Config()
|
return ResponseOutput.Ok(new ObjectStoreDTO() { ObjectStoreUse = serviceOption.ObjectStoreUse, MinIO = serviceOption.MinIO, AliyunOSS = serviceOption.AliyunOSS, AWS = serviceOption.AWS });
|
||||||
{
|
|
||||||
//AccessKeyId = ossOptions.accessKeyId,
|
|
||||||
//AccessKeySecret = ossOptions.accessKeySecret,
|
|
||||||
AccessKeyId = "LTAI5tJV76pYX5yPg1N9QVE8",
|
|
||||||
AccessKeySecret = "roRNLa9YG1of4pYruJGCNKBXEWTAWa",
|
|
||||||
|
|
||||||
Endpoint = "sts.cn-hangzhou.aliyuncs.com"
|
#region 临时token 屏蔽
|
||||||
});
|
//IClientProfile profile = DefaultProfile.GetProfile(ossOptions.RegionId, ossOptions.AccessKeyId, ossOptions.AccessKeySecret);
|
||||||
|
//DefaultAcsClient client = new DefaultAcsClient(profile);
|
||||||
var assumeRoleRequest = new AlibabaCloud.SDK.Sts20150401.Models.AssumeRoleRequest();
|
|
||||||
// 将<YOUR_ROLE_SESSION_NAME>设置为自定义的会话名称,例如oss-role-session。
|
|
||||||
assumeRoleRequest.RoleSessionName = $"session-name-{NewId.NextGuid()}";
|
|
||||||
// 将<YOUR_ROLE_ARN>替换为拥有上传文件到指定OSS Bucket权限的RAM角色的ARN。
|
|
||||||
//assumeRoleRequest.RoleArn = ossOptions.roleArn;
|
|
||||||
assumeRoleRequest.RoleArn = "acs:ram::1899121822495495:role/webdirect";
|
|
||||||
assumeRoleRequest.DurationSeconds = 7200;
|
|
||||||
var runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
|
|
||||||
var response = client.AssumeRoleWithOptions(assumeRoleRequest, runtime);
|
|
||||||
var credentials = response.Body.Credentials;
|
|
||||||
|
|
||||||
var tempToken = new AliyunOSSTempToken()
|
|
||||||
{
|
|
||||||
AccessKeyId = credentials.AccessKeyId,
|
|
||||||
AccessKeySecret = credentials.AccessKeySecret,
|
|
||||||
Expiration = credentials.Expiration,
|
|
||||||
SecurityToken = credentials.SecurityToken,
|
|
||||||
|
|
||||||
|
|
||||||
Region = ossOptions.region,
|
//// 创建一个STS请求
|
||||||
BucketName = ossOptions.bucketName,
|
//AssumeRoleRequest request = new AssumeRoleRequest
|
||||||
ViewEndpoint = ossOptions.viewEndpoint,
|
//{
|
||||||
|
// RoleArn = ossOptions.RoleArn, // 角色ARN,需要替换为你的角色ARN
|
||||||
|
// RoleSessionName = $"session-name-{NewId.NextGuid()}", // 角色会话名称,可自定义
|
||||||
|
// DurationSeconds = 900, // 令牌有效期(单位:秒),这里设置为1小时
|
||||||
|
//};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
return ResponseOutput.Ok(new ObjectStoreDTO() { ObjectStoreUse = serviceOption.ObjectStoreUse, AliyunOSS = serviceOption.AliyunOSS, AliyunOSSTemp= tempToken });
|
//AssumeRoleResponse response = client.GetAcsResponse(request);
|
||||||
|
|
||||||
|
//// 返回STS令牌信息给前端
|
||||||
|
//var stsToken = new ObjectStoreDTO()
|
||||||
|
//{
|
||||||
|
// ObjectStoreUse = serviceOption.ObjectStoreUse,
|
||||||
|
// AliyunOSS = new AliyunOSSTempToken()
|
||||||
|
// {
|
||||||
|
// AccessKeyId = response.Credentials.AccessKeyId,
|
||||||
|
// AccessKeySecret = response.Credentials.AccessKeySecret,
|
||||||
|
// SecurityToken = response.Credentials.SecurityToken,
|
||||||
|
// Expiration = response.Credentials.Expiration,
|
||||||
|
|
||||||
|
// Region = ossOptions.Region,
|
||||||
|
// BucketName = ossOptions.BucketName,
|
||||||
|
// ViewEndpoint = ossOptions.ViewEndpoint,
|
||||||
|
|
||||||
|
// },
|
||||||
|
// MinIO = serviceOption.MinIO
|
||||||
|
//};
|
||||||
|
//return ResponseOutput.Ok(stsToken);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
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)
|
||||||
|
|
@ -354,21 +356,44 @@ namespace IRaCIS.Api.Controllers
|
||||||
|
|
||||||
}
|
}
|
||||||
[HttpGet("user/getUploadTempToken")]
|
[HttpGet("user/getUploadTempToken")]
|
||||||
public IResponseOutput GetUploadTempToken([FromServices] IOptionsMonitor<ObjectStoreServiceOptions> options)
|
public IResponseOutput GetUploadTempToken([FromServices] IOptionsMonitor<AliyunOSSOptions> options)
|
||||||
{
|
{
|
||||||
var serviceOption = options.CurrentValue;
|
var ossOptions = options.CurrentValue;
|
||||||
|
|
||||||
if (Enum.TryParse<ObjectStoreUse>(serviceOption.ObjectStoreUse, out var parsedEnum) && parsedEnum == ObjectStoreUse.AliyunOSS)
|
var client = new Client(new AlibabaCloud.OpenApiClient.Models.Config()
|
||||||
{
|
{
|
||||||
var ossOptions = serviceOption.AliyunOSS;
|
//AccessKeyId = ossOptions.accessKeyId,
|
||||||
|
//AccessKeySecret = ossOptions.accessKeySecret,
|
||||||
|
AccessKeyId = "LTAI5tJV76pYX5yPg1N9QVE8",
|
||||||
|
AccessKeySecret = "roRNLa9YG1of4pYruJGCNKBXEWTAWa",
|
||||||
|
|
||||||
|
Endpoint = "sts.cn-hangzhou.aliyuncs.com"
|
||||||
|
});
|
||||||
|
|
||||||
|
var assumeRoleRequest = new AlibabaCloud.SDK.Sts20150401.Models.AssumeRoleRequest();
|
||||||
|
// 将<YOUR_ROLE_SESSION_NAME>设置为自定义的会话名称,例如oss-role-session。
|
||||||
|
assumeRoleRequest.RoleSessionName = $"session-name-{NewId.NextGuid()}";
|
||||||
|
// 将<YOUR_ROLE_ARN>替换为拥有上传文件到指定OSS Bucket权限的RAM角色的ARN。
|
||||||
|
//assumeRoleRequest.RoleArn = ossOptions.roleArn;
|
||||||
|
assumeRoleRequest.RoleArn = "acs:ram::1899121822495495:role/webdirect";
|
||||||
|
assumeRoleRequest.DurationSeconds = 3600;
|
||||||
|
var runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
|
||||||
|
var response = client.AssumeRoleWithOptions(assumeRoleRequest, runtime);
|
||||||
|
var credentials = response.Body.Credentials;
|
||||||
|
|
||||||
|
return ResponseOutput.Ok(new
|
||||||
|
{
|
||||||
|
AccessKeyId = credentials.AccessKeyId,
|
||||||
|
AccessKeySecret = credentials.AccessKeySecret,
|
||||||
|
Expiration = credentials.Expiration,
|
||||||
|
SecurityToken = credentials.SecurityToken,
|
||||||
|
|
||||||
|
|
||||||
|
Region = ossOptions.region,
|
||||||
|
BucketName = ossOptions.bucketName,
|
||||||
|
ViewEndpoint = ossOptions.viewEndpoint,
|
||||||
|
|
||||||
}
|
});
|
||||||
|
|
||||||
return ResponseOutput.Ok();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ using System.Security.AccessControl;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace IRaCIS.Core.Application.Helper
|
namespace IRaCIS.Core.Application.Helper
|
||||||
{
|
{
|
||||||
|
|
@ -56,10 +55,7 @@ namespace IRaCIS.Core.Application.Helper
|
||||||
public class ObjectStoreServiceOptions
|
public class ObjectStoreServiceOptions
|
||||||
{
|
{
|
||||||
public string ObjectStoreUse { get; set; }
|
public string ObjectStoreUse { get; set; }
|
||||||
|
|
||||||
public AliyunOSSOptions AliyunOSS { get; set; }
|
public AliyunOSSOptions AliyunOSS { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public MinIOOptions MinIO { get; set; }
|
public MinIOOptions MinIO { get; set; }
|
||||||
|
|
||||||
public AWSOptions AWS { get; set; }
|
public AWSOptions AWS { get; set; }
|
||||||
|
|
@ -72,8 +68,6 @@ namespace IRaCIS.Core.Application.Helper
|
||||||
|
|
||||||
public AliyunOSSOptions AliyunOSS { get; set; }
|
public AliyunOSSOptions AliyunOSS { get; set; }
|
||||||
|
|
||||||
public AliyunOSSTempToken AliyunOSSTemp { get; set; }
|
|
||||||
|
|
||||||
public MinIOOptions MinIO { get; set; }
|
public MinIOOptions MinIO { get; set; }
|
||||||
|
|
||||||
public AWSOptions AWS { get; set; }
|
public AWSOptions AWS { get; set; }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue