修改scp
parent
03702477d6
commit
9e71732061
|
@ -1,35 +1,22 @@
|
||||||
using Aliyun.OSS;
|
using AlibabaCloud.SDK.Sts20150401;
|
||||||
using IRaCIS.Core.Infrastructure;
|
using Aliyun.OSS;
|
||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using Minio.DataModel.Args;
|
|
||||||
using Minio;
|
|
||||||
using SharpCompress.Common;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Security.AccessControl;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
using Minio.ApiEndpoints;
|
|
||||||
using System.Reactive.Linq;
|
|
||||||
using IRaCIS.Core.Domain.Share;
|
|
||||||
using IRaCIS.Core.Infrastructure.NewtonsoftJson;
|
|
||||||
using Amazon.Runtime;
|
|
||||||
using Amazon.SecurityToken;
|
|
||||||
using Amazon.SecurityToken.Model;
|
|
||||||
using Amazon;
|
using Amazon;
|
||||||
|
using Amazon.Runtime;
|
||||||
using Amazon.S3;
|
using Amazon.S3;
|
||||||
using Amazon.S3.Model;
|
using Amazon.S3.Model;
|
||||||
|
using Amazon.SecurityToken;
|
||||||
|
using Amazon.SecurityToken.Model;
|
||||||
|
using IRaCIS.Core.Infrastructure;
|
||||||
|
using IRaCIS.Core.Infrastructure.NewtonsoftJson;
|
||||||
using MassTransit;
|
using MassTransit;
|
||||||
using AlibabaCloud.SDK.Sts20150401;
|
using Microsoft.Extensions.Options;
|
||||||
|
using Minio;
|
||||||
|
using Minio.DataModel.Args;
|
||||||
|
using System.Reactive.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace IRaCIS.Core.SCP;
|
||||||
|
|
||||||
namespace IRaCIS.Core.SCP
|
|
||||||
{
|
|
||||||
#region 绑定和返回模型
|
#region 绑定和返回模型
|
||||||
|
|
||||||
[LowerCamelCaseJson]
|
[LowerCamelCaseJson]
|
||||||
|
@ -158,7 +145,7 @@ namespace IRaCIS.Core.SCP
|
||||||
|
|
||||||
public Task DeleteFromPrefix(string prefix);
|
public Task DeleteFromPrefix(string prefix);
|
||||||
|
|
||||||
public Task<ObjectStoreDTO> GetObjectStoreTempToken();
|
public ObjectStoreDTO GetObjectStoreTempToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -175,9 +162,10 @@ namespace IRaCIS.Core.SCP
|
||||||
{
|
{
|
||||||
ObjectStoreServiceOptions = options.CurrentValue;
|
ObjectStoreServiceOptions = options.CurrentValue;
|
||||||
|
|
||||||
GetObjectStoreTempToken().GetAwaiter().GetResult();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder
|
/// oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -188,6 +176,8 @@ namespace IRaCIS.Core.SCP
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<string> UploadToOSSAsync(Stream fileStream, string oosFolderPath, string fileRealName, bool isFileNameAddGuid = true)
|
public async Task<string> UploadToOSSAsync(Stream fileStream, string oosFolderPath, string fileRealName, bool isFileNameAddGuid = true)
|
||||||
{
|
{
|
||||||
|
GetObjectStoreTempToken();
|
||||||
|
|
||||||
var ossRelativePath = isFileNameAddGuid ? $"{oosFolderPath}/{Guid.NewGuid()}_{fileRealName}" : $"{oosFolderPath}/{fileRealName}";
|
var ossRelativePath = isFileNameAddGuid ? $"{oosFolderPath}/{Guid.NewGuid()}_{fileRealName}" : $"{oosFolderPath}/{fileRealName}";
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -287,6 +277,8 @@ namespace IRaCIS.Core.SCP
|
||||||
/// <exception cref="BusinessValidationFailedException"></exception>
|
/// <exception cref="BusinessValidationFailedException"></exception>
|
||||||
public async Task<string> UploadToOSSAsync(string localFilePath, string oosFolderPath, bool isFileNameAddGuid = true)
|
public async Task<string> UploadToOSSAsync(string localFilePath, string oosFolderPath, bool isFileNameAddGuid = true)
|
||||||
{
|
{
|
||||||
|
GetObjectStoreTempToken();
|
||||||
|
|
||||||
var localFileName = Path.GetFileName(localFilePath);
|
var localFileName = Path.GetFileName(localFilePath);
|
||||||
|
|
||||||
var ossRelativePath = isFileNameAddGuid ? $"{oosFolderPath}/{Guid.NewGuid()}_{localFileName}" : $"{oosFolderPath}/{localFileName}";
|
var ossRelativePath = isFileNameAddGuid ? $"{oosFolderPath}/{Guid.NewGuid()}_{localFileName}" : $"{oosFolderPath}/{localFileName}";
|
||||||
|
@ -355,6 +347,7 @@ namespace IRaCIS.Core.SCP
|
||||||
|
|
||||||
public async Task DownLoadFromOSSAsync(string ossRelativePath, string localFilePath)
|
public async Task DownLoadFromOSSAsync(string ossRelativePath, string localFilePath)
|
||||||
{
|
{
|
||||||
|
GetObjectStoreTempToken();
|
||||||
|
|
||||||
ossRelativePath = ossRelativePath.TrimStart('/');
|
ossRelativePath = ossRelativePath.TrimStart('/');
|
||||||
try
|
try
|
||||||
|
@ -440,6 +433,8 @@ namespace IRaCIS.Core.SCP
|
||||||
|
|
||||||
public async Task<string> GetSignedUrl(string ossRelativePath)
|
public async Task<string> GetSignedUrl(string ossRelativePath)
|
||||||
{
|
{
|
||||||
|
GetObjectStoreTempToken();
|
||||||
|
|
||||||
ossRelativePath = ossRelativePath.TrimStart('/');
|
ossRelativePath = ossRelativePath.TrimStart('/');
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -538,6 +533,8 @@ namespace IRaCIS.Core.SCP
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task DeleteFromPrefix(string prefix)
|
public async Task DeleteFromPrefix(string prefix)
|
||||||
{
|
{
|
||||||
|
GetObjectStoreTempToken();
|
||||||
|
|
||||||
if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS")
|
if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS")
|
||||||
{
|
{
|
||||||
var aliConfig = ObjectStoreServiceOptions.AliyunOSS;
|
var aliConfig = ObjectStoreServiceOptions.AliyunOSS;
|
||||||
|
@ -674,10 +671,9 @@ namespace IRaCIS.Core.SCP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ObjectStoreDTO GetObjectStoreTempToken()
|
||||||
|
|
||||||
public async Task<ObjectStoreDTO> GetObjectStoreTempToken()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
var ossOptions = ObjectStoreServiceOptions.AliyunOSS;
|
var ossOptions = ObjectStoreServiceOptions.AliyunOSS;
|
||||||
|
|
||||||
if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS")
|
if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS")
|
||||||
|
@ -745,7 +741,7 @@ namespace IRaCIS.Core.SCP
|
||||||
DurationSeconds = awsOptions.DurationSeconds // 临时凭证有效期
|
DurationSeconds = awsOptions.DurationSeconds // 临时凭证有效期
|
||||||
};
|
};
|
||||||
|
|
||||||
var assumeRoleResponse = await stsClient.AssumeRoleAsync(assumeRoleRequest);
|
var assumeRoleResponse = stsClient.AssumeRoleAsync(assumeRoleRequest).Result;
|
||||||
|
|
||||||
var credentials = assumeRoleResponse.Credentials;
|
var credentials = assumeRoleResponse.Credentials;
|
||||||
|
|
||||||
|
@ -772,6 +768,3 @@ namespace IRaCIS.Core.SCP
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue