Skip to content

Commit

Permalink
fix restore param days (#52)
Browse files Browse the repository at this point in the history
* dev_tidy (merge request !28)

Squash merge branch 'dev_tidy_e8e91608' into 'master'

* 预签名下载不做路径校验

* dev_signUrlDownloadFix (merge request !31)

Squash merge branch 'dev_signUrlDownloadFix' into 'master'

* 状态判断后写入文件

* update

* 404下载创建文件

* dev_bucketPolicy (merge request !34)

Squash merge branch 'dev_bucketPolicy' into 'master'

* dev_optimDemoAndDocNew (merge request !35)

Squash merge branch 'dev_optimDemoAndDocNew' into 'master'
bucket policy逻辑更新到github上

* 更新版本 (merge request !36)

Squash merge branch 'dev_addVersiion' into 'master'

* add interface

* add interface

* add interface

* add request

* dev_optdemo (merge request !41)

Squash merge branch 'dev_optdemo' into 'master'

* modify version (merge request !42)

Squash merge branch 'dev_ci_doc' into 'master'
modify verison

* dev_demoopt13 (merge request !43)

Squash merge branch 'dev_demoopt13' into 'master'

* dev_demoopt14 (merge request !45)

Squash merge branch 'dev_demoopt14' into 'master'

* dev_demo0919 (merge request !46)

Squash merge branch 'dev_demo0919' into 'master'

* region校验降低拼接转跳风险

* add sign & document

* Object restore恢复参数Days

---------

Co-authored-by: nedzzhang <[email protected]>
Co-authored-by: weiyankong <[email protected]>
Co-authored-by: weiyankong <[email protected]>
  • Loading branch information
4 people authored Jan 16, 2025
1 parent bf24381 commit 4735756
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 7 deletions.
14 changes: 10 additions & 4 deletions QCloudCSharpSDK/COSXML/Model/Object/RestoreObjectRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using COSXML.Model.Tag;
using COSXML.Common;
using COSXML.CosException;
using COSXML.Network;

namespace COSXML.Model.Object
Expand All @@ -27,6 +28,7 @@ public RestoreObjectRequest(string bucket, string key)
this.queryParameters.Add("restore", null);
restoreConfigure = new RestoreConfigure();
restoreConfigure.casJobParameters = new RestoreConfigure.CASJobParameters();
restoreConfigure.days = 0;
}

/// <summary>
Expand All @@ -35,12 +37,10 @@ public RestoreObjectRequest(string bucket, string key)
/// <param name="days"></param>
public void SetExpireDays(int days)
{

if (days < 0)
if (days <= 0)
{
days = 0;
throw new CosClientException(-1, "param 'Days' ranges from 1-365, Some storage types do not need call SetExpireDays function to set Days param");
}

restoreConfigure.days = days;
}

Expand All @@ -65,6 +65,12 @@ public void SetVersionId(string versionId)

public override Network.RequestBody GetRequestBody()
{
if (restoreConfigure.days == 0)
{
RestoreConfigureNoDays restoreConfigureNoDays = new RestoreConfigureNoDays();
restoreConfigureNoDays.casJobParameters = restoreConfigure.casJobParameters;
return GetXmlRequestBody(restoreConfigureNoDays);
}
return GetXmlRequestBody(restoreConfigure);
}
}
Expand Down
13 changes: 13 additions & 0 deletions QCloudCSharpSDK/COSXML/Model/Tag/RestoreConfigure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,17 @@ public enum Tier
Bulk
}
}

[XmlRoot("RestoreRequest")]
public sealed class RestoreConfigureNoDays
{
/// <summary>
/// 归档存储工作参数配置
/// <see href="CASJobParameters"/>
/// </summary>
[XmlElement("CASJobParameters")]
public RestoreConfigure.CASJobParameters casJobParameters;
}


}
8 changes: 7 additions & 1 deletion QCloudCSharpSDK/COSXMLDemo/MainProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ static void Main(string[] args)

public void DoSomething()
{

// BucketPolicyModel.BucketPolicyMain();
// DownloadObject.DownloadObjectMain();
// UploadObject.UploadObjectMain();

// BucketPolicyModel.BucketPolicyMain();
// DownloadObject.DownloadObjectMain();
UploadObject.UploadObjectMain();
Expand All @@ -40,13 +43,16 @@ public void DoSomething()
// BucketReplicationModel.BucketReplicationMain();
// BucketLoggingModel.BucketLoggingMain();


// BucketTaggingModel.BucketTaggingMain();


// ObjectTaggingModel.ObjectTaggingMain();
// BucketInventoryModel.BucketInventoryMain();
// BucketDomainModel.BucketDomainMain();
// PutObjectACLModel.PutObjectACLMain();//
// BucketRefererModel.BucketRefererMain();//

// BucketWebsiteModel.BucketWebsiteMain();

}
Expand Down
1 change: 1 addition & 0 deletions QCloudCSharpSDK/COSXMLDemo/Object/ObjectRestore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void RestoreObject()
string key = "exampleObject"; //对象键
RestoreObjectRequest request = new RestoreObjectRequest(bucket, key);
//恢复时间
request.SetExpireDays(3); //https://cloud.tencent.com/document/product/436/12633
request.SetExpireDays(3);
request.SetTier(COSXML.Model.Tag.RestoreConfigure.Tier.Bulk);
//执行请求
Expand Down
47 changes: 45 additions & 2 deletions QCloudCSharpSDK/COSXMLTests/ObjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,8 +1071,13 @@ public void RestoreObject()
cosXml.PutObject(putRequest);

RestoreObjectRequest request = new RestoreObjectRequest(bucket, objectKey);
//恢复时间
request.SetExpireDays(-1);
//恢复时间,时间参数在1-365内
try {
request.SetExpireDays(-1); }
catch (COSXML.CosException.CosClientException clientEx) {
Assert.True(true);
}

request.SetExpireDays(3);
request.SetTier(COSXML.Model.Tag.RestoreConfigure.Tier.Standard);

Expand Down Expand Up @@ -1100,6 +1105,44 @@ public void RestoreObject()
Assert.Fail();
}
}


[Test()]
public void RestoreObjectNoDaysParam()
{


string objectKey = "archive_object";
try
{
byte[] data = File.ReadAllBytes(smallFileSrcPath);
PutObjectRequest putRequest = new PutObjectRequest(bucket, objectKey, data);
putRequest.SetCosStorageClass("DEEP_ARCHIVE");
cosXml.PutObject(putRequest);
RestoreObjectRequest request = new RestoreObjectRequest(bucket, objectKey);
request.SetTier(COSXML.Model.Tag.RestoreConfigure.Tier.Standard);

//执行请求,该请求不设置Days参数
RestoreObjectResult result = cosXml.RestoreObject(request);
Assert.True(result.IsSuccessful());
request.SetVersionId("null");
DeleteObjectRequest deleteRequest = new DeleteObjectRequest(bucket, objectKey);
deleteRequest.SetVersionId("null");
DeleteObjectResult deleteObjectResult = cosXml.DeleteObject(deleteRequest);
Assert.True(deleteObjectResult.IsSuccessful());
}
catch (COSXML.CosException.CosClientException clientEx)
{
Console.WriteLine("CosClientException: " + clientEx.Message);
Assert.Fail();
}
catch (COSXML.CosException.CosServerException serverEx)
{
Console.WriteLine("CosServerException: " + serverEx.GetInfo());
Assert.Fail();
}
}


[Test()]
public void PostObject()
Expand Down

0 comments on commit 4735756

Please sign in to comment.