diff options
author | Soha Jin <soha@lohu.info> | 2021-09-09 13:23:22 +0300 |
---|---|---|
committer | Soha Jin <soha@lohu.info> | 2021-09-09 13:23:22 +0300 |
commit | 3487365d56642aa11ffda336ce7d9165a1157c75 (patch) | |
tree | 60e64e242479e8454189b65b69edfcd9a3aa8764 /Duplicati/Library/Backend/TencentCOS/COSBackend.cs | |
parent | b9aad24deb4a4c88bb284bce3a6ee64e1939ce9e (diff) |
Tencent COS: support setting storage class
Diffstat (limited to 'Duplicati/Library/Backend/TencentCOS/COSBackend.cs')
-rw-r--r-- | Duplicati/Library/Backend/TencentCOS/COSBackend.cs | 29 |
1 files changed, 22 insertions, 7 deletions
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"; /// <summary> /// Set default HTTPS request @@ -81,6 +82,11 @@ namespace Duplicati.Library.Backend.TencentCOS /// A path or subfolder in a bucket /// </summary> public string Path { get; set; } + /// <summary> + /// Storage class of the object + /// https://cloud.tencent.com/document/product/436/33417 + /// </summary> + 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<ICommandLineArgument>(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) }); } } |