From 3487365d56642aa11ffda336ce7d9165a1157c75 Mon Sep 17 00:00:00 2001 From: Soha Jin Date: Thu, 9 Sep 2021 18:23:22 +0800 Subject: Tencent COS: support setting storage class --- Duplicati/Library/Backend/TencentCOS/COSBackend.cs | 29 ++++++++++++++++------ Duplicati/Library/Backend/TencentCOS/Strings.cs | 3 +++ 2 files changed, 25 insertions(+), 7 deletions(-) (limited to 'Duplicati/Library') diff --git a/Duplicati/Library/Backend/TencentCOS/COSBackend.cs b/Duplicati/Library/Backend/TencentCOS/COSBackend.cs index 5951c50b3..249999fa8 100644 --- a/Duplicati/Library/Backend/TencentCOS/COSBackend.cs +++ b/Duplicati/Library/Backend/TencentCOS/COSBackend.cs @@ -29,6 +29,7 @@ namespace Duplicati.Library.Backend.TencentCOS private const string COS_SECRET_ID = "cos-secret-id"; private const string COS_SECRET_KEY = "cos-secret-key"; private const string COS_BUCKET = "cos-bucket"; + private const string COS_STORAGE_CLASS = "cos-storage-class"; /// /// Set default HTTPS request @@ -81,6 +82,11 @@ namespace Duplicati.Library.Backend.TencentCOS /// A path or subfolder in a bucket /// public string Path { get; set; } + /// + /// Storage class of the object + /// https://cloud.tencent.com/document/product/436/33417 + /// + public string StorageClass { get; set; } } public COS() { } @@ -121,6 +127,11 @@ namespace Duplicati.Library.Backend.TencentCOS { _cosOptions.Bucket = options[COS_BUCKET]; } + + if (options.ContainsKey(COS_STORAGE_CLASS)) + { + _cosOptions.StorageClass = options[COS_STORAGE_CLASS]; + } } CosXml GetCosXml() @@ -290,6 +301,10 @@ namespace Duplicati.Library.Backend.TencentCOS request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), KEY_DURATION_SECOND); request.SetRequestHeader("Content-Type", "application/octet-stream"); + if (!string.IsNullOrEmpty(_cosOptions.StorageClass)) + { + request.SetRequestHeader("x-" + COS_STORAGE_CLASS, _cosOptions.StorageClass); + } PutObjectResult result = cosXml.PutObject(request); } @@ -348,8 +363,7 @@ namespace Duplicati.Library.Backend.TencentCOS string sourceRegion = _cosOptions.Region; string sourceKey = GetFullKey(oldname); - CopySourceStruct copySource = new CopySourceStruct(sourceAppid, sourceBucket, - sourceRegion, sourceKey); + CopySourceStruct copySource = new CopySourceStruct(sourceAppid, sourceBucket, sourceRegion, sourceKey); string bucket = _cosOptions.Bucket; string key = GetFullKey(newname); @@ -388,11 +402,12 @@ namespace Duplicati.Library.Backend.TencentCOS get { return new List(new ICommandLineArgument[] { - new CommandLineArgument(COS_APP_ID, CommandLineArgument.ArgumentType.String, Strings.COSBackend.COSAccountDescriptionShort,Strings.COSBackend.COSAccountDescriptionLong), - new CommandLineArgument(COS_REGION, CommandLineArgument.ArgumentType.String, Strings.COSBackend.COSLocationDescriptionShort,Strings.COSBackend.COSLocationDescriptionLong), - new CommandLineArgument(COS_SECRET_ID, CommandLineArgument.ArgumentType.String, Strings.COSBackend.COSAPISecretIdDescriptionShort,Strings.COSBackend.COSAPISecretIdDescriptionLong), - new CommandLineArgument(COS_SECRET_KEY, CommandLineArgument.ArgumentType.Password, Strings.COSBackend.COSAPISecretKeyDescriptionShort,Strings.COSBackend.COSAPISecretKeyDescriptionLong), - new CommandLineArgument(COS_BUCKET, CommandLineArgument.ArgumentType.String,Strings.COSBackend.COSBucketDescriptionShort,Strings.COSBackend.COSBucketDescriptionLong), + new CommandLineArgument(COS_APP_ID, CommandLineArgument.ArgumentType.String, Strings.COSBackend.COSAccountDescriptionShort, Strings.COSBackend.COSAccountDescriptionLong), + new CommandLineArgument(COS_REGION, CommandLineArgument.ArgumentType.String, Strings.COSBackend.COSLocationDescriptionShort, Strings.COSBackend.COSLocationDescriptionLong), + new CommandLineArgument(COS_SECRET_ID, CommandLineArgument.ArgumentType.String, Strings.COSBackend.COSAPISecretIdDescriptionShort, Strings.COSBackend.COSAPISecretIdDescriptionLong), + new CommandLineArgument(COS_SECRET_KEY, CommandLineArgument.ArgumentType.Password, Strings.COSBackend.COSAPISecretKeyDescriptionShort, Strings.COSBackend.COSAPISecretKeyDescriptionLong), + new CommandLineArgument(COS_BUCKET, CommandLineArgument.ArgumentType.String, Strings.COSBackend.COSBucketDescriptionShort, Strings.COSBackend.COSBucketDescriptionLong), + new CommandLineArgument(COS_STORAGE_CLASS, CommandLineArgument.ArgumentType.String, Strings.COSBackend.COSStorageClassDescriptionShort, Strings.COSBackend.COSStorageClassDescriptionLong) }); } } diff --git a/Duplicati/Library/Backend/TencentCOS/Strings.cs b/Duplicati/Library/Backend/TencentCOS/Strings.cs index 65fe0ff37..9d02eb7e9 100644 --- a/Duplicati/Library/Backend/TencentCOS/Strings.cs +++ b/Duplicati/Library/Backend/TencentCOS/Strings.cs @@ -21,6 +21,9 @@ namespace Duplicati.Library.Backend.Strings public static string COSLocationDescriptionShort { get { return LC.L(@"Specifies COS location constraints"); } } public static string COSLocationDescriptionLong { get { return LC.L(@"Region (Region) is the distribution area of ​​the Tencent cloud hosting machine room, the object storage COS data is stored in the storage buckets of these regions. https://cloud.tencent.com/document/product/436/6224"); } } + + public static string COSStorageClassDescriptionShort { get { return LC.L(@"Storage class of the object"); } } + public static string COSStorageClassDescriptionLong { get { return LC.L(@"Storage class of the object; check enumerated values at https://cloud.tencent.com/document/product/436/33417."); } } } } -- cgit v1.2.3