diff --git a/sdk/include/alibabacloud/oss/Const.h b/sdk/include/alibabacloud/oss/Const.h index b7f75e6..4bb0ca0 100644 --- a/sdk/include/alibabacloud/oss/Const.h +++ b/sdk/include/alibabacloud/oss/Const.h @@ -1,59 +1,62 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once -#include - -namespace AlibabaCloud -{ -namespace OSS -{ - const int64_t MaxFileSize = 5LL * 1024LL * 1024LL * 1024LL; - const int32_t MaxPrefixStringSize = 1024; - const int32_t MaxMarkerStringSize = 1024; - const int32_t MaxDelimiterStringSize = 1024; - const int32_t MaxReturnedKeys = 1000; - const int32_t MaxUploads = 1000; - const int32_t DeleteObjectsUpperLimit = 1000; - const int32_t BucketCorsRuleLimit = 10; - const int32_t LifecycleRuleLimit = 1000; - const int32_t ObjectNameLengthLimit = 1023; - const int32_t PartNumberUpperLimit = 10000; - const int32_t DefaultPartSize = 8 * 1024 * 1024; - const int32_t PartSizeLowerLimit = 100 * 1024; - const int32_t MaxPathLength = 124; - const int32_t MinPathLength = 4; - const int32_t DefaultResumableThreadNum = 3; - const uint32_t MaxLiveChannelNameLength = 1023; - const uint32_t MaxLiveChannelDescriptionLength = 128; - const uint32_t MinLiveChannelFragCount = 1; - const uint32_t MaxLiveChannelFragCount = 100; - const uint32_t MinLiveChannelFragDuration = 1; - const uint32_t MaxLiveChannelFragDuration = 100; - const uint32_t MinLiveChannelPlayListLength = 6; - const uint32_t MaxLiveChannelPlayListLength = 128; - const uint32_t MinLiveChannelInterval = 1; - const uint32_t MaxLiveChannelInterval = 100; - const uint64_t SecondsOfDay = 24*60*60; - const uint32_t MaxListLiveChannelKeys = 1000; - -#ifdef _WIN32 - const char PATH_DELIMITER = '\\'; -#else - const char PATH_DELIMITER = '/'; -#endif -} -} +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include + +namespace AlibabaCloud +{ +namespace OSS +{ + const int64_t MaxFileSize = 5LL * 1024LL * 1024LL * 1024LL; + const int32_t MaxPrefixStringSize = 1024; + const int32_t MaxMarkerStringSize = 1024; + const int32_t MaxDelimiterStringSize = 1024; + const int32_t MaxReturnedKeys = 1000; + const int32_t MaxUploads = 1000; + const int32_t DeleteObjectsUpperLimit = 1000; + const int32_t BucketCorsRuleLimit = 10; + const int32_t LifecycleRuleLimit = 1000; + const int32_t ObjectNameLengthLimit = 1023; + const int32_t PartNumberUpperLimit = 10000; + const int32_t DefaultPartSize = 8 * 1024 * 1024; + const int32_t PartSizeLowerLimit = 100 * 1024; + const int32_t MaxPathLength = 124; + const int32_t MinPathLength = 4; + const int32_t DefaultResumableThreadNum = 3; + const uint32_t MaxLiveChannelNameLength = 1023; + const uint32_t MaxLiveChannelDescriptionLength = 128; + const uint32_t MinLiveChannelFragCount = 1; + const uint32_t MaxLiveChannelFragCount = 100; + const uint32_t MinLiveChannelFragDuration = 1; + const uint32_t MaxLiveChannelFragDuration = 100; + const uint32_t MinLiveChannelPlayListLength = 6; + const uint32_t MaxLiveChannelPlayListLength = 128; + const uint32_t MinLiveChannelInterval = 1; + const uint32_t MaxLiveChannelInterval = 100; + const uint64_t SecondsOfDay = 24*60*60; + const uint32_t MaxListLiveChannelKeys = 1000; + const uint32_t TagKeyLengthLimit = 128; + const uint32_t TagValueLengthLimit = 256; + const uint32_t MaxTagSize = 10; + +#ifdef _WIN32 + const char PATH_DELIMITER = '\\'; +#else + const char PATH_DELIMITER = '/'; +#endif +} +} diff --git a/sdk/include/alibabacloud/oss/OssClient.h b/sdk/include/alibabacloud/oss/OssClient.h index 193f869..4233026 100644 --- a/sdk/include/alibabacloud/oss/OssClient.h +++ b/sdk/include/alibabacloud/oss/OssClient.h @@ -170,6 +170,10 @@ namespace OSS GetObjectOutcome SelectObject(const SelectObjectRequest& request) const; CreateSelectObjectMetaOutcome CreateSelectObjectMeta(const CreateSelectObjectMetaRequest& request) const; + SetObjectTaggingOutcome SetObjectTagging(const SetObjectTaggingRequest& request) const; + DeleteObjectTaggingOutcome DeleteObjectTagging(const DeleteObjectTaggingRequest& request) const; + GetObjectTaggingOutcome GetObjectTagging(const GetObjectTaggingRequest& request) const; + /*MultipartUpload*/ InitiateMultipartUploadOutcome InitiateMultipartUpload(const InitiateMultipartUploadRequest& request) const; PutObjectOutcome UploadPart(const UploadPartRequest& request) const; @@ -235,7 +239,7 @@ namespace OSS void DisableRequest(); void EnableRequest(); private: - OssClientImpl *client_; + std::shared_ptr client_; }; } } diff --git a/sdk/include/alibabacloud/oss/OssFwd.h b/sdk/include/alibabacloud/oss/OssFwd.h index 7d55748..d3dd733 100644 --- a/sdk/include/alibabacloud/oss/OssFwd.h +++ b/sdk/include/alibabacloud/oss/OssFwd.h @@ -121,6 +121,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include namespace AlibabaCloud @@ -156,8 +162,10 @@ namespace OSS using CopyObjectOutcome = Outcome; using GetSymlinkOutcome = Outcome; using CreateSymlinkOutcome = Outcome; - using CreateSelectObjectMetaOutcome = Outcome; + using SetObjectTaggingOutcome = Outcome; + using GetObjectTaggingOutcome = Outcome; + using DeleteObjectTaggingOutcome = Outcome; /*multipart*/ using InitiateMultipartUploadOutcome = Outcome; diff --git a/sdk/include/alibabacloud/oss/model/AppendObjectRequest.h b/sdk/include/alibabacloud/oss/model/AppendObjectRequest.h index 0920eb1..5e8443c 100644 --- a/sdk/include/alibabacloud/oss/model/AppendObjectRequest.h +++ b/sdk/include/alibabacloud/oss/model/AppendObjectRequest.h @@ -1,55 +1,56 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once -#include -#include -#include -#include - - -namespace AlibabaCloud -{ -namespace OSS -{ - class ALIBABACLOUD_OSS_EXPORT AppendObjectRequest: public OssObjectRequest - { - public: - AppendObjectRequest(const std::string& bucket, const std::string& key, - const std::shared_ptr& content); - AppendObjectRequest(const std::string& bucket, const std::string& key, - const std::shared_ptr& content, - const ObjectMetaData& meta); - void setPosition(uint64_t position); - void setCacheControl(const std::string& value); - void setContentDisposition(const std::string& value); - void setContentEncoding(const std::string& value); - void setContentMd5(const std::string& value); - void setExpires(uint64_t expires); - void setExpires(const std::string& value); - void setAcl(const CannedAccessControlList& acl); - virtual std::shared_ptr Body() const; - protected: - virtual HeaderCollection specialHeaders() const ; - virtual ParameterCollection specialParameters() const; - private: - uint64_t position_; - std::shared_ptr content_; - ObjectMetaData metaData_; - }; -} -} - +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include +#include +#include + + +namespace AlibabaCloud +{ +namespace OSS +{ + class ALIBABACLOUD_OSS_EXPORT AppendObjectRequest: public OssObjectRequest + { + public: + AppendObjectRequest(const std::string& bucket, const std::string& key, + const std::shared_ptr& content); + AppendObjectRequest(const std::string& bucket, const std::string& key, + const std::shared_ptr& content, + const ObjectMetaData& meta); + void setPosition(uint64_t position); + void setCacheControl(const std::string& value); + void setContentDisposition(const std::string& value); + void setContentEncoding(const std::string& value); + void setContentMd5(const std::string& value); + void setExpires(uint64_t expires); + void setExpires(const std::string& value); + void setAcl(const CannedAccessControlList& acl); + void setTagging(const std::string& value); + virtual std::shared_ptr Body() const; + protected: + virtual HeaderCollection specialHeaders() const ; + virtual ParameterCollection specialParameters() const; + private: + uint64_t position_; + std::shared_ptr content_; + ObjectMetaData metaData_; + }; +} +} + diff --git a/sdk/include/alibabacloud/oss/model/CopyObjectRequest.h b/sdk/include/alibabacloud/oss/model/CopyObjectRequest.h index 7fd21ef..1142ddd 100644 --- a/sdk/include/alibabacloud/oss/model/CopyObjectRequest.h +++ b/sdk/include/alibabacloud/oss/model/CopyObjectRequest.h @@ -1,48 +1,50 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once -#include -#include -#include -#include - - -namespace AlibabaCloud -{ -namespace OSS -{ - class ALIBABACLOUD_OSS_EXPORT CopyObjectRequest: public OssObjectRequest - { - public: - CopyObjectRequest(const std::string& bucket, const std::string& key); - CopyObjectRequest(const std::string& bucket, const std::string& key, - const ObjectMetaData& meta); - void setCopySource(const std::string& srcBucket,const std::string& srcObject); - void setSourceIfMatchETag(const std::string& value); - void setSourceIfNotMatchETag(const std::string& value); - void setSourceIfUnModifiedSince(const std::string& value); - void setSourceIfModifiedSince(const std::string& value); - void setMetadataDirective(const CopyActionList& action); - void setAcl(const CannedAccessControlList& acl); - protected: - virtual HeaderCollection specialHeaders() const ; - private: - ObjectMetaData metaData_; - }; -} -} - +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include +#include +#include + + +namespace AlibabaCloud +{ +namespace OSS +{ + class ALIBABACLOUD_OSS_EXPORT CopyObjectRequest: public OssObjectRequest + { + public: + CopyObjectRequest(const std::string& bucket, const std::string& key); + CopyObjectRequest(const std::string& bucket, const std::string& key, + const ObjectMetaData& meta); + void setCopySource(const std::string& srcBucket,const std::string& srcObject); + void setSourceIfMatchETag(const std::string& value); + void setSourceIfNotMatchETag(const std::string& value); + void setSourceIfUnModifiedSince(const std::string& value); + void setSourceIfModifiedSince(const std::string& value); + void setMetadataDirective(const CopyActionList& action); + void setAcl(const CannedAccessControlList& acl); + void setTagging(const std::string& value); + void setTaggingDirective(const CopyActionList& action); + protected: + virtual HeaderCollection specialHeaders() const ; + private: + ObjectMetaData metaData_; + }; +} +} + diff --git a/sdk/include/alibabacloud/oss/model/CreateSymlinkRequest.h b/sdk/include/alibabacloud/oss/model/CreateSymlinkRequest.h index 5b331c4..5512c65 100644 --- a/sdk/include/alibabacloud/oss/model/CreateSymlinkRequest.h +++ b/sdk/include/alibabacloud/oss/model/CreateSymlinkRequest.h @@ -1,42 +1,43 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once -#include -#include -#include -#include - -namespace AlibabaCloud -{ -namespace OSS -{ - class ALIBABACLOUD_OSS_EXPORT CreateSymlinkRequest: public OssObjectRequest - { - public: - CreateSymlinkRequest(const std::string& bucket, const std::string& key); - CreateSymlinkRequest(const std::string& bucket, const std::string& key, - const ObjectMetaData& meta); - void SetSymlinkTarget(const std::string& value); - protected: - virtual HeaderCollection specialHeaders() const ; - virtual ParameterCollection specialParameters() const; - private: - ObjectMetaData metaData_; - }; -} -} - +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include +#include +#include + +namespace AlibabaCloud +{ +namespace OSS +{ + class ALIBABACLOUD_OSS_EXPORT CreateSymlinkRequest: public OssObjectRequest + { + public: + CreateSymlinkRequest(const std::string& bucket, const std::string& key); + CreateSymlinkRequest(const std::string& bucket, const std::string& key, + const ObjectMetaData& meta); + void SetSymlinkTarget(const std::string& value); + void setTagging(const std::string& value); + protected: + virtual HeaderCollection specialHeaders() const ; + virtual ParameterCollection specialParameters() const; + private: + ObjectMetaData metaData_; + }; +} +} + diff --git a/sdk/include/alibabacloud/oss/model/DeleteObjectTaggingRequest.h b/sdk/include/alibabacloud/oss/model/DeleteObjectTaggingRequest.h new file mode 100644 index 0000000..f4c7b59 --- /dev/null +++ b/sdk/include/alibabacloud/oss/model/DeleteObjectTaggingRequest.h @@ -0,0 +1,33 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include + +namespace AlibabaCloud +{ +namespace OSS +{ + class ALIBABACLOUD_OSS_EXPORT DeleteObjectTaggingRequest : public OssObjectRequest + { + public: + DeleteObjectTaggingRequest(const std::string& bucket, const std::string& key); + protected: + virtual ParameterCollection specialParameters() const; + }; +} +} diff --git a/sdk/include/alibabacloud/oss/model/DeleteObjectTaggingResult.h b/sdk/include/alibabacloud/oss/model/DeleteObjectTaggingResult.h new file mode 100644 index 0000000..b7dbb83 --- /dev/null +++ b/sdk/include/alibabacloud/oss/model/DeleteObjectTaggingResult.h @@ -0,0 +1,32 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include + +namespace AlibabaCloud +{ +namespace OSS +{ + class ALIBABACLOUD_OSS_EXPORT DeleteObjectTaggingResult : public OssResult + { + public: + DeleteObjectTaggingResult() {} + }; +} +} + diff --git a/sdk/include/alibabacloud/oss/model/GetObjectTaggingRequest.h b/sdk/include/alibabacloud/oss/model/GetObjectTaggingRequest.h new file mode 100644 index 0000000..2a65928 --- /dev/null +++ b/sdk/include/alibabacloud/oss/model/GetObjectTaggingRequest.h @@ -0,0 +1,33 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include + +namespace AlibabaCloud +{ +namespace OSS +{ + class ALIBABACLOUD_OSS_EXPORT GetObjectTaggingRequest : public OssObjectRequest + { + public: + GetObjectTaggingRequest(const std::string& bucket, const std::string& key); + protected: + virtual ParameterCollection specialParameters() const; + }; +} +} diff --git a/sdk/include/alibabacloud/oss/model/GetObjectTaggingResult.h b/sdk/include/alibabacloud/oss/model/GetObjectTaggingResult.h new file mode 100644 index 0000000..d82511e --- /dev/null +++ b/sdk/include/alibabacloud/oss/model/GetObjectTaggingResult.h @@ -0,0 +1,38 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include +#include + +namespace AlibabaCloud +{ +namespace OSS +{ + class ALIBABACLOUD_OSS_EXPORT GetObjectTaggingResult : public OssResult + { + public: + GetObjectTaggingResult(); + GetObjectTaggingResult(const std::string& data); + GetObjectTaggingResult(const std::shared_ptr& data); + GetObjectTaggingResult& operator=(const std::string& data); + const AlibabaCloud::OSS::Tagging& Tagging() const { return tagging_; }; + private: + AlibabaCloud::OSS::Tagging tagging_; + }; +} +} diff --git a/sdk/include/alibabacloud/oss/model/InitiateMultipartUploadRequest.h b/sdk/include/alibabacloud/oss/model/InitiateMultipartUploadRequest.h index 6ea61e6..8f74501 100644 --- a/sdk/include/alibabacloud/oss/model/InitiateMultipartUploadRequest.h +++ b/sdk/include/alibabacloud/oss/model/InitiateMultipartUploadRequest.h @@ -1,48 +1,49 @@ -/* - * Copyright 2009-2018 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once -#include -#include -#include - -namespace AlibabaCloud -{ -namespace OSS -{ - - class ALIBABACLOUD_OSS_EXPORT InitiateMultipartUploadRequest: public OssObjectRequest - { - public: - InitiateMultipartUploadRequest(const std::string& bucket, const std::string& key); - InitiateMultipartUploadRequest(const std::string& bucket, const std::string& key, - const ObjectMetaData& metaData); - void setCacheControl(const std::string& value); - void setContentDisposition(const std::string& value); - void setContentEncoding(const std::string& value); - void setExpires(const std::string& value); - ObjectMetaData& MetaData(); - void setEncodingType(const std::string& encodingType); - protected: - virtual HeaderCollection specialHeaders() const; - virtual ParameterCollection specialParameters() const; - private: - ObjectMetaData metaData_; - std::string encodingType_; - bool encodingTypeIsSet_; - }; -} -} +/* + * Copyright 2009-2018 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include +#include + +namespace AlibabaCloud +{ +namespace OSS +{ + + class ALIBABACLOUD_OSS_EXPORT InitiateMultipartUploadRequest: public OssObjectRequest + { + public: + InitiateMultipartUploadRequest(const std::string& bucket, const std::string& key); + InitiateMultipartUploadRequest(const std::string& bucket, const std::string& key, + const ObjectMetaData& metaData); + void setCacheControl(const std::string& value); + void setContentDisposition(const std::string& value); + void setContentEncoding(const std::string& value); + void setExpires(const std::string& value); + ObjectMetaData& MetaData(); + void setEncodingType(const std::string& encodingType); + void setTagging(const std::string& value); + protected: + virtual HeaderCollection specialHeaders() const; + virtual ParameterCollection specialParameters() const; + private: + ObjectMetaData metaData_; + std::string encodingType_; + bool encodingTypeIsSet_; + }; +} +} diff --git a/sdk/include/alibabacloud/oss/model/LifecycleRule.h b/sdk/include/alibabacloud/oss/model/LifecycleRule.h index 778ccd3..75ae0e3 100644 --- a/sdk/include/alibabacloud/oss/model/LifecycleRule.h +++ b/sdk/include/alibabacloud/oss/model/LifecycleRule.h @@ -1,93 +1,98 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once -#include -#include -#include -#include - -namespace AlibabaCloud -{ -namespace OSS -{ - class ALIBABACLOUD_OSS_EXPORT LifeCycleExpiration - { - public: - LifeCycleExpiration(); - LifeCycleExpiration(uint32_t days); - LifeCycleExpiration(const std::string& createdBeforeDate); - void setDays(uint32_t days); - void setCreatedBeforeDate(const std::string& date); - uint32_t Days() const { return days_; } - const std::string& CreatedBeforeDate() const { return createdBeforeDate_; } - private: - uint32_t days_; - std::string createdBeforeDate_; - }; - - class ALIBABACLOUD_OSS_EXPORT LifeCycleTransition - { - public: - LifeCycleTransition() = default; - LifeCycleTransition(const LifeCycleExpiration& expiration, AlibabaCloud::OSS::StorageClass storageClass); - void setExpiration(const LifeCycleExpiration& expiration); - void setStorageClass(AlibabaCloud::OSS::StorageClass storageClass); - const LifeCycleExpiration& Expiration() const { return expiration_; } - LifeCycleExpiration& Expiration() { return expiration_; } - AlibabaCloud::OSS::StorageClass StorageClass() const { return storageClass_; } - private: - LifeCycleExpiration expiration_; - AlibabaCloud::OSS::StorageClass storageClass_; - }; - - using LifeCycleTransitionList = std::vector; - - class ALIBABACLOUD_OSS_EXPORT LifecycleRule - { - public: - LifecycleRule() = default; - const std::string& ID() const { return id_; } - const std::string& Prefix() const { return prefix_; } - RuleStatus Status() const { return status_;} - const LifeCycleExpiration& Expiration() const { return expiration_; } - const LifeCycleTransitionList& TransitionList() const { return transitionList_; } - const LifeCycleExpiration& AbortMultipartUpload() const { return abortMultipartUpload_; } - LifeCycleExpiration& Expiration() { return expiration_; } - LifeCycleTransitionList& TransitionList() { return transitionList_; } - LifeCycleExpiration& AbortMultipartUpload() { return abortMultipartUpload_; } - void setID(const std::string& id) { id_ = id; } - void setPrefix(const std::string& prefix) { prefix_ = prefix; } - void setStatus(RuleStatus status) { status_ = status; } - void setExpiration(const LifeCycleExpiration& expiration) { expiration_ = expiration; } - void addTransition(const LifeCycleTransition&transition) { transitionList_.push_back(transition); } - void setTransitionList(const LifeCycleTransitionList& transitionList) { transitionList_ = transitionList; } - void setAbortMultipartUpload(const LifeCycleExpiration& expiration) { abortMultipartUpload_ = expiration; } - bool hasExpiration() const; - bool hasTransitionList() const; - bool hasAbortMultipartUpload() const; - bool operator==(const LifecycleRule& right) const; - private: - std::string id_; - std::string prefix_; - RuleStatus status_; - LifeCycleExpiration expiration_; - LifeCycleTransitionList transitionList_; - LifeCycleExpiration abortMultipartUpload_; - }; - using LifecycleRuleList = std::vector; -} -} +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include +#include +#include +#include + +namespace AlibabaCloud +{ +namespace OSS +{ + class ALIBABACLOUD_OSS_EXPORT LifeCycleExpiration + { + public: + LifeCycleExpiration(); + LifeCycleExpiration(uint32_t days); + LifeCycleExpiration(const std::string& createdBeforeDate); + void setDays(uint32_t days); + void setCreatedBeforeDate(const std::string& date); + uint32_t Days() const { return days_; } + const std::string& CreatedBeforeDate() const { return createdBeforeDate_; } + private: + uint32_t days_; + std::string createdBeforeDate_; + }; + + class ALIBABACLOUD_OSS_EXPORT LifeCycleTransition + { + public: + LifeCycleTransition() = default; + LifeCycleTransition(const LifeCycleExpiration& expiration, AlibabaCloud::OSS::StorageClass storageClass); + void setExpiration(const LifeCycleExpiration& expiration); + void setStorageClass(AlibabaCloud::OSS::StorageClass storageClass); + const LifeCycleExpiration& Expiration() const { return expiration_; } + LifeCycleExpiration& Expiration() { return expiration_; } + AlibabaCloud::OSS::StorageClass StorageClass() const { return storageClass_; } + private: + LifeCycleExpiration expiration_; + AlibabaCloud::OSS::StorageClass storageClass_; + }; + + using LifeCycleTransitionList = std::vector; + + class ALIBABACLOUD_OSS_EXPORT LifecycleRule + { + public: + LifecycleRule() = default; + const std::string& ID() const { return id_; } + const std::string& Prefix() const { return prefix_; } + RuleStatus Status() const { return status_;} + const LifeCycleExpiration& Expiration() const { return expiration_; } + const LifeCycleTransitionList& TransitionList() const { return transitionList_; } + const LifeCycleExpiration& AbortMultipartUpload() const { return abortMultipartUpload_; } + LifeCycleExpiration& Expiration() { return expiration_; } + LifeCycleTransitionList& TransitionList() { return transitionList_; } + LifeCycleExpiration& AbortMultipartUpload() { return abortMultipartUpload_; } + const TagSet& Tags() const { return tagSet_; } + void setID(const std::string& id) { id_ = id; } + void setPrefix(const std::string& prefix) { prefix_ = prefix; } + void setStatus(RuleStatus status) { status_ = status; } + void setExpiration(const LifeCycleExpiration& expiration) { expiration_ = expiration; } + void addTransition(const LifeCycleTransition&transition) { transitionList_.push_back(transition); } + void setTransitionList(const LifeCycleTransitionList& transitionList) { transitionList_ = transitionList; } + void setAbortMultipartUpload(const LifeCycleExpiration& expiration) { abortMultipartUpload_ = expiration; } + void addTag(const Tag& tag) { tagSet_.push_back(tag); } + void setTags(const TagSet& tags) { tagSet_ = tags; } + bool hasExpiration() const; + bool hasTransitionList() const; + bool hasAbortMultipartUpload() const; + bool operator==(const LifecycleRule& right) const; + private: + std::string id_; + std::string prefix_; + RuleStatus status_; + LifeCycleExpiration expiration_; + LifeCycleTransitionList transitionList_; + LifeCycleExpiration abortMultipartUpload_; + TagSet tagSet_; + }; + using LifecycleRuleList = std::vector; +} +} diff --git a/sdk/include/alibabacloud/oss/model/PutObjectRequest.h b/sdk/include/alibabacloud/oss/model/PutObjectRequest.h index c65ba15..e551afa 100644 --- a/sdk/include/alibabacloud/oss/model/PutObjectRequest.h +++ b/sdk/include/alibabacloud/oss/model/PutObjectRequest.h @@ -1,51 +1,52 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once -#include -#include -#include -#include - -namespace AlibabaCloud -{ -namespace OSS -{ - class ALIBABACLOUD_OSS_EXPORT PutObjectRequest: public OssObjectRequest - { - public: - PutObjectRequest(const std::string& bucket, const std::string& key, - const std::shared_ptr& content); - PutObjectRequest(const std::string& bucket, const std::string& key, - const std::shared_ptr& content, - const ObjectMetaData& meta); - void setCacheControl(const std::string& value); - void setContentDisposition(const std::string& value); - void setContentEncoding(const std::string& value); - void setContentMd5(const std::string& value); - void setExpires(const std::string& value); - void setCallback(const std::string& callback, const std::string& callbackVar = ""); - ObjectMetaData& MetaData(); - virtual std::shared_ptr Body() const; - protected: - virtual HeaderCollection specialHeaders() const; - virtual int validate() const; - private: - std::shared_ptr content_; - ObjectMetaData metaData_; - }; -} -} +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include +#include +#include + +namespace AlibabaCloud +{ +namespace OSS +{ + class ALIBABACLOUD_OSS_EXPORT PutObjectRequest: public OssObjectRequest + { + public: + PutObjectRequest(const std::string& bucket, const std::string& key, + const std::shared_ptr& content); + PutObjectRequest(const std::string& bucket, const std::string& key, + const std::shared_ptr& content, + const ObjectMetaData& meta); + void setCacheControl(const std::string& value); + void setContentDisposition(const std::string& value); + void setContentEncoding(const std::string& value); + void setContentMd5(const std::string& value); + void setExpires(const std::string& value); + void setCallback(const std::string& callback, const std::string& callbackVar = ""); + void setTagging(const std::string& value); + ObjectMetaData& MetaData(); + virtual std::shared_ptr Body() const; + protected: + virtual HeaderCollection specialHeaders() const; + virtual int validate() const; + private: + std::shared_ptr content_; + ObjectMetaData metaData_; + }; +} +} diff --git a/sdk/include/alibabacloud/oss/model/SetObjectTaggingRequest.h b/sdk/include/alibabacloud/oss/model/SetObjectTaggingRequest.h new file mode 100644 index 0000000..e73ea99 --- /dev/null +++ b/sdk/include/alibabacloud/oss/model/SetObjectTaggingRequest.h @@ -0,0 +1,41 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include +#include + +namespace AlibabaCloud +{ +namespace OSS +{ + class ALIBABACLOUD_OSS_EXPORT SetObjectTaggingRequest : public OssObjectRequest + { + public: + SetObjectTaggingRequest(const std::string& bucket, const std::string& key); + SetObjectTaggingRequest(const std::string& bucket, const std::string& key, + const Tagging& tagging); + void setTagging(const Tagging& tagging); + protected: + virtual std::string payload() const; + virtual ParameterCollection specialParameters() const; + virtual int validate() const; + private: + Tagging tagging_; + }; +} +} diff --git a/sdk/include/alibabacloud/oss/model/SetObjectTaggingResult.h b/sdk/include/alibabacloud/oss/model/SetObjectTaggingResult.h new file mode 100644 index 0000000..2ed2ac2 --- /dev/null +++ b/sdk/include/alibabacloud/oss/model/SetObjectTaggingResult.h @@ -0,0 +1,32 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include + +namespace AlibabaCloud +{ +namespace OSS +{ + class ALIBABACLOUD_OSS_EXPORT SetObjectTaggingResult : public OssResult + { + public: + SetObjectTaggingResult() {} + }; +} +} + diff --git a/sdk/include/alibabacloud/oss/model/Tagging.h b/sdk/include/alibabacloud/oss/model/Tagging.h new file mode 100644 index 0000000..8ea3388 --- /dev/null +++ b/sdk/include/alibabacloud/oss/model/Tagging.h @@ -0,0 +1,59 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include +namespace AlibabaCloud +{ +namespace OSS +{ + class ALIBABACLOUD_OSS_EXPORT Tag + { + public: + Tag() {}; + Tag(const std::string& key, const std::string& value) : + key_(key), value_(value) + {} + void setKey(const std::string& key) { key_ = key; } + void setValue(const std::string& value) { value_ = value; } + const std::string& Key() const { return key_; } + const std::string& Value() const { return value_; } + private: + std::string key_; + std::string value_; + }; + + using TagSet = std::vector; + + class ALIBABACLOUD_OSS_EXPORT Tagging + { + public: + Tagging() {}; + Tagging(const TagSet& tags) { tagSet_ = tags;} + + const TagSet& Tags() const { return tagSet_; } + void setTags(const TagSet& tags) { tagSet_ = tags; } + void setTags(TagSet&& tags) { tagSet_ = std::move(tags); } + void addTag(const Tag& tag) { tagSet_.push_back(tag) ; } + void addTag(Tag&& tag) { tagSet_.push_back(std::move(tag)); } + void clear() { tagSet_.clear();} + std::string toQueryParameters(); + private: + TagSet tagSet_; + }; +} +} diff --git a/sdk/include/alibabacloud/oss/model/UploadObjectRequest.h b/sdk/include/alibabacloud/oss/model/UploadObjectRequest.h index a8297a5..06eb37a 100644 --- a/sdk/include/alibabacloud/oss/model/UploadObjectRequest.h +++ b/sdk/include/alibabacloud/oss/model/UploadObjectRequest.h @@ -1,68 +1,69 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once -#include -#include -#include -#include -#include - -namespace AlibabaCloud -{ -namespace OSS -{ - class ALIBABACLOUD_OSS_EXPORT UploadObjectRequest : public OssResumableBaseRequest - { - public: - UploadObjectRequest(const std::string& bucket, const std::string& key, - const std::string& filePath, const std::string& checkpointDir, - const uint64_t partSize, const uint32_t threadNum); - UploadObjectRequest(const std::string& bucket, const std::string& key, - const std::string& filePath, const std::string &checkpointDir, - const uint64_t partSize, const uint32_t threadNum, const ObjectMetaData& meta); - UploadObjectRequest(const std::string& bucket, const std::string& key, - const std::string& filePath, const std::string& checkpointDir, - const ObjectMetaData& meta); - UploadObjectRequest(const std::string& bucket, const std::string& key, - const std::string& filePath, const std::string& checkpointDir); - UploadObjectRequest(const std::string& bucket, const std::string& key, - const std::string& filePath); - - std::shared_ptr Content(){ return content_; } - const std::string& EncodingType() const{return encodingType_;} - const std::string& FilePath() const{return filePath_;} - const ObjectMetaData& MetaData() const { return metaData_; } - ObjectMetaData& MetaData() { return metaData_; } - - void setCacheControl(const std::string& value){metaData_.addHeader(Http::CACHE_CONTROL, value);} - void setContentDisposition(const std::string& value){metaData_.addHeader(Http::CONTENT_DISPOSITION, value);} - void setContentEncoding(const std::string& value){metaData_.addHeader(Http::CONTENT_ENCODING, value);} - void setExpires(const std::string& value){metaData_.addHeader(Http::EXPIRES, value);} - void setAcl(CannedAccessControlList& acl); - void setCallback(const std::string& callback, const std::string& callbackVar = ""); - void setEncodingType(const std::string& type) {encodingType_ = type; } - - protected: - virtual int validate() const; - private: - std::string filePath_; - std::shared_ptr content_; - ObjectMetaData metaData_; - std::string encodingType_; - }; -} +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include +#include +#include +#include + +namespace AlibabaCloud +{ +namespace OSS +{ + class ALIBABACLOUD_OSS_EXPORT UploadObjectRequest : public OssResumableBaseRequest + { + public: + UploadObjectRequest(const std::string& bucket, const std::string& key, + const std::string& filePath, const std::string& checkpointDir, + const uint64_t partSize, const uint32_t threadNum); + UploadObjectRequest(const std::string& bucket, const std::string& key, + const std::string& filePath, const std::string &checkpointDir, + const uint64_t partSize, const uint32_t threadNum, const ObjectMetaData& meta); + UploadObjectRequest(const std::string& bucket, const std::string& key, + const std::string& filePath, const std::string& checkpointDir, + const ObjectMetaData& meta); + UploadObjectRequest(const std::string& bucket, const std::string& key, + const std::string& filePath, const std::string& checkpointDir); + UploadObjectRequest(const std::string& bucket, const std::string& key, + const std::string& filePath); + + std::shared_ptr Content(){ return content_; } + const std::string& EncodingType() const{return encodingType_;} + const std::string& FilePath() const{return filePath_;} + const ObjectMetaData& MetaData() const { return metaData_; } + ObjectMetaData& MetaData() { return metaData_; } + + void setCacheControl(const std::string& value){metaData_.addHeader(Http::CACHE_CONTROL, value);} + void setContentDisposition(const std::string& value){metaData_.addHeader(Http::CONTENT_DISPOSITION, value);} + void setContentEncoding(const std::string& value){metaData_.addHeader(Http::CONTENT_ENCODING, value);} + void setExpires(const std::string& value){metaData_.addHeader(Http::EXPIRES, value);} + void setAcl(CannedAccessControlList& acl); + void setCallback(const std::string& callback, const std::string& callbackVar = ""); + void setEncodingType(const std::string& type) {encodingType_ = type; } + void setTagging(const std::string& value); + + protected: + virtual int validate() const; + private: + std::string filePath_; + std::shared_ptr content_; + ObjectMetaData metaData_; + std::string encodingType_; + }; +} } \ No newline at end of file diff --git a/sdk/src/OssClient.cc b/sdk/src/OssClient.cc index 2ac329b..3fbe31c 100644 --- a/sdk/src/OssClient.cc +++ b/sdk/src/OssClient.cc @@ -90,16 +90,12 @@ OssClient::OssClient(const std::string &endpoint, const Credentials &credentials } OssClient::OssClient(const std::string &endpoint, const std::shared_ptr& credentialsProvider, const ClientConfiguration & configuration) : - client_(new OssClientImpl(endpoint, credentialsProvider, configuration)) + client_(std::make_shared(endpoint, credentialsProvider, configuration)) { } OssClient::~OssClient() { - if (client_) { - delete client_; - } - client_ = nullptr; } ListBucketsOutcome OssClient::ListBuckets() const @@ -520,6 +516,21 @@ CreateSelectObjectMetaOutcome OssClient::CreateSelectObjectMeta(const CreateSele return client_->CreateSelectObjectMeta(request); } +SetObjectTaggingOutcome OssClient::SetObjectTagging(const SetObjectTaggingRequest& request) const +{ + return client_->SetObjectTagging(request); +} + +DeleteObjectTaggingOutcome OssClient::DeleteObjectTagging(const DeleteObjectTaggingRequest& request) const +{ + return client_->DeleteObjectTagging(request); +} + +GetObjectTaggingOutcome OssClient::GetObjectTagging(const GetObjectTaggingRequest& request) const +{ + return client_->GetObjectTagging(request); +} + StringOutcome OssClient::GeneratePresignedUrl(const GeneratePresignedUrlRequest &request) const { return client_->GeneratePresignedUrl(request); diff --git a/sdk/src/OssClientImpl.cc b/sdk/src/OssClientImpl.cc index f8738de..6629bbb 100644 --- a/sdk/src/OssClientImpl.cc +++ b/sdk/src/OssClientImpl.cc @@ -873,6 +873,46 @@ CreateSelectObjectMetaOutcome OssClientImpl::CreateSelectObjectMeta(const Create } } +SetObjectTaggingOutcome OssClientImpl::SetObjectTagging(const SetObjectTaggingRequest& request) const +{ + auto outcome = MakeRequest(request, Http::Method::Put); + if (outcome.isSuccess()) { + SetObjectTaggingResult result; + result.requestId_ = outcome.result().RequestId(); + return SetObjectTaggingOutcome(std::move(result)); + } + else { + return SetObjectTaggingOutcome(outcome.error()); + } +} + +DeleteObjectTaggingOutcome OssClientImpl::DeleteObjectTagging(const DeleteObjectTaggingRequest& request) const +{ + auto outcome = MakeRequest(request, Http::Method::Delete); + if (outcome.isSuccess()) { + DeleteObjectTaggingResult result; + result.requestId_ = outcome.result().RequestId(); + return DeleteObjectTaggingOutcome(std::move(result)); + } + else { + return DeleteObjectTaggingOutcome(outcome.error()); + } +} + +GetObjectTaggingOutcome OssClientImpl::GetObjectTagging(const GetObjectTaggingRequest& request) const +{ + auto outcome = MakeRequest(request, Http::Method::Get); + if (outcome.isSuccess()) { + GetObjectTaggingResult result(outcome.result().payload()); + result.requestId_ = outcome.result().RequestId(); + return result.ParseDone() ? GetObjectTaggingOutcome(std::move(result)) : + GetObjectTaggingOutcome(OssError("ParseXMLError", "Parsing ObjectTagging result fail.")); + } + else { + return GetObjectTaggingOutcome(outcome.error()); + } +} + StringOutcome OssClientImpl::GeneratePresignedUrl(const GeneratePresignedUrlRequest &request) const { if (!IsValidBucketName(request.bucket_) || diff --git a/sdk/src/OssClientImpl.h b/sdk/src/OssClientImpl.h index 0b1743d..e76c519 100644 --- a/sdk/src/OssClientImpl.h +++ b/sdk/src/OssClientImpl.h @@ -92,6 +92,10 @@ namespace OSS GetObjectOutcome SelectObject(const SelectObjectRequest &request) const; CreateSelectObjectMetaOutcome CreateSelectObjectMeta(const CreateSelectObjectMetaRequest &request) const; + SetObjectTaggingOutcome SetObjectTagging(const SetObjectTaggingRequest& request) const; + DeleteObjectTaggingOutcome DeleteObjectTagging(const DeleteObjectTaggingRequest& request) const; + GetObjectTaggingOutcome GetObjectTagging(const GetObjectTaggingRequest& request) const; + /*MultipartUpload*/ InitiateMultipartUploadOutcome InitiateMultipartUpload(const InitiateMultipartUploadRequest &request) const; PutObjectOutcome UploadPart(const UploadPartRequest& request) const; diff --git a/sdk/src/model/AppendObjectRequest.cc b/sdk/src/model/AppendObjectRequest.cc index caea2f2..bb4362e 100644 --- a/sdk/src/model/AppendObjectRequest.cc +++ b/sdk/src/model/AppendObjectRequest.cc @@ -77,6 +77,11 @@ void AppendObjectRequest::setAcl(const CannedAccessControlList& acl) metaData_.addHeader("x-oss-object-acl", ToAclName(acl)); } +void AppendObjectRequest::setTagging(const std::string& value) +{ + metaData_.addHeader("x-oss-tagging", value); +} + std::shared_ptr AppendObjectRequest::Body() const { return content_; diff --git a/sdk/src/model/CopyObjectRequest.cc b/sdk/src/model/CopyObjectRequest.cc index d46e218..5761b7e 100644 --- a/sdk/src/model/CopyObjectRequest.cc +++ b/sdk/src/model/CopyObjectRequest.cc @@ -1,84 +1,94 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "../utils/Utils.h" -#include -using namespace AlibabaCloud::OSS; - -CopyObjectRequest::CopyObjectRequest(const std::string &bucket, const std::string &key): - OssObjectRequest(bucket, key) -{ -} - -CopyObjectRequest::CopyObjectRequest(const std::string &bucket, const std::string &key, - const ObjectMetaData &metaData): - OssObjectRequest(bucket, key), - metaData_(metaData) -{ -} - -void CopyObjectRequest::setCopySource(const std::string& srcBucket,const std::string& srcObject) -{ - std::stringstream ssDesc; - ssDesc << "/" << srcBucket << "/" << UrlEncode(srcObject); - std::string value = ssDesc.str(); - metaData_.addHeader("x-oss-copy-source", value); -} - -void CopyObjectRequest::setSourceIfMatchETag(const std::string& value) -{ - metaData_.addHeader("x-oss-copy-source-if-match", value); -} - -void CopyObjectRequest::setSourceIfNotMatchETag(const std::string& value) -{ - metaData_.addHeader("x-oss-copy-source-if-none-match", value); -} - -void CopyObjectRequest::setSourceIfUnModifiedSince(const std::string& value) -{ - metaData_.addHeader("x-oss-copy-source-if-unmodified-since", value); -} - -void CopyObjectRequest::setSourceIfModifiedSince(const std::string& value) -{ - metaData_.addHeader("x-oss-copy-source-if-modified-since", value); -} - -void CopyObjectRequest::setMetadataDirective(const CopyActionList& action) -{ - metaData_.addHeader("x-oss-metadata-directive", ToCopyActionName(action)); -} - -void CopyObjectRequest::setAcl(const CannedAccessControlList& acl) -{ - metaData_.addHeader("x-oss-object-acl", ToAclName(acl)); -} - -HeaderCollection CopyObjectRequest::specialHeaders() const -{ - auto headers = metaData_.toHeaderCollection(); - - if (headers.find(Http::CONTENT_TYPE) == headers.end()) { - headers[Http::CONTENT_TYPE] = LookupMimeType(Key()); - } - - return headers; -} - +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include "../utils/Utils.h" +#include +using namespace AlibabaCloud::OSS; + +CopyObjectRequest::CopyObjectRequest(const std::string &bucket, const std::string &key): + OssObjectRequest(bucket, key) +{ +} + +CopyObjectRequest::CopyObjectRequest(const std::string &bucket, const std::string &key, + const ObjectMetaData &metaData): + OssObjectRequest(bucket, key), + metaData_(metaData) +{ +} + +void CopyObjectRequest::setCopySource(const std::string& srcBucket,const std::string& srcObject) +{ + std::stringstream ssDesc; + ssDesc << "/" << srcBucket << "/" << UrlEncode(srcObject); + std::string value = ssDesc.str(); + metaData_.addHeader("x-oss-copy-source", value); +} + +void CopyObjectRequest::setSourceIfMatchETag(const std::string& value) +{ + metaData_.addHeader("x-oss-copy-source-if-match", value); +} + +void CopyObjectRequest::setSourceIfNotMatchETag(const std::string& value) +{ + metaData_.addHeader("x-oss-copy-source-if-none-match", value); +} + +void CopyObjectRequest::setSourceIfUnModifiedSince(const std::string& value) +{ + metaData_.addHeader("x-oss-copy-source-if-unmodified-since", value); +} + +void CopyObjectRequest::setSourceIfModifiedSince(const std::string& value) +{ + metaData_.addHeader("x-oss-copy-source-if-modified-since", value); +} + +void CopyObjectRequest::setMetadataDirective(const CopyActionList& action) +{ + metaData_.addHeader("x-oss-metadata-directive", ToCopyActionName(action)); +} + +void CopyObjectRequest::setAcl(const CannedAccessControlList& acl) +{ + metaData_.addHeader("x-oss-object-acl", ToAclName(acl)); +} + +void CopyObjectRequest::setTagging(const std::string& value) +{ + metaData_.addHeader("x-oss-tagging", value); +} + +void CopyObjectRequest::setTaggingDirective(const CopyActionList& action) +{ + metaData_.addHeader("x-oss-tagging-directive", ToCopyActionName(action)); +} + +HeaderCollection CopyObjectRequest::specialHeaders() const +{ + auto headers = metaData_.toHeaderCollection(); + + if (headers.find(Http::CONTENT_TYPE) == headers.end()) { + headers[Http::CONTENT_TYPE] = LookupMimeType(Key()); + } + + return headers; +} + diff --git a/sdk/src/model/CreateSymlinkRequest.cc b/sdk/src/model/CreateSymlinkRequest.cc index b990e31..fafccc5 100644 --- a/sdk/src/model/CreateSymlinkRequest.cc +++ b/sdk/src/model/CreateSymlinkRequest.cc @@ -1,53 +1,58 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "../utils/Utils.h" - -using namespace AlibabaCloud::OSS; - -CreateSymlinkRequest::CreateSymlinkRequest(const std::string &bucket, const std::string &key): - OssObjectRequest(bucket, key) -{ -} - -CreateSymlinkRequest::CreateSymlinkRequest(const std::string &bucket, const std::string &key, - const ObjectMetaData &metaData): - OssObjectRequest(bucket, key), - metaData_(metaData) -{ -} - -void CreateSymlinkRequest::SetSymlinkTarget(const std::string& value) -{ - metaData_.addHeader("x-oss-symlink-target", value); -} - -HeaderCollection CreateSymlinkRequest::specialHeaders() const -{ - return metaData_.toHeaderCollection(); -} - - -ParameterCollection CreateSymlinkRequest::specialParameters() const -{ - ParameterCollection paramters; - paramters["symlink"] = ""; - return paramters; -} - - +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "../utils/Utils.h" + +using namespace AlibabaCloud::OSS; + +CreateSymlinkRequest::CreateSymlinkRequest(const std::string &bucket, const std::string &key): + OssObjectRequest(bucket, key) +{ +} + +CreateSymlinkRequest::CreateSymlinkRequest(const std::string &bucket, const std::string &key, + const ObjectMetaData &metaData): + OssObjectRequest(bucket, key), + metaData_(metaData) +{ +} + +void CreateSymlinkRequest::SetSymlinkTarget(const std::string& value) +{ + metaData_.addHeader("x-oss-symlink-target", value); +} + +void CreateSymlinkRequest::setTagging(const std::string& value) +{ + metaData_.addHeader("x-oss-tagging", value); +} + +HeaderCollection CreateSymlinkRequest::specialHeaders() const +{ + return metaData_.toHeaderCollection(); +} + + +ParameterCollection CreateSymlinkRequest::specialParameters() const +{ + ParameterCollection paramters; + paramters["symlink"] = ""; + return paramters; +} + + diff --git a/sdk/src/model/DeleteObjectTaggingRequest.cc b/sdk/src/model/DeleteObjectTaggingRequest.cc new file mode 100644 index 0000000..75de553 --- /dev/null +++ b/sdk/src/model/DeleteObjectTaggingRequest.cc @@ -0,0 +1,32 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +using namespace AlibabaCloud::OSS; + +DeleteObjectTaggingRequest::DeleteObjectTaggingRequest(const std::string& bucket, const std::string& key): + OssObjectRequest(bucket, key) +{ +} + +ParameterCollection DeleteObjectTaggingRequest::specialParameters() const +{ + ParameterCollection parameters; + parameters["tagging"] = ""; + return parameters; +} + diff --git a/sdk/src/model/GetBucketLifecycleResult.cc b/sdk/src/model/GetBucketLifecycleResult.cc index 96e3cd1..1e46fea 100644 --- a/sdk/src/model/GetBucketLifecycleResult.cc +++ b/sdk/src/model/GetBucketLifecycleResult.cc @@ -1,121 +1,139 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "../utils/Utils.h" -using namespace AlibabaCloud::OSS; -using namespace tinyxml2; - - -GetBucketLifecycleResult::GetBucketLifecycleResult() : - OssResult() -{ -} - -GetBucketLifecycleResult::GetBucketLifecycleResult(const std::string& result): - GetBucketLifecycleResult() -{ - *this = result; -} - -GetBucketLifecycleResult::GetBucketLifecycleResult(const std::shared_ptr& result): - GetBucketLifecycleResult() -{ - std::istreambuf_iterator isb(*result.get()), end; - std::string str(isb, end); - *this = str; -} - -GetBucketLifecycleResult& GetBucketLifecycleResult::operator =(const std::string& result) -{ - XMLDocument doc; - XMLError xml_err; - if ((xml_err = doc.Parse(result.c_str(), result.size())) == XML_SUCCESS) { - XMLElement* root =doc.RootElement(); - if (root && !std::strncmp("LifecycleConfiguration", root->Name(), 22)) { - XMLElement *rule_node = root->FirstChildElement("Rule"); - for (; rule_node; rule_node = rule_node->NextSiblingElement("Rule")) { - LifecycleRule rule; - XMLElement *node; - node = rule_node->FirstChildElement("ID"); - if (node && node->GetText()) rule.setID(node->GetText()); - - node = rule_node->FirstChildElement("Prefix"); - if (node && node->GetText()) rule.setPrefix(node->GetText()); - - node = rule_node->FirstChildElement("Status"); - if (node && node->GetText()) rule.setStatus(ToRuleStatusType(node->GetText())); - - node = rule_node->FirstChildElement("Expiration"); - if (node) { - XMLElement *subNode; - //Days - subNode = node->FirstChildElement("Days"); - if (subNode && subNode->GetText()) { - rule.Expiration().setDays(std::stoi(subNode->GetText(), nullptr, 10)); - } - //CreatedBeforeDate - subNode = node->FirstChildElement("CreatedBeforeDate"); - if (subNode && subNode->GetText()) { - rule.Expiration().setCreatedBeforeDate(subNode->GetText()); - } - } - - node = rule_node->FirstChildElement("Transition"); - for (; node; node = node->NextSiblingElement("Transition")) { - LifeCycleTransition transiton; - XMLElement *subNode; - //Days - subNode = node->FirstChildElement("Days"); - if (subNode && subNode->GetText()) { - transiton.Expiration().setDays(std::stoi(subNode->GetText(), nullptr, 10)); - } - //CreatedBeforeDate - subNode = node->FirstChildElement("CreatedBeforeDate"); - if (subNode && subNode->GetText()) { - transiton.Expiration().setCreatedBeforeDate(subNode->GetText()); - } - //StorageClass - subNode = node->FirstChildElement("StorageClass"); - if (subNode && subNode->GetText()) { - transiton.setStorageClass(ToStorageClassType(subNode->GetText())); - } - rule.addTransition(transiton); - } - - node = rule_node->FirstChildElement("AbortMultipartUpload"); - if (node) { - XMLElement *subNode; - //Days - subNode = node->FirstChildElement("Days"); - if (subNode && subNode->GetText()) { - rule.AbortMultipartUpload().setDays(std::stoi(subNode->GetText(), nullptr, 10)); - } - //CreatedBeforeDate - subNode = node->FirstChildElement("CreatedBeforeDate"); - if (subNode && subNode->GetText()) { - rule.AbortMultipartUpload().setCreatedBeforeDate(subNode->GetText()); - } - } - lifecycleRuleList_.emplace_back(std::move(rule)); - } - parseDone_ = true; - } - } - return *this; -} +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include "../utils/Utils.h" +using namespace AlibabaCloud::OSS; +using namespace tinyxml2; + + +GetBucketLifecycleResult::GetBucketLifecycleResult() : + OssResult() +{ +} + +GetBucketLifecycleResult::GetBucketLifecycleResult(const std::string& result): + GetBucketLifecycleResult() +{ + *this = result; +} + +GetBucketLifecycleResult::GetBucketLifecycleResult(const std::shared_ptr& result): + GetBucketLifecycleResult() +{ + std::istreambuf_iterator isb(*result.get()), end; + std::string str(isb, end); + *this = str; +} + +GetBucketLifecycleResult& GetBucketLifecycleResult::operator =(const std::string& result) +{ + XMLDocument doc; + XMLError xml_err; + if ((xml_err = doc.Parse(result.c_str(), result.size())) == XML_SUCCESS) { + XMLElement* root =doc.RootElement(); + if (root && !std::strncmp("LifecycleConfiguration", root->Name(), 22)) { + XMLElement *rule_node = root->FirstChildElement("Rule"); + for (; rule_node; rule_node = rule_node->NextSiblingElement("Rule")) { + LifecycleRule rule; + XMLElement *node; + node = rule_node->FirstChildElement("ID"); + if (node && node->GetText()) rule.setID(node->GetText()); + + node = rule_node->FirstChildElement("Prefix"); + if (node && node->GetText()) rule.setPrefix(node->GetText()); + + node = rule_node->FirstChildElement("Status"); + if (node && node->GetText()) rule.setStatus(ToRuleStatusType(node->GetText())); + + node = rule_node->FirstChildElement("Expiration"); + if (node) { + XMLElement *subNode; + //Days + subNode = node->FirstChildElement("Days"); + if (subNode && subNode->GetText()) { + rule.Expiration().setDays(std::stoi(subNode->GetText(), nullptr, 10)); + } + //CreatedBeforeDate + subNode = node->FirstChildElement("CreatedBeforeDate"); + if (subNode && subNode->GetText()) { + rule.Expiration().setCreatedBeforeDate(subNode->GetText()); + } + } + + node = rule_node->FirstChildElement("Transition"); + for (; node; node = node->NextSiblingElement("Transition")) { + LifeCycleTransition transiton; + XMLElement *subNode; + //Days + subNode = node->FirstChildElement("Days"); + if (subNode && subNode->GetText()) { + transiton.Expiration().setDays(std::stoi(subNode->GetText(), nullptr, 10)); + } + //CreatedBeforeDate + subNode = node->FirstChildElement("CreatedBeforeDate"); + if (subNode && subNode->GetText()) { + transiton.Expiration().setCreatedBeforeDate(subNode->GetText()); + } + //StorageClass + subNode = node->FirstChildElement("StorageClass"); + if (subNode && subNode->GetText()) { + transiton.setStorageClass(ToStorageClassType(subNode->GetText())); + } + rule.addTransition(transiton); + } + + node = rule_node->FirstChildElement("AbortMultipartUpload"); + if (node) { + XMLElement *subNode; + //Days + subNode = node->FirstChildElement("Days"); + if (subNode && subNode->GetText()) { + rule.AbortMultipartUpload().setDays(std::stoi(subNode->GetText(), nullptr, 10)); + } + //CreatedBeforeDate + subNode = node->FirstChildElement("CreatedBeforeDate"); + if (subNode && subNode->GetText()) { + rule.AbortMultipartUpload().setCreatedBeforeDate(subNode->GetText()); + } + } + + node = rule_node->FirstChildElement("Tag"); + for (; node; node = node->NextSiblingElement("Tag")) { + Tag tag; + XMLElement *subNode; + //Key + subNode = node->FirstChildElement("Key"); + if (subNode && subNode->GetText()) { + tag.setKey(subNode->GetText()); + } + //Value + subNode = node->FirstChildElement("Value"); + if (subNode && subNode->GetText()) { + tag.setValue(subNode->GetText()); + } + rule.addTag(tag); + } + + lifecycleRuleList_.emplace_back(std::move(rule)); + } + parseDone_ = true; + } + } + return *this; +} diff --git a/sdk/src/model/GetObjectTaggingRequest.cc b/sdk/src/model/GetObjectTaggingRequest.cc new file mode 100644 index 0000000..dcc2271 --- /dev/null +++ b/sdk/src/model/GetObjectTaggingRequest.cc @@ -0,0 +1,32 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +using namespace AlibabaCloud::OSS; + +GetObjectTaggingRequest::GetObjectTaggingRequest(const std::string &bucket, const std::string &key) + :OssObjectRequest(bucket, key) +{ +} + +ParameterCollection GetObjectTaggingRequest::specialParameters() const +{ + ParameterCollection paramters; + paramters["tagging"] = ""; + return paramters; +} + diff --git a/sdk/src/model/GetObjectTaggingResult.cc b/sdk/src/model/GetObjectTaggingResult.cc new file mode 100644 index 0000000..b5677d9 --- /dev/null +++ b/sdk/src/model/GetObjectTaggingResult.cc @@ -0,0 +1,75 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include "../utils/Utils.h" +using namespace AlibabaCloud::OSS; +using namespace tinyxml2; + +GetObjectTaggingResult::GetObjectTaggingResult() : + OssResult() +{ +} + +GetObjectTaggingResult::GetObjectTaggingResult(const std::string& result): + GetObjectTaggingResult() +{ + *this = result; +} + +GetObjectTaggingResult::GetObjectTaggingResult(const std::shared_ptr& result): + GetObjectTaggingResult() +{ + std::istreambuf_iterator isb(*result.get()), end; + std::string str(isb, end); + *this = str; +} + +GetObjectTaggingResult& GetObjectTaggingResult::operator =(const std::string& result) +{ + XMLDocument doc; + XMLError xml_err; + if ((xml_err = doc.Parse(result.c_str(), result.size())) == XML_SUCCESS) { + XMLElement* root =doc.RootElement(); + if (root && !std::strncmp("Tagging", root->Name(), 7)) { + XMLElement* tagSet_node = root->FirstChildElement("TagSet"); + if (tagSet_node) { + XMLElement *tag_node = tagSet_node->FirstChildElement("Tag"); + for (; tag_node; tag_node = tag_node->NextSiblingElement("Tag")) { + XMLElement *subNode; + Tag tag; + //Key + subNode = tag_node->FirstChildElement("Key"); + if (subNode && subNode->GetText()) { + tag.setKey(subNode->GetText()); + } + //Value + subNode = tag_node->FirstChildElement("Value"); + if (subNode && subNode->GetText()) { + tag.setValue(subNode->GetText()); + } + tagging_.addTag(tag); + } + } + //TODO check the result and the parse flag; + parseDone_ = true; + } + } + return *this; +} + diff --git a/sdk/src/model/InitiateMultipartUploadRequest.cc b/sdk/src/model/InitiateMultipartUploadRequest.cc index f1a06e9..850e453 100644 --- a/sdk/src/model/InitiateMultipartUploadRequest.cc +++ b/sdk/src/model/InitiateMultipartUploadRequest.cc @@ -1,87 +1,92 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "../utils/Utils.h" -#include -using namespace AlibabaCloud::OSS; - -InitiateMultipartUploadRequest::InitiateMultipartUploadRequest(const std::string &bucket, const std::string &key) : - InitiateMultipartUploadRequest(bucket, key, ObjectMetaData()) -{ -} - -InitiateMultipartUploadRequest::InitiateMultipartUploadRequest(const std::string &bucket, const std::string &key, - const ObjectMetaData &metaData) : - OssObjectRequest(bucket, key), - metaData_(metaData), - encodingTypeIsSet_(false) -{ -} - -void InitiateMultipartUploadRequest::setEncodingType(const std::string &encodingType) -{ - encodingType_ = encodingType; - encodingTypeIsSet_ = true; -} - -void InitiateMultipartUploadRequest::setCacheControl(const std::string &value) -{ - metaData_.addHeader(Http::CACHE_CONTROL, value); -} - -void InitiateMultipartUploadRequest::setContentDisposition(const std::string &value) -{ - metaData_.addHeader(Http::CONTENT_DISPOSITION, value); -} - -void InitiateMultipartUploadRequest::setContentEncoding(const std::string &value) -{ - metaData_.addHeader(Http::CONTENT_ENCODING, value); -} - -void InitiateMultipartUploadRequest::setExpires(const std::string &value) -{ - metaData_.addHeader(Http::EXPIRES, value); -} - -ObjectMetaData &InitiateMultipartUploadRequest::MetaData() -{ - return metaData_; -} - -HeaderCollection InitiateMultipartUploadRequest::specialHeaders() const -{ - auto headers = metaData_.toHeaderCollection(); - if (headers.find(Http::CONTENT_TYPE) == headers.end()) { - headers[Http::CONTENT_TYPE] = LookupMimeType(Key()); - } - - return headers; -} - -ParameterCollection InitiateMultipartUploadRequest::specialParameters() const -{ - ParameterCollection parameters; - parameters["uploads"] = ""; - if (encodingTypeIsSet_) - { - parameters["encoding-type"] = encodingType_; - } - return parameters; -} +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include "../utils/Utils.h" +#include +using namespace AlibabaCloud::OSS; + +InitiateMultipartUploadRequest::InitiateMultipartUploadRequest(const std::string &bucket, const std::string &key) : + InitiateMultipartUploadRequest(bucket, key, ObjectMetaData()) +{ +} + +InitiateMultipartUploadRequest::InitiateMultipartUploadRequest(const std::string &bucket, const std::string &key, + const ObjectMetaData &metaData) : + OssObjectRequest(bucket, key), + metaData_(metaData), + encodingTypeIsSet_(false) +{ +} + +void InitiateMultipartUploadRequest::setEncodingType(const std::string &encodingType) +{ + encodingType_ = encodingType; + encodingTypeIsSet_ = true; +} + +void InitiateMultipartUploadRequest::setCacheControl(const std::string &value) +{ + metaData_.addHeader(Http::CACHE_CONTROL, value); +} + +void InitiateMultipartUploadRequest::setContentDisposition(const std::string &value) +{ + metaData_.addHeader(Http::CONTENT_DISPOSITION, value); +} + +void InitiateMultipartUploadRequest::setContentEncoding(const std::string &value) +{ + metaData_.addHeader(Http::CONTENT_ENCODING, value); +} + +void InitiateMultipartUploadRequest::setExpires(const std::string &value) +{ + metaData_.addHeader(Http::EXPIRES, value); +} + +void InitiateMultipartUploadRequest::setTagging(const std::string& value) +{ + metaData_.addHeader("x-oss-tagging", value); +} + +ObjectMetaData &InitiateMultipartUploadRequest::MetaData() +{ + return metaData_; +} + +HeaderCollection InitiateMultipartUploadRequest::specialHeaders() const +{ + auto headers = metaData_.toHeaderCollection(); + if (headers.find(Http::CONTENT_TYPE) == headers.end()) { + headers[Http::CONTENT_TYPE] = LookupMimeType(Key()); + } + + return headers; +} + +ParameterCollection InitiateMultipartUploadRequest::specialParameters() const +{ + ParameterCollection parameters; + parameters["uploads"] = ""; + if (encodingTypeIsSet_) + { + parameters["encoding-type"] = encodingType_; + } + return parameters; +} diff --git a/sdk/src/model/LifecycleRule.cc b/sdk/src/model/LifecycleRule.cc index 12f3439..44a231d 100644 --- a/sdk/src/model/LifecycleRule.cc +++ b/sdk/src/model/LifecycleRule.cc @@ -1,120 +1,137 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -using namespace AlibabaCloud::OSS; - -LifeCycleExpiration::LifeCycleExpiration() : - days_(0), - createdBeforeDate_() -{ -} - -LifeCycleExpiration::LifeCycleExpiration(uint32_t days) : - days_(days), - createdBeforeDate_() -{ -} - -LifeCycleExpiration::LifeCycleExpiration(const std::string &createdBeforeDate) : - days_(0), - createdBeforeDate_(createdBeforeDate) -{ -} - -void LifeCycleExpiration::setDays(uint32_t days) -{ - days_ = days; - createdBeforeDate_.clear(); -} - -void LifeCycleExpiration::setCreatedBeforeDate(const std::string &date) -{ - createdBeforeDate_ = date; - days_ = 0; -} - -LifeCycleTransition::LifeCycleTransition(const LifeCycleExpiration& expiration, AlibabaCloud::OSS::StorageClass storageClass) : - expiration_(expiration), - storageClass_(storageClass) -{ -} - -void LifeCycleTransition::setExpiration(const LifeCycleExpiration &expiration) -{ - expiration_ = expiration; -} - -void LifeCycleTransition::setStorageClass(AlibabaCloud::OSS::StorageClass storageClass) -{ - storageClass_ = storageClass; -} - -bool LifecycleRule::hasExpiration() const -{ - return (expiration_.Days() > 0 || !expiration_.CreatedBeforeDate().empty()); -} - -bool LifecycleRule::hasTransitionList() const -{ - return !transitionList_.empty(); -} - -bool LifecycleRule::hasAbortMultipartUpload() const -{ - return (abortMultipartUpload_.Days() > 0 || !abortMultipartUpload_.CreatedBeforeDate().empty()); -} - -bool LifecycleRule::operator==(const LifecycleRule& right) const -{ - if (id_ != right.id_ || - prefix_ != right.prefix_ || - status_ != right.status_) { - return false; - } - - if (expiration_.Days() != right.expiration_.Days() || - expiration_.CreatedBeforeDate() != right.expiration_.CreatedBeforeDate()) { - return false; - } - - if (abortMultipartUpload_.Days() != right.abortMultipartUpload_.Days() || - abortMultipartUpload_.CreatedBeforeDate() != right.abortMultipartUpload_.CreatedBeforeDate()) { - return false; - } - - if (transitionList_.size() != right.transitionList_.size()) { - return false; - } - - auto first = transitionList_.begin(); - auto Rightfirst = right.transitionList_.begin(); - - for (; first != transitionList_.end(); ) { - - if (first->Expiration().Days() != Rightfirst->Expiration().Days() || - first->Expiration().CreatedBeforeDate() != Rightfirst->Expiration().CreatedBeforeDate() || - first->StorageClass() != Rightfirst->StorageClass()) { - return false; - } - first++; - Rightfirst++; - } - - return true; -} +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + +using namespace AlibabaCloud::OSS; + +LifeCycleExpiration::LifeCycleExpiration() : + days_(0), + createdBeforeDate_() +{ +} + +LifeCycleExpiration::LifeCycleExpiration(uint32_t days) : + days_(days), + createdBeforeDate_() +{ +} + +LifeCycleExpiration::LifeCycleExpiration(const std::string &createdBeforeDate) : + days_(0), + createdBeforeDate_(createdBeforeDate) +{ +} + +void LifeCycleExpiration::setDays(uint32_t days) +{ + days_ = days; + createdBeforeDate_.clear(); +} + +void LifeCycleExpiration::setCreatedBeforeDate(const std::string &date) +{ + createdBeforeDate_ = date; + days_ = 0; +} + +LifeCycleTransition::LifeCycleTransition(const LifeCycleExpiration& expiration, AlibabaCloud::OSS::StorageClass storageClass) : + expiration_(expiration), + storageClass_(storageClass) +{ +} + +void LifeCycleTransition::setExpiration(const LifeCycleExpiration &expiration) +{ + expiration_ = expiration; +} + +void LifeCycleTransition::setStorageClass(AlibabaCloud::OSS::StorageClass storageClass) +{ + storageClass_ = storageClass; +} + +bool LifecycleRule::hasExpiration() const +{ + return (expiration_.Days() > 0 || !expiration_.CreatedBeforeDate().empty()); +} + +bool LifecycleRule::hasTransitionList() const +{ + return !transitionList_.empty(); +} + +bool LifecycleRule::hasAbortMultipartUpload() const +{ + return (abortMultipartUpload_.Days() > 0 || !abortMultipartUpload_.CreatedBeforeDate().empty()); +} + +bool LifecycleRule::operator==(const LifecycleRule& right) const +{ + if (id_ != right.id_ || + prefix_ != right.prefix_ || + status_ != right.status_) { + return false; + } + + if (expiration_.Days() != right.expiration_.Days() || + expiration_.CreatedBeforeDate() != right.expiration_.CreatedBeforeDate()) { + return false; + } + + if (abortMultipartUpload_.Days() != right.abortMultipartUpload_.Days() || + abortMultipartUpload_.CreatedBeforeDate() != right.abortMultipartUpload_.CreatedBeforeDate()) { + return false; + } + + if (transitionList_.size() != right.transitionList_.size()) { + return false; + } + + auto first = transitionList_.begin(); + auto Rightfirst = right.transitionList_.begin(); + + for (; first != transitionList_.end(); ) { + + if (first->Expiration().Days() != Rightfirst->Expiration().Days() || + first->Expiration().CreatedBeforeDate() != Rightfirst->Expiration().CreatedBeforeDate() || + first->StorageClass() != Rightfirst->StorageClass()) { + return false; + } + first++; + Rightfirst++; + } + + if (tagSet_.size() != right.tagSet_.size()) { + return false; + } + + auto firstTag = tagSet_.begin(); + auto RightfirstTag = right.tagSet_.begin(); + + for (; firstTag != tagSet_.end(); ) { + + if (firstTag->Key() != RightfirstTag->Key() || + firstTag->Value()!= RightfirstTag->Value()) { + return false; + } + firstTag++; + RightfirstTag++; + } + + return true; +} diff --git a/sdk/src/model/ModelError.cc b/sdk/src/model/ModelError.cc index fb1e76a..693319e 100644 --- a/sdk/src/model/ModelError.cc +++ b/sdk/src/model/ModelError.cc @@ -101,7 +101,11 @@ static const char * GetArgErrorMsg(const int code) "The request InputFormat/OutputFormat is invalid. It cannot set InputFormat or OutputFormat as nullptr.", "The request InputFormat/OutputFormat is invalid. It cannot set InputFormat and OutputFormat in difficent type.", /*CreateSelectObject -64*/ - "The request InputFormat is invalid. It cannot set InputFormat as nullptr." + "The request InputFormat is invalid. It cannot set InputFormat as nullptr.", + /*Tagging -65*/ + "Object tags cannot be greater than 10.", + "Object Tag key is invalid, it's length should be [1, 128].", + "Object Tag value is invalid, it's length should be less than 256." }; int index = code - ARG_ERROR_START; diff --git a/sdk/src/model/ModelError.h b/sdk/src/model/ModelError.h index a11ceec..e20aa64 100644 --- a/sdk/src/model/ModelError.h +++ b/sdk/src/model/ModelError.h @@ -115,6 +115,11 @@ namespace OSS /*CreateSelectObjectMeta*/ const int ARG_ERROR_CREATE_SELECT_OBJECT_META_NULL_POINT = ARG_ERROR_BASE + 64; + + /*Tagging*/ + const int ARG_ERROR_TAGGING_TAGS_LIMIT = ARG_ERROR_BASE + 65; + const int ARG_ERROR_TAGGING_TAG_KEY_LIMIT = ARG_ERROR_BASE + 66; + const int ARG_ERROR_TAGGING_TAG_VALUE_LIMIT = ARG_ERROR_BASE + 67; } } diff --git a/sdk/src/model/PutObjectRequest.cc b/sdk/src/model/PutObjectRequest.cc index bc887ad..982d6dc 100644 --- a/sdk/src/model/PutObjectRequest.cc +++ b/sdk/src/model/PutObjectRequest.cc @@ -1,123 +1,128 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "../utils/Utils.h" -#include "ModelError.h" -#include -using namespace AlibabaCloud::OSS; - -PutObjectRequest::PutObjectRequest(const std::string &bucket, const std::string &key, - const std::shared_ptr &content) : - OssObjectRequest(bucket, key), - content_(content) -{ - setFlags(Flags() | REQUEST_FLAG_CHECK_CRC64); -} - -PutObjectRequest::PutObjectRequest(const std::string &bucket, const std::string &key, - const std::shared_ptr &content, const ObjectMetaData &metaData) : - OssObjectRequest(bucket, key), - content_(content), - metaData_(metaData) -{ - setFlags(Flags() | REQUEST_FLAG_CHECK_CRC64); -} - -void PutObjectRequest::setCacheControl(const std::string &value) -{ - metaData_.addHeader(Http::CACHE_CONTROL, value); -} - -void PutObjectRequest::setContentDisposition(const std::string &value) -{ - metaData_.addHeader(Http::CONTENT_DISPOSITION, value); -} - -void PutObjectRequest::setContentEncoding(const std::string &value) -{ - metaData_.addHeader(Http::CONTENT_ENCODING, value); -} - -void PutObjectRequest::setContentMd5(const std::string &value) -{ - metaData_.addHeader(Http::CONTENT_MD5, value); -} - -void PutObjectRequest::setExpires(const std::string &value) -{ - metaData_.addHeader(Http::EXPIRES, value); -} - -void PutObjectRequest::setCallback(const std::string& callback, const std::string& callbackVar) -{ - metaData_.removeHeader("x-oss-callback"); - metaData_.removeHeader("x-oss-callback-var"); - - if (!callback.empty()) { - metaData_.addHeader("x-oss-callback", callback); - } - - if (!callbackVar.empty()) { - metaData_.addHeader("x-oss-callback-var", callbackVar); - } -} - -ObjectMetaData &PutObjectRequest::MetaData() -{ - return metaData_; -} - -std::shared_ptr PutObjectRequest::Body() const -{ - return content_; -} - -HeaderCollection PutObjectRequest::specialHeaders() const -{ - auto headers = metaData_.toHeaderCollection(); - - if (headers.find(Http::CONTENT_TYPE) == headers.end()) { - headers[Http::CONTENT_TYPE] = LookupMimeType(Key()); - } - - return headers; -} - -int PutObjectRequest::validate() const -{ - int ret = OssObjectRequest::validate(); - if (ret != 0) { - return ret; - } - - if (content_ == nullptr) { - return ARG_ERROR_REQUEST_BODY_NULLPTR; - } - - if (content_->bad()) { - return ARG_ERROR_REQUEST_BODY_BAD_STATE; - } - - if (content_->fail()) { - return ARG_ERROR_REQUEST_BODY_FAIL_STATE; - } - - return 0; -} - +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include "../utils/Utils.h" +#include "ModelError.h" +#include +using namespace AlibabaCloud::OSS; + +PutObjectRequest::PutObjectRequest(const std::string &bucket, const std::string &key, + const std::shared_ptr &content) : + OssObjectRequest(bucket, key), + content_(content) +{ + setFlags(Flags() | REQUEST_FLAG_CHECK_CRC64); +} + +PutObjectRequest::PutObjectRequest(const std::string &bucket, const std::string &key, + const std::shared_ptr &content, const ObjectMetaData &metaData) : + OssObjectRequest(bucket, key), + content_(content), + metaData_(metaData) +{ + setFlags(Flags() | REQUEST_FLAG_CHECK_CRC64); +} + +void PutObjectRequest::setCacheControl(const std::string &value) +{ + metaData_.addHeader(Http::CACHE_CONTROL, value); +} + +void PutObjectRequest::setContentDisposition(const std::string &value) +{ + metaData_.addHeader(Http::CONTENT_DISPOSITION, value); +} + +void PutObjectRequest::setContentEncoding(const std::string &value) +{ + metaData_.addHeader(Http::CONTENT_ENCODING, value); +} + +void PutObjectRequest::setContentMd5(const std::string &value) +{ + metaData_.addHeader(Http::CONTENT_MD5, value); +} + +void PutObjectRequest::setExpires(const std::string &value) +{ + metaData_.addHeader(Http::EXPIRES, value); +} + +void PutObjectRequest::setCallback(const std::string& callback, const std::string& callbackVar) +{ + metaData_.removeHeader("x-oss-callback"); + metaData_.removeHeader("x-oss-callback-var"); + + if (!callback.empty()) { + metaData_.addHeader("x-oss-callback", callback); + } + + if (!callbackVar.empty()) { + metaData_.addHeader("x-oss-callback-var", callbackVar); + } +} + +void PutObjectRequest::setTagging(const std::string& value) +{ + metaData_.addHeader("x-oss-tagging", value); +} + +ObjectMetaData &PutObjectRequest::MetaData() +{ + return metaData_; +} + +std::shared_ptr PutObjectRequest::Body() const +{ + return content_; +} + +HeaderCollection PutObjectRequest::specialHeaders() const +{ + auto headers = metaData_.toHeaderCollection(); + + if (headers.find(Http::CONTENT_TYPE) == headers.end()) { + headers[Http::CONTENT_TYPE] = LookupMimeType(Key()); + } + + return headers; +} + +int PutObjectRequest::validate() const +{ + int ret = OssObjectRequest::validate(); + if (ret != 0) { + return ret; + } + + if (content_ == nullptr) { + return ARG_ERROR_REQUEST_BODY_NULLPTR; + } + + if (content_->bad()) { + return ARG_ERROR_REQUEST_BODY_BAD_STATE; + } + + if (content_->fail()) { + return ARG_ERROR_REQUEST_BODY_FAIL_STATE; + } + + return 0; +} + diff --git a/sdk/src/model/SetBucketLifecycleRequest.cc b/sdk/src/model/SetBucketLifecycleRequest.cc index d907f3a..e8448e7 100644 --- a/sdk/src/model/SetBucketLifecycleRequest.cc +++ b/sdk/src/model/SetBucketLifecycleRequest.cc @@ -1,112 +1,116 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include <../utils/Utils.h> -#include "ModelError.h" - -using namespace AlibabaCloud::OSS; - -std::string SetBucketLifecycleRequest::payload() const -{ - std::stringstream ss; - ss << "" << std::endl; - ss << "" << std::endl; - for (auto const &rule : lifecycleRules_) - { - ss << " " << std::endl; - ss << " " << rule.ID() << "" << std::endl; - ss << " " << rule.Prefix() << "" << std::endl; - ss << " " << ToRuleStatusName(rule.Status()) << "" << std::endl; - if (rule.hasExpiration()) - { - ss << " " << std::endl; - if (rule.Expiration().Days() > 0) { - ss << " " << std::to_string(rule.Expiration().Days()) << "" << std::endl; - } - else { - ss << " " << rule.Expiration().CreatedBeforeDate() << "" << std::endl; - } - ss << " " << std::endl; - } - for (auto const & transition: rule.TransitionList()) - { - ss << " " << std::endl; - if (transition.Expiration().Days() > 0) { - ss << " " << std::to_string(transition.Expiration().Days()) << "" << std::endl; - } - else { - ss << " " << transition.Expiration().CreatedBeforeDate() << "" << std::endl; - } - ss << " " << ToStorageClassName(transition.StorageClass()) << "" << std::endl; - ss << " " << std::endl; - } - if (rule.hasAbortMultipartUpload()) - { - ss << " " << std::endl; - if (rule.AbortMultipartUpload().Days() > 0) { - ss << " " << std::to_string(rule.AbortMultipartUpload().Days()) << "" << std::endl; - } - else { - ss << " " << rule.AbortMultipartUpload().CreatedBeforeDate() << "" << std::endl; - } - ss << " " << std::endl; - } - ss << " " << std::endl; - } - ss << "" << std::endl; - return ss.str(); -} - -ParameterCollection SetBucketLifecycleRequest::specialParameters() const -{ - ParameterCollection parameters; - parameters["lifecycle"] = ""; - return parameters; -} - -int SetBucketLifecycleRequest::validate() const -{ - int ret; - if ((ret = OssBucketRequest::validate()) != 0) { - return ret; - } - - if (lifecycleRules_.size() > LifecycleRuleLimit) { - return ARG_ERROR_LIFECYCLE_RULE_LIMIT; - } - - if (lifecycleRules_.empty()) { - return ARG_ERROR_LIFECYCLE_RULE_EMPTY; - } - - for (auto const &rule : lifecycleRules_) { - //no config rule - if (!rule.hasAbortMultipartUpload() && - !rule.hasExpiration() && - !rule.hasTransitionList()) { - return ARG_ERROR_LIFECYCLE_RULE_CONFIG_EMPTY; - } - - if (rule.Prefix().empty() && lifecycleRules_.size() > 1) { - return ARG_ERROR_LIFECYCLE_RULE_ONLY_ONE_FOR_BUCKET; - } - } - - return 0; -} +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include <../utils/Utils.h> +#include "ModelError.h" + +using namespace AlibabaCloud::OSS; + +std::string SetBucketLifecycleRequest::payload() const +{ + std::stringstream ss; + ss << "" << std::endl; + ss << "" << std::endl; + for (auto const &rule : lifecycleRules_) + { + ss << " " << std::endl; + ss << " " << rule.ID() << "" << std::endl; + ss << " " << rule.Prefix() << "" << std::endl; + for (const auto& tag : rule.Tags()) + { + ss << " " << tag.Key() << "" << tag.Value() << "" << std::endl; + } + ss << " " << ToRuleStatusName(rule.Status()) << "" << std::endl; + if (rule.hasExpiration()) + { + ss << " " << std::endl; + if (rule.Expiration().Days() > 0) { + ss << " " << std::to_string(rule.Expiration().Days()) << "" << std::endl; + } + else { + ss << " " << rule.Expiration().CreatedBeforeDate() << "" << std::endl; + } + ss << " " << std::endl; + } + for (auto const & transition: rule.TransitionList()) + { + ss << " " << std::endl; + if (transition.Expiration().Days() > 0) { + ss << " " << std::to_string(transition.Expiration().Days()) << "" << std::endl; + } + else { + ss << " " << transition.Expiration().CreatedBeforeDate() << "" << std::endl; + } + ss << " " << ToStorageClassName(transition.StorageClass()) << "" << std::endl; + ss << " " << std::endl; + } + if (rule.hasAbortMultipartUpload()) + { + ss << " " << std::endl; + if (rule.AbortMultipartUpload().Days() > 0) { + ss << " " << std::to_string(rule.AbortMultipartUpload().Days()) << "" << std::endl; + } + else { + ss << " " << rule.AbortMultipartUpload().CreatedBeforeDate() << "" << std::endl; + } + ss << " " << std::endl; + } + ss << " " << std::endl; + } + ss << "" << std::endl; + return ss.str(); +} + +ParameterCollection SetBucketLifecycleRequest::specialParameters() const +{ + ParameterCollection parameters; + parameters["lifecycle"] = ""; + return parameters; +} + +int SetBucketLifecycleRequest::validate() const +{ + int ret; + if ((ret = OssBucketRequest::validate()) != 0) { + return ret; + } + + if (lifecycleRules_.size() > LifecycleRuleLimit) { + return ARG_ERROR_LIFECYCLE_RULE_LIMIT; + } + + if (lifecycleRules_.empty()) { + return ARG_ERROR_LIFECYCLE_RULE_EMPTY; + } + + for (auto const &rule : lifecycleRules_) { + //no config rule + if (!rule.hasAbortMultipartUpload() && + !rule.hasExpiration() && + !rule.hasTransitionList()) { + return ARG_ERROR_LIFECYCLE_RULE_CONFIG_EMPTY; + } + + if (rule.Prefix().empty() && lifecycleRules_.size() > 1) { + return ARG_ERROR_LIFECYCLE_RULE_ONLY_ONE_FOR_BUCKET; + } + } + + return 0; +} diff --git a/sdk/src/model/SetObjectTaggingRequest.cc b/sdk/src/model/SetObjectTaggingRequest.cc new file mode 100644 index 0000000..989ccfa --- /dev/null +++ b/sdk/src/model/SetObjectTaggingRequest.cc @@ -0,0 +1,85 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include "../utils/Utils.h" +#include "ModelError.h" +#include +using namespace AlibabaCloud::OSS; + +SetObjectTaggingRequest::SetObjectTaggingRequest(const std::string& bucket, const std::string& key): + OssObjectRequest(bucket, key) +{ +} + +SetObjectTaggingRequest::SetObjectTaggingRequest(const std::string& bucket, const std::string& key, + const Tagging& tagging): + OssObjectRequest(bucket, key), + tagging_(tagging) +{ +} + +void SetObjectTaggingRequest::setTagging(const Tagging& tagging) +{ + tagging_ = tagging; +} + + +std::string SetObjectTaggingRequest::payload() const +{ + std::stringstream ss; + ss << "" << std::endl; + ss << "" << std::endl; + ss << " " << std::endl; + for (const auto& tag : tagging_.Tags()) { + ss << " "<< tag.Key() <<"" << tag.Value() << "" << std::endl; + } + ss << " " << std::endl; + ss << "" << std::endl; + return ss.str(); +} + +ParameterCollection SetObjectTaggingRequest::specialParameters() const +{ + ParameterCollection parameters; + parameters["tagging"] = ""; + return parameters; +} + +int SetObjectTaggingRequest::validate() const +{ + int ret; + if ((ret = OssObjectRequest::validate()) != 0) { + return ret; + } + + if (tagging_.Tags().empty() || tagging_.Tags().size() > MaxTagSize) { + return ARG_ERROR_TAGGING_TAGS_LIMIT; + } + + for (const auto& tag : tagging_.Tags()) { + + if (!IsValidTagKey(tag.Key())) + return ARG_ERROR_TAGGING_TAG_KEY_LIMIT; + + if (!IsValidTagValue(tag.Value())) + return ARG_ERROR_TAGGING_TAG_VALUE_LIMIT; + } + + return 0; +} \ No newline at end of file diff --git a/sdk/src/model/Tagging.cc b/sdk/src/model/Tagging.cc new file mode 100644 index 0000000..caf8e76 --- /dev/null +++ b/sdk/src/model/Tagging.cc @@ -0,0 +1,40 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "../utils/Utils.h" +#include + +using namespace AlibabaCloud::OSS; + +std::string Tagging::toQueryParameters() +{ + std::string sep; + std::stringstream ss; + for (const auto& tag : tagSet_) + { + if (tag.Key().empty()) + continue; + + if (tag.Value().empty()) + ss << sep << UrlEncode(tag.Key()); + else + ss << sep << UrlEncode(tag.Key()) << "=" << UrlEncode(tag.Value()); + + sep = "&"; + } + return ss.str(); +} diff --git a/sdk/src/model/UploadObjectRequest.cc b/sdk/src/model/UploadObjectRequest.cc index d8507ac..2e6167e 100644 --- a/sdk/src/model/UploadObjectRequest.cc +++ b/sdk/src/model/UploadObjectRequest.cc @@ -88,6 +88,11 @@ void UploadObjectRequest::setCallback(const std::string& callback, const std::st } } +void UploadObjectRequest::setTagging(const std::string& value) +{ + metaData_.addHeader("x-oss-tagging", value); +} + int UploadObjectRequest::validate() const { if(partSize_ < PartSizeLowerLimit){ diff --git a/sdk/src/utils/SignUtils.cc b/sdk/src/utils/SignUtils.cc index 2727d9c..9f16676 100644 --- a/sdk/src/utils/SignUtils.cc +++ b/sdk/src/utils/SignUtils.cc @@ -1,123 +1,123 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "SignUtils.h" -#include "Utils.h" -#include -#include -#include -#include -#include -#include - -using namespace AlibabaCloud::OSS; - -const static std::set ParamtersToSign = -{ - "acl", "location", "bucketInfo", "stat", "referer", "cors", "website", "restore", - "logging", "symlink", "qos", "uploadId", "uploads", "partNumber", - "response-content-type", "response-content-language", "response-expires", - "response-cache-control", "response-content-disposition", "response-content-encoding", - "append", "position", "lifecycle", "delete", "live", "status", "comp", "vod", - "startTime", "endTime", "x-oss-process", "security-token", "objectMeta", - "callback", "callback-var" -}; - -SignUtils::SignUtils(const std::string &version): - signVersion_(version), - canonicalString_() -{ -} - -SignUtils::~SignUtils() -{ -} - -const std::string &SignUtils::CanonicalString() const -{ - return canonicalString_; -} - -void SignUtils::build(const std::string &method, - const std::string &resource, - const std::string &date, - const HeaderCollection &headers, - const ParameterCollection ¶meters) -{ - std::stringstream ss; - - /*Version 1*/ - // VERB + "\n" + - // Content-MD5 + "\n" + - // Content-Type + "\n" - // Date + "\n" + - // CanonicalizedOSSHeaders + - // CanonicalizedResource) + - - //common headers - ss << method << "\n"; - if (headers.find(Http::CONTENT_MD5) != headers.end()) { - ss << headers.at(Http::CONTENT_MD5); - } - ss << "\n"; - if (headers.find(Http::CONTENT_TYPE) != headers.end()) { - ss << headers.at(Http::CONTENT_TYPE); - } - ss << "\n"; - //Date or EXPIRES - ss << date << "\n"; - - //CanonicalizedOSSHeaders, start with x-oss- - for (const auto &header : headers) { - std::string lower = Trim(ToLower(header.first.c_str()).c_str()); - if (lower.compare(0, 6, "x-oss-", 6) == 0) { - std::string value = Trim(header.second.c_str()); - ss << lower << ":" << value << "\n"; - } - } - - //CanonicalizedResource, the sub resouce in - ss << resource; - char separator = '?'; - for (auto const& param : parameters) { - if (ParamtersToSign.find(param.first) == ParamtersToSign.end()) { - continue; - } - - ss << separator; - ss << param.first; - if (!param.second.empty()) { - ss << "=" << param.second; - } - separator = '&'; - } - - canonicalString_ = ss.str(); -} - -void SignUtils::build(const std::string &expires, - const std::string &resource, - const ParameterCollection ¶meters) -{ - std::stringstream ss; - ss << expires << '\n'; - for(auto const& param : parameters) - { - ss << param.first << ":" << param.second << '\n'; - } - ss << resource; - canonicalString_ = ss.str(); -} +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "SignUtils.h" +#include "Utils.h" +#include +#include +#include +#include +#include +#include + +using namespace AlibabaCloud::OSS; + +const static std::set ParamtersToSign = +{ + "acl", "location", "bucketInfo", "stat", "referer", "cors", "website", "restore", + "logging", "symlink", "qos", "uploadId", "uploads", "partNumber", + "response-content-type", "response-content-language", "response-expires", + "response-cache-control", "response-content-disposition", "response-content-encoding", + "append", "position", "lifecycle", "delete", "live", "status", "comp", "vod", + "startTime", "endTime", "x-oss-process", "security-token", "objectMeta", + "callback", "callback-var", "tagging" +}; + +SignUtils::SignUtils(const std::string &version): + signVersion_(version), + canonicalString_() +{ +} + +SignUtils::~SignUtils() +{ +} + +const std::string &SignUtils::CanonicalString() const +{ + return canonicalString_; +} + +void SignUtils::build(const std::string &method, + const std::string &resource, + const std::string &date, + const HeaderCollection &headers, + const ParameterCollection ¶meters) +{ + std::stringstream ss; + + /*Version 1*/ + // VERB + "\n" + + // Content-MD5 + "\n" + + // Content-Type + "\n" + // Date + "\n" + + // CanonicalizedOSSHeaders + + // CanonicalizedResource) + + + //common headers + ss << method << "\n"; + if (headers.find(Http::CONTENT_MD5) != headers.end()) { + ss << headers.at(Http::CONTENT_MD5); + } + ss << "\n"; + if (headers.find(Http::CONTENT_TYPE) != headers.end()) { + ss << headers.at(Http::CONTENT_TYPE); + } + ss << "\n"; + //Date or EXPIRES + ss << date << "\n"; + + //CanonicalizedOSSHeaders, start with x-oss- + for (const auto &header : headers) { + std::string lower = Trim(ToLower(header.first.c_str()).c_str()); + if (lower.compare(0, 6, "x-oss-", 6) == 0) { + std::string value = Trim(header.second.c_str()); + ss << lower << ":" << value << "\n"; + } + } + + //CanonicalizedResource, the sub resouce in + ss << resource; + char separator = '?'; + for (auto const& param : parameters) { + if (ParamtersToSign.find(param.first) == ParamtersToSign.end()) { + continue; + } + + ss << separator; + ss << param.first; + if (!param.second.empty()) { + ss << "=" << param.second; + } + separator = '&'; + } + + canonicalString_ = ss.str(); +} + +void SignUtils::build(const std::string &expires, + const std::string &resource, + const ParameterCollection ¶meters) +{ + std::stringstream ss; + ss << expires << '\n'; + for(auto const& param : parameters) + { + ss << param.first << ":" << param.second << '\n'; + } + ss << resource; + canonicalString_ = ss.str(); +} diff --git a/sdk/src/utils/Utils.cc b/sdk/src/utils/Utils.cc index 394679b..98caa4f 100644 --- a/sdk/src/utils/Utils.cc +++ b/sdk/src/utils/Utils.cc @@ -536,6 +536,19 @@ bool AlibabaCloud::OSS::IsValidBucketName(const std::string &bucketName) } } + bool AlibabaCloud::OSS::IsValidTagKey(const std::string &key) + { + if (key.empty() || key.size() > TagKeyLengthLimit) + return false; + + return true; + } + + bool AlibabaCloud::OSS::IsValidTagValue(const std::string &value) + { + return value.size() <= TagValueLengthLimit; + } + const std::string& AlibabaCloud::OSS::LookupMimeType(const std::string &name) { const static std::map mimeType = { diff --git a/sdk/src/utils/Utils.h b/sdk/src/utils/Utils.h index b8fd579..077a863 100644 --- a/sdk/src/utils/Utils.h +++ b/sdk/src/utils/Utils.h @@ -1,92 +1,93 @@ -/* - * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -namespace AlibabaCloud -{ -namespace OSS -{ - #define UNUSED_PARAM(x) ((void)(x)) - - std::string ComputeContentMD5(const std::string& data); - std::string ComputeContentMD5(const char *data, size_t size); - std::string ComputeContentMD5(std::istream & stream); - - std::string ComputeContentETag(const std::string& data); - std::string ComputeContentETag(const char *data, size_t size); - std::string ComputeContentETag(std::istream & stream); - - std::string GenerateUuid(); - std::string UrlEncode(const std::string &src); - std::string UrlDecode(const std::string &src); - - std::string Base64Encode(const std::string &src); - std::string Base64Encode(const char *src, int len); - std::string Base64EncodeUrlSafe(const std::string &src); - std::string Base64EncodeUrlSafe(const char *src, int len); - - - void StringReplace(std::string &src, const std::string &s1, const std::string &s2); - std::string LeftTrim(const char* source); - std::string RightTrim(const char* source); - std::string Trim(const char* source); - std::string LeftTrimQuotes(const char* source); - std::string RightTrimQuotes(const char* source); - std::string TrimQuotes(const char* source); - std::string ToLower(const char* source); - std::string ToUpper(const char* source); - std::string ToGmtTime(std::time_t &t); - std::string ToUtcTime(std::time_t &t); - std::time_t UtcToUnixTime(const std::string &t); - - bool IsIp(const std::string &host); - bool IsValidBucketName(const std::string &bucketName); - bool IsValidObjectKey(const std::string &key); - bool IsValidLoggingPrefix(const std::string &prefix); - bool IsValidChannelName(const std::string &channelName); - bool IsValidPlayListName(const std::string &playListName); - - - const std::string &LookupMimeType(const std::string& name); - std::string CombineHostString(const std::string &endpoint, const std::string &bucket, bool isCname); - std::string CombinePathString(const std::string &endpoint, const std::string &bucket, const std::string &key); - std::string CombineQueryString(const ParameterCollection ¶meters); - std::string CombineRTMPString(const std::string &endpoint, const std::string &bucket, bool isCname); - - - std::streampos GetIOStreamLength(std::iostream &stream); - - const char *ToStorageClassName(StorageClass storageClass); - StorageClass ToStorageClassType(const char *name); - - const char *ToAclName(CannedAccessControlList acl); - CannedAccessControlList ToAclType(const char *name); - - const char * ToCopyActionName(CopyActionList action); - - const char * ToRuleStatusName(RuleStatus status); - RuleStatus ToRuleStatusType(const char *name); - - const char * ToLiveChannelStatusName(LiveChannelStatus status); - LiveChannelStatus ToLiveChannelStatusType(const char *name); -} -} +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include + +namespace AlibabaCloud +{ +namespace OSS +{ + #define UNUSED_PARAM(x) ((void)(x)) + + std::string ComputeContentMD5(const std::string& data); + std::string ComputeContentMD5(const char *data, size_t size); + std::string ComputeContentMD5(std::istream & stream); + + std::string ComputeContentETag(const std::string& data); + std::string ComputeContentETag(const char *data, size_t size); + std::string ComputeContentETag(std::istream & stream); + + std::string GenerateUuid(); + std::string UrlEncode(const std::string &src); + std::string UrlDecode(const std::string &src); + + std::string Base64Encode(const std::string &src); + std::string Base64Encode(const char *src, int len); + std::string Base64EncodeUrlSafe(const std::string &src); + std::string Base64EncodeUrlSafe(const char *src, int len); + + + void StringReplace(std::string &src, const std::string &s1, const std::string &s2); + std::string LeftTrim(const char* source); + std::string RightTrim(const char* source); + std::string Trim(const char* source); + std::string LeftTrimQuotes(const char* source); + std::string RightTrimQuotes(const char* source); + std::string TrimQuotes(const char* source); + std::string ToLower(const char* source); + std::string ToUpper(const char* source); + std::string ToGmtTime(std::time_t &t); + std::string ToUtcTime(std::time_t &t); + std::time_t UtcToUnixTime(const std::string &t); + + bool IsIp(const std::string &host); + bool IsValidBucketName(const std::string &bucketName); + bool IsValidObjectKey(const std::string &key); + bool IsValidLoggingPrefix(const std::string &prefix); + bool IsValidChannelName(const std::string &channelName); + bool IsValidPlayListName(const std::string &playListName); + bool IsValidTagKey(const std::string &key); + bool IsValidTagValue(const std::string &value); + + const std::string &LookupMimeType(const std::string& name); + std::string CombineHostString(const std::string &endpoint, const std::string &bucket, bool isCname); + std::string CombinePathString(const std::string &endpoint, const std::string &bucket, const std::string &key); + std::string CombineQueryString(const ParameterCollection ¶meters); + std::string CombineRTMPString(const std::string &endpoint, const std::string &bucket, bool isCname); + + + std::streampos GetIOStreamLength(std::iostream &stream); + + const char *ToStorageClassName(StorageClass storageClass); + StorageClass ToStorageClassType(const char *name); + + const char *ToAclName(CannedAccessControlList acl); + CannedAccessControlList ToAclType(const char *name); + + const char * ToCopyActionName(CopyActionList action); + + const char * ToRuleStatusName(RuleStatus status); + RuleStatus ToRuleStatusType(const char *name); + + const char * ToLiveChannelStatusName(LiveChannelStatus status); + LiveChannelStatus ToLiveChannelStatusType(const char *name); +} +} diff --git a/test/src/Object/ObjectTaggingTest.cc b/test/src/Object/ObjectTaggingTest.cc new file mode 100644 index 0000000..45b73a3 --- /dev/null +++ b/test/src/Object/ObjectTaggingTest.cc @@ -0,0 +1,1256 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "../Config.h" +#include "../Utils.h" + +namespace AlibabaCloud +{ +namespace OSS +{ + +class ObjectTaggingTest : public ::testing::Test +{ +protected: + ObjectTaggingTest() + { + } + + ~ObjectTaggingTest() override + { + } + + // Sets up the stuff shared by all tests in this test case. + static void SetUpTestCase() + { + ClientConfiguration conf; + Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + BucketName = TestUtils::GetBucketName("cpp-sdk-objecttagging"); + CreateBucketOutcome outCome = Client->CreateBucket(CreateBucketRequest(BucketName)); + EXPECT_EQ(outCome.isSuccess(), true); + } + + // Tears down the stuff shared by all tests in this test case. + static void TearDownTestCase() + { + TestUtils::CleanBucket(*Client, BucketName); + Client = nullptr; + } + + // Sets up the test fixture. + void SetUp() override + { + } + + // Tears down the test fixture. + void TearDown() override + { + } +public: + static std::shared_ptr Client; + static std::string BucketName; +}; + +std::shared_ptr ObjectTaggingTest::Client = nullptr; +std::string ObjectTaggingTest::BucketName = ""; + +TEST_F(ObjectTaggingTest, TagClassTest) +{ + Tag tag1; + EXPECT_EQ("", tag1.Key()); + EXPECT_EQ("", tag1.Value()); + + tag1.setKey("key1"); + tag1.setValue("value1"); + EXPECT_EQ("key1", tag1.Key()); + EXPECT_EQ("value1", tag1.Value()); + + Tag tag2("key2", "value2"); + EXPECT_EQ("key2", tag2.Key()); + EXPECT_EQ("value2", tag2.Value()); +} + +TEST_F(ObjectTaggingTest, TaggingClassTest) +{ + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + + Tag tag("key3", "value3"); + tagging.addTag(tag); + EXPECT_EQ(tagging.Tags().size(), 3U); + EXPECT_EQ(tagging.Tags()[1].Key(), "key2"); + EXPECT_EQ(tagging.Tags()[1].Value(), "value2"); + + TagSet tagset; + tagset.push_back(Tag("key4", "value4")); + tagset.push_back(Tag("key5", "value5")); + Tagging tagging2(tagset); + EXPECT_EQ(tagging2.Tags().size(), 2U); + EXPECT_EQ(tagging2.Tags()[1].Key(), "key5"); + EXPECT_EQ(tagging2.Tags()[1].Value(), "value5"); + EXPECT_EQ(tagging2.toQueryParameters(), "key4=value4&key5=value5"); + + + tagset.push_back(Tag("key6", "value6")); + tagset.push_back(Tag("key7", "value7")); + tagging2.setTags(tagset); + EXPECT_EQ(tagging2.Tags().size(), 4U); + EXPECT_EQ(tagging2.Tags()[2].Key(), "key6"); + EXPECT_EQ(tagging2.Tags()[2].Value(), "value6"); + EXPECT_EQ(tagging2.toQueryParameters(), "key4=value4&key5=value5&key6=value6&key7=value7"); + + tagset.push_back(Tag("key8", "")); + tagset.push_back(Tag("key9", "value9")); + tagging2.setTags(tagset); + EXPECT_EQ(tagging2.toQueryParameters(), "key4=value4&key5=value5&key6=value6&key7=value7&key8&key9=value9"); + + tagging2.clear(); + EXPECT_EQ(tagging2.Tags().size(), 0U); + tagset.clear(); + tagset.push_back(Tag("key10=", "value 10+")); + tagset.push_back(Tag("key11&", "value11.")); + tagging2.setTags(tagset); + EXPECT_EQ(tagging2.Tags().size(), 2U); + EXPECT_EQ(tagging2.toQueryParameters(), "key10%3D=value%2010%2B&key11%26=value11."); + + tagging2.addTag(Tag("", "value12.")); + EXPECT_EQ(tagging2.Tags().size(), 3U); + EXPECT_EQ(tagging2.toQueryParameters(), "key10%3D=value%2010%2B&key11%26=value11."); +} + +TEST_F(ObjectTaggingTest, GetObjectTaggingResultTest) +{ + + std::string xml = R"( + + + + )"; + + GetObjectTaggingResult result(xml); + EXPECT_EQ(result.Tagging().Tags().size(), 0U); + + xml = R"( + + + + a + 1 + + + b + 2 + + + )"; + + GetObjectTaggingResult result1(xml); + EXPECT_EQ(result1.Tagging().Tags().size(), 2U); + EXPECT_EQ(result1.Tagging().Tags()[0].Key(), "a"); + EXPECT_EQ(result1.Tagging().Tags()[0].Value(), "1"); + EXPECT_EQ(result1.Tagging().Tags()[1].Key(), "b"); + EXPECT_EQ(result1.Tagging().Tags()[1].Value(), "2"); + + GetObjectTaggingResult result2; + result2 = xml; + EXPECT_EQ(result2.Tagging().Tags().size(), 2U); + EXPECT_EQ(result2.Tagging().Tags()[0].Key(), "a"); + EXPECT_EQ(result2.Tagging().Tags()[0].Value(), "1"); + EXPECT_EQ(result2.Tagging().Tags()[1].Key(), "b"); + EXPECT_EQ(result2.Tagging().Tags()[1].Value(), "2"); +} + +TEST_F(ObjectTaggingTest, LifecycleRuleClassTest) +{ + LifecycleRule rule1; + LifecycleRule rule2; + TagSet tagset; + tagset.push_back(Tag("key1", "value1")); + tagset.push_back(Tag("key2", "value2")); + + rule1.setTags(tagset); + EXPECT_EQ(rule1.Tags().size(), 2U); + rule1.addTag(Tag("key3", "value3")); + EXPECT_EQ(rule1.Tags().size(), 3U); + EXPECT_EQ(rule1.Tags()[0].Key(), "key1"); + EXPECT_EQ(rule1.Tags()[1].Key(), "key2"); + EXPECT_EQ(rule1.Tags()[2].Key(), "key3"); + + EXPECT_FALSE(rule1 == rule2); + + rule2.addTag(Tag("key1", "value1")); + rule2.addTag(Tag("key2", "value2")); + rule2.addTag(Tag("key3", "value3")); + EXPECT_TRUE(rule1 == rule2); + + rule2.setTags(tagset); + rule2.addTag(Tag("key4", "value3")); + EXPECT_FALSE(rule1 == rule2); + + rule2.setTags(tagset); + rule2.addTag(Tag("key3", "value4")); + EXPECT_FALSE(rule1 == rule2); +} + +TEST_F(ObjectTaggingTest, ObjectTaggingBasicTest) +{ + auto key = TestUtils::GetObjectKey("ObjectTaggingBasicTest"); + auto content = std::make_shared("Tagging Test"); + auto outcome = Client->PutObject(BucketName, key, content); + EXPECT_EQ(outcome.isSuccess(), true); + + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + auto putTaggingOutcome = Client->SetObjectTagging(SetObjectTaggingRequest(BucketName, key, tagging)); + EXPECT_EQ(putTaggingOutcome.isSuccess(), true); + EXPECT_TRUE(putTaggingOutcome.result().RequestId().size() > 0U); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 2U); + EXPECT_TRUE(getTaggingOutcome.result().RequestId().size() > 0U); + + size_t i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging.Tags()[i].Value(), tag.Value()); + i++; + } + + auto delTaggingOutcome = Client->DeleteObjectTagging(DeleteObjectTaggingRequest(BucketName, key)); + EXPECT_EQ(delTaggingOutcome.isSuccess(), true); + EXPECT_TRUE(delTaggingOutcome.result().RequestId().size() > 0U); + + + getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 0U); +} + +TEST_F(ObjectTaggingTest, ObjectTaggingNegativeTest) +{ + std::string key = "invalid-key"; + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + + auto putTaggingOutcome = Client->SetObjectTagging(SetObjectTaggingRequest("cpp-sdk-test-invalid-bucket", key, tagging)); + EXPECT_EQ(putTaggingOutcome.isSuccess(), false); + EXPECT_TRUE(putTaggingOutcome.error().RequestId().size() > 0U); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), false); + EXPECT_TRUE(getTaggingOutcome.error().RequestId().size() > 0U); + + auto delTaggingOutcome = Client->DeleteObjectTagging(DeleteObjectTaggingRequest(BucketName, key)); + EXPECT_EQ(delTaggingOutcome.isSuccess(), false); + EXPECT_TRUE(delTaggingOutcome.error().RequestId().size() > 0U); +} + +TEST_F(ObjectTaggingTest, SetObjectWithSpecialCharTagsTest) +{ + auto key = TestUtils::GetObjectKey("SetObjectWithSpecialCharTagsTest"); + auto content = std::make_shared("Tagging Test"); + auto outcome = Client->PutObject(BucketName, key, content); + EXPECT_EQ(outcome.isSuccess(), true); + + Tagging tagging; + tagging.addTag(Tag("key1=", "value 1+")); + tagging.addTag(Tag("key2-", "value2.")); + tagging.addTag(Tag("key3:/", "")); + + auto putTaggingOutcome = Client->SetObjectTagging(SetObjectTaggingRequest(BucketName, key, tagging)); + EXPECT_EQ(putTaggingOutcome.isSuccess(), true); + EXPECT_TRUE(putTaggingOutcome.result().RequestId().size() > 0); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 3U); + + size_t i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging.Tags()[i].Value(), tag.Value()); + i++; + } +} + +TEST_F(ObjectTaggingTest, SetObjectWithGreaterThan10TagsTest) +{ + auto key = TestUtils::GetObjectKey("SetObjectWithGreaterThan10TagsTest"); + auto content = std::make_shared("Tagging Test"); + auto outcome = Client->PutObject(BucketName, key, content); + EXPECT_EQ(outcome.isSuccess(), true); + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + tagging.addTag(Tag("key3", "value3")); + tagging.addTag(Tag("key4", "value4")); + tagging.addTag(Tag("key5", "value5")); + tagging.addTag(Tag("key6", "value6")); + tagging.addTag(Tag("key7", "value7")); + tagging.addTag(Tag("key8", "value8")); + tagging.addTag(Tag("key9", "value9")); + tagging.addTag(Tag("key10", "value10")); + tagging.addTag(Tag("key11", "value11")); + + auto putTaggingOutcome = Client->SetObjectTagging(SetObjectTaggingRequest(BucketName, key, tagging)); + EXPECT_EQ(putTaggingOutcome.isSuccess(), false); + EXPECT_EQ(putTaggingOutcome.error().Code(), "ValidateError"); + EXPECT_TRUE(putTaggingOutcome.error().Message().find("Object tags cannot be greater than 10") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, SetObjectWithDuplicatedTagsTest) +{ + auto key = TestUtils::GetObjectKey("SetObjectWithDuplicatedTagsTest"); + auto content = std::make_shared("Tagging Test"); + auto outcome = Client->PutObject(BucketName, key, content); + EXPECT_EQ(outcome.isSuccess(), true); + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key1", "value2")); + + auto putTaggingOutcome = Client->SetObjectTagging(SetObjectTaggingRequest(BucketName, key, tagging)); + EXPECT_EQ(putTaggingOutcome.isSuccess(), false); + EXPECT_EQ(putTaggingOutcome.error().Code(), "InvalidTag"); + EXPECT_TRUE(putTaggingOutcome.error().Message().find("Cannot provide multiple Tags with the same key") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, SetObjectWithUnsupportTagsTest) +{ + auto key = TestUtils::GetObjectKey("SetObjectWithUnsupportTagsTest"); + auto content = std::make_shared("Tagging Test"); + auto outcome = Client->PutObject(BucketName, key, content); + EXPECT_EQ(outcome.isSuccess(), true); + Tagging tagging; + tagging.addTag(Tag("key1&", "value1")); + tagging.addTag(Tag("key2", "value2")); + + auto putTaggingOutcome = Client->SetObjectTagging(SetObjectTaggingRequest(BucketName, key, tagging)); + EXPECT_EQ(putTaggingOutcome.isSuccess(), false); + EXPECT_EQ(putTaggingOutcome.error().Code(), "InvalidTag"); + EXPECT_TRUE(putTaggingOutcome.error().Message().find("The TagKey you have provided is invalid") != std::string::npos); +} + + +TEST_F(ObjectTaggingTest, PutObjectWithNormalCharTagsTest) +{ + auto key = TestUtils::GetObjectKey("PutObjectWithNormalCharTagsTest"); + auto content = std::make_shared("Tagging Test"); + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + + PutObjectRequest request(BucketName, key, content); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->PutObject(request); + EXPECT_EQ(outcome.isSuccess(), true); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 2U); + + size_t i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging.Tags()[i].Value(), tag.Value()); + i++; + } +} + +TEST_F(ObjectTaggingTest, PutObjectWithSpecialCharTagsTest) +{ + auto key = TestUtils::GetObjectKey("PutObjectWithSpecialCharTagsTest"); + auto content = std::make_shared("Tagging Test"); + Tagging tagging; + tagging.addTag(Tag("key1=", "value 1+")); + tagging.addTag(Tag("key2-", "value2.")); + tagging.addTag(Tag("key3:/", "")); + + PutObjectRequest request(BucketName, key, content); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->PutObject(request); + EXPECT_EQ(outcome.isSuccess(), true); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 3U); + + size_t i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging.Tags()[i].Value(), tag.Value()); + i++; + } +} + +TEST_F(ObjectTaggingTest, PutObjectWithGreaterThan10TagsTest) +{ + auto key = TestUtils::GetObjectKey("PutObjectWithGreaterThan10TagsTest"); + auto content = std::make_shared("Tagging Test"); + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + tagging.addTag(Tag("key3", "value3")); + tagging.addTag(Tag("key4", "value4")); + tagging.addTag(Tag("key5", "value5")); + tagging.addTag(Tag("key6", "value6")); + tagging.addTag(Tag("key7", "value7")); + tagging.addTag(Tag("key8", "value8")); + tagging.addTag(Tag("key9", "value9")); + tagging.addTag(Tag("key10", "value10")); + tagging.addTag(Tag("key11", "value11")); + + PutObjectRequest request(BucketName, key, content); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->PutObject(request); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "BadRequest"); + EXPECT_TRUE(outcome.error().Message().find("Object tags cannot be greater than 10") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, PutObjectWithDuplicatedTagsTest) +{ + auto key = TestUtils::GetObjectKey("PutObjectWithDuplicatedTagsTest"); + auto content = std::make_shared("Tagging Test"); + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key1", "value2")); + + PutObjectRequest request(BucketName, key, content); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->PutObject(request); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "InvalidArgument"); + EXPECT_TRUE(outcome.error().Message().find("query parameters without tag name duplicates") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, PutObjectWithUnsupportTagsTest) +{ + auto key = TestUtils::GetObjectKey("PutObjectWithUnsupportTagsTest"); + auto content = std::make_shared("Tagging Test"); + Tagging tagging; + tagging.addTag(Tag("key1&", "value1")); + tagging.addTag(Tag("key2", "value2")); + + PutObjectRequest request(BucketName, key, content); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->PutObject(request); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "InvalidTag"); + EXPECT_TRUE(outcome.error().Message().find("The TagKey you have provided is invalid") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, MultipartUploadWithNormalCharTagsTest) +{ + auto key = TestUtils::GetObjectKey("MultipartUploadWithNormalCharTagsTest"); + Tagging tagging; + tagging.addTag(Tag("key1=", "value 1+")); + tagging.addTag(Tag("key2-", "value2.")); + tagging.addTag(Tag("key3:/", "")); + + InitiateMultipartUploadRequest request(BucketName, key); + request.setTagging(tagging.toQueryParameters()); + auto initOutcome = Client->InitiateMultipartUpload(request); + EXPECT_EQ(initOutcome.isSuccess(), true); + EXPECT_FALSE(initOutcome.result().RequestId().empty()); + + PartList partETags; + auto content = TestUtils::GetRandomStream(1024); + UploadPartRequest uRequest(BucketName, key, content); + uRequest.setPartNumber(1); + uRequest.setUploadId(initOutcome.result().UploadId()); + auto uploadPartOutcome = Client->UploadPart(uRequest); + EXPECT_EQ(uploadPartOutcome.isSuccess(), true); + EXPECT_FALSE(uploadPartOutcome.result().RequestId().empty()); + Part part(1, uploadPartOutcome.result().ETag()); + partETags.push_back(part); + + CompleteMultipartUploadRequest completeRequest(BucketName, key, partETags); + completeRequest.setUploadId(initOutcome.result().UploadId()); + auto cOutcome = Client->CompleteMultipartUpload(completeRequest); + EXPECT_EQ(cOutcome.isSuccess(), true); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 3U); + + size_t i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging.Tags()[i].Value(), tag.Value()); + i++; + } +} + +TEST_F(ObjectTaggingTest, ResumableUploadWithNormalCharTagsByPutObjectTest) +{ + auto key = TestUtils::GetObjectKey("ResumableUploadWithNormalCharTagsByPutObjectTest"); + std::string file = TestUtils::GetTargetFileName("ResumableUploadWithNormalCharTagsByPutObjectTest"); + TestUtils::WriteRandomDatatoFile(file, 102400); + + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + + UploadObjectRequest request(BucketName, key, file); + request.setPartSize(204800U); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->ResumableUploadObject(request); + EXPECT_EQ(outcome.isSuccess(), true); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 2U); + + size_t i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging.Tags()[i].Value(), tag.Value()); + i++; + } +} + +TEST_F(ObjectTaggingTest, ResumableUploadWithNormalCharTagsTest) +{ + auto key = TestUtils::GetObjectKey("ResumableUploadWithNormalCharTagsTest"); + std::string file = TestUtils::GetTargetFileName("ResumableUploadWithNormalCharTagsTest"); + TestUtils::WriteRandomDatatoFile(file, 204800); + + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + + UploadObjectRequest request(BucketName, key, file); + request.setPartSize(102400U); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->ResumableUploadObject(request); + EXPECT_EQ(outcome.isSuccess(), true); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 2U); + + size_t i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging.Tags()[i].Value(), tag.Value()); + i++; + } +} + +TEST_F(ObjectTaggingTest, ResumableUploadWithSpecialCharTagsTest) +{ + auto key = TestUtils::GetObjectKey("ResumableUploadWithSpecialCharTagsTest"); + std::string file = TestUtils::GetTargetFileName("ResumableUploadWithSpecialCharTagsTest"); + TestUtils::WriteRandomDatatoFile(file, 204800); + + Tagging tagging; + tagging.addTag(Tag("key1=", "value 1+")); + tagging.addTag(Tag("key2-", "value2.")); + tagging.addTag(Tag("key3:/", "")); + + UploadObjectRequest request(BucketName, key, file); + request.setPartSize(102400U); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->ResumableUploadObject(request); + EXPECT_EQ(outcome.isSuccess(), true); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 3U); + + size_t i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging.Tags()[i].Value(), tag.Value()); + i++; + } +} + +TEST_F(ObjectTaggingTest, ResumableUploadWithGreaterThan10TagsTest) +{ + auto key = TestUtils::GetObjectKey("ResumableUploadWithGreaterThan10TagsTest"); + std::string file = TestUtils::GetTargetFileName("ResumableUploadWithSpecialCharTagsTest"); + TestUtils::WriteRandomDatatoFile(file, 204800); + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + tagging.addTag(Tag("key3", "value3")); + tagging.addTag(Tag("key4", "value4")); + tagging.addTag(Tag("key5", "value5")); + tagging.addTag(Tag("key6", "value6")); + tagging.addTag(Tag("key7", "value7")); + tagging.addTag(Tag("key8", "value8")); + tagging.addTag(Tag("key9", "value9")); + tagging.addTag(Tag("key10", "value10")); + tagging.addTag(Tag("key11", "value11")); + + UploadObjectRequest request(BucketName, key, file); + request.setPartSize(102400U); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->ResumableUploadObject(request); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "BadRequest"); + EXPECT_TRUE(outcome.error().Message().find("Object tags cannot be greater than 10") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, ResumableUploadWithDuplicatedTagsTest) +{ + auto key = TestUtils::GetObjectKey("ResumableUploadWithDuplicatedTagsTest"); + std::string file = TestUtils::GetTargetFileName("ResumableUploadWithDuplicatedTagsTest"); + TestUtils::WriteRandomDatatoFile(file, 204800); + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key1", "value2")); + + UploadObjectRequest request(BucketName, key, file); + request.setPartSize(102400U); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->ResumableUploadObject(request); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "InvalidArgument"); + EXPECT_TRUE(outcome.error().Message().find("query parameters without tag name duplicates") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, ResumableUploadWithUnsupportTagsTest) +{ + auto key = TestUtils::GetObjectKey("ResumableUploadWithUnsupportTagsTest"); + std::string file = TestUtils::GetTargetFileName("ResumableUploadWithUnsupportTagsTest"); + TestUtils::WriteRandomDatatoFile(file, 204800); + Tagging tagging; + tagging.addTag(Tag("key1&", "value1")); + tagging.addTag(Tag("key2", "value2")); + + UploadObjectRequest request(BucketName, key, file); + request.setPartSize(102400U); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->ResumableUploadObject(request); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "InvalidTag"); + EXPECT_TRUE(outcome.error().Message().find("The TagKey you have provided is invalid") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, AppendObjectWithNormalCharTagsTest) +{ + auto key = TestUtils::GetObjectKey("AppendObjectWithNormalCharTagsTest"); + auto content = std::make_shared("Tagging Test"); + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + + AppendObjectRequest request(BucketName, key, content); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->AppendObject(request); + EXPECT_EQ(outcome.isSuccess(), true); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 2U); + + size_t i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging.Tags()[i].Value(), tag.Value()); + i++; + } +} + +TEST_F(ObjectTaggingTest, AppendObjectWithSpecialCharTagsTest) +{ + auto key = TestUtils::GetObjectKey("AppendObjectWithSpecialCharTagsTest"); + auto content = std::make_shared("Tagging Test"); + Tagging tagging; + tagging.addTag(Tag("key1=", "value 1+")); + tagging.addTag(Tag("key2-", "value2.")); + tagging.addTag(Tag("key3:/", "")); + + AppendObjectRequest request(BucketName, key, content); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->AppendObject(request); + EXPECT_EQ(outcome.isSuccess(), true); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 3U); + + size_t i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging.Tags()[i].Value(), tag.Value()); + i++; + } +} + +TEST_F(ObjectTaggingTest, AppendObjectWithGreaterThan10TagsTest) +{ + auto key = TestUtils::GetObjectKey("AppendObjectWithGreaterThan10TagsTest"); + auto content = std::make_shared("Tagging Test"); + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + tagging.addTag(Tag("key3", "value3")); + tagging.addTag(Tag("key4", "value4")); + tagging.addTag(Tag("key5", "value5")); + tagging.addTag(Tag("key6", "value6")); + tagging.addTag(Tag("key7", "value7")); + tagging.addTag(Tag("key8", "value8")); + tagging.addTag(Tag("key9", "value9")); + tagging.addTag(Tag("key10", "value10")); + tagging.addTag(Tag("key11", "value11")); + + AppendObjectRequest request(BucketName, key, content); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->AppendObject(request); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "BadRequest"); + EXPECT_TRUE(outcome.error().Message().find("Object tags cannot be greater than 10") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, AppendObjectWithDuplicatedTagsTest) +{ + auto key = TestUtils::GetObjectKey("AppendObjectWithDuplicatedTagsTest"); + auto content = std::make_shared("Tagging Test"); + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key1", "value2")); + + AppendObjectRequest request(BucketName, key, content); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->AppendObject(request); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "InvalidArgument"); + EXPECT_TRUE(outcome.error().Message().find("query parameters without tag name duplicates") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, AppendObjectWithUnsupportTagsTest) +{ + auto key = TestUtils::GetObjectKey("AppendObjectWithUnsupportTagsTest"); + auto content = std::make_shared("Tagging Test"); + Tagging tagging; + tagging.addTag(Tag("key1&", "value1")); + tagging.addTag(Tag("key2", "value2")); + + AppendObjectRequest request(BucketName, key, content); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->AppendObject(request); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "InvalidTag"); + EXPECT_TRUE(outcome.error().Message().find("The TagKey you have provided is invalid") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, CopyObjectWithDefaultTest) +{ + auto key = TestUtils::GetObjectKey("CopyObjectWithDefaultTest"); + auto content = std::make_shared("Tagging Test"); + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + + PutObjectRequest request(BucketName, key, content); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->PutObject(request); + EXPECT_EQ(outcome.isSuccess(), true); + + auto key_cp = TestUtils::GetObjectKey("CopyObjectWithDefaultTest-COPY"); + CopyObjectRequest cpRequest(BucketName, key_cp); + cpRequest.setCopySource(BucketName, key); + auto cpOutcome = Client->CopyObject(cpRequest); + EXPECT_EQ(cpOutcome.isSuccess(), true); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key_cp)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 2U); + + size_t i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging.Tags()[i].Value(), tag.Value()); + i++; + } + + EXPECT_EQ(outcome.result().ETag(), Client->HeadObject(BucketName, key_cp).result().ETag()); +} + +TEST_F(ObjectTaggingTest, CopyObjectWithNormalCharTagsTest) +{ + auto key = TestUtils::GetObjectKey("CopyObjectWithNormalCharTagsTest"); + auto content = std::make_shared("Tagging Test"); + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + + PutObjectRequest request(BucketName, key, content); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->PutObject(request); + EXPECT_EQ(outcome.isSuccess(), true); + + Tagging tagging2; + tagging2.addTag(Tag("key1-2", "value1-2")); + tagging2.addTag(Tag("key2-2", "value2-2")); + tagging2.addTag(Tag("key3-2", "value3-2")); + + //replace + auto key_cp = TestUtils::GetObjectKey("CopyObjectWithNormalCharTagsTest-COPY"); + CopyObjectRequest cpRequest(BucketName, key_cp); + cpRequest.setCopySource(BucketName, key); + cpRequest.setTagging(tagging2.toQueryParameters()); + cpRequest.setTaggingDirective(CopyActionList::Replace); + auto cpOutcome = Client->CopyObject(cpRequest); + EXPECT_EQ(cpOutcome.isSuccess(), true); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key_cp)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 3U); + + size_t i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging2.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging2.Tags()[i].Value(), tag.Value()); + i++; + } + EXPECT_EQ(outcome.result().ETag(), Client->HeadObject(BucketName, key_cp).result().ETag()); + + //copy + cpRequest.setCopySource(BucketName, key); + cpRequest.setTagging(tagging2.toQueryParameters()); + cpRequest.setTaggingDirective(CopyActionList::Copy); + cpOutcome = Client->CopyObject(cpRequest); + EXPECT_EQ(cpOutcome.isSuccess(), true); + + getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key_cp)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 2U); + + i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging.Tags()[i].Value(), tag.Value()); + i++; + } + EXPECT_EQ(outcome.result().ETag(), Client->HeadObject(BucketName, key_cp).result().ETag()); +} + +TEST_F(ObjectTaggingTest, CopyObjectWithSpecialCharTagsTest) +{ + auto key = TestUtils::GetObjectKey("CopyObjectWithSpecialCharTagsTest"); + auto content = std::make_shared("Tagging Test"); + + auto outcome = Client->PutObject(PutObjectRequest(BucketName, key, content)); + EXPECT_EQ(outcome.isSuccess(), true); + + Tagging tagging; + tagging.addTag(Tag("key1=", "value 1+")); + tagging.addTag(Tag("key2-", "value2.")); + tagging.addTag(Tag("key3:/", "")); + + //replace + auto key_cp = TestUtils::GetObjectKey("CopyObjectWithSpecialCharTagsTest-COPY"); + CopyObjectRequest cpRequest(BucketName, key_cp); + cpRequest.setCopySource(BucketName, key); + cpRequest.setTagging(tagging.toQueryParameters()); + cpRequest.setTaggingDirective(CopyActionList::Replace); + auto cpOutcome = Client->CopyObject(cpRequest); + EXPECT_EQ(cpOutcome.isSuccess(), true); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key_cp)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 3U); + + size_t i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging.Tags()[i].Value(), tag.Value()); + i++; + } + EXPECT_EQ(outcome.result().ETag(), Client->HeadObject(BucketName, key_cp).result().ETag()); +} + +TEST_F(ObjectTaggingTest, CopyObjectWithGreaterThan10TagsTest) +{ + auto key = TestUtils::GetObjectKey("CopyObjectWithGreaterThan10TagsTest"); + auto content = std::make_shared("Tagging Test"); + + auto putOutcome = Client->PutObject(PutObjectRequest(BucketName, key, content)); + EXPECT_EQ(putOutcome.isSuccess(), true); + + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + tagging.addTag(Tag("key3", "value3")); + tagging.addTag(Tag("key4", "value4")); + tagging.addTag(Tag("key5", "value5")); + tagging.addTag(Tag("key6", "value6")); + tagging.addTag(Tag("key7", "value7")); + tagging.addTag(Tag("key8", "value8")); + tagging.addTag(Tag("key9", "value9")); + tagging.addTag(Tag("key10", "value10")); + tagging.addTag(Tag("key11", "value11")); + + //replace + auto key_cp = TestUtils::GetObjectKey("CopyObjectWithGreaterThan10TagsTest-COPY"); + CopyObjectRequest cpRequest(BucketName, key_cp); + cpRequest.setCopySource(BucketName, key); + cpRequest.setTagging(tagging.toQueryParameters()); + cpRequest.setTaggingDirective(CopyActionList::Replace); + auto outcome = Client->CopyObject(cpRequest); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "BadRequest"); + EXPECT_TRUE(outcome.error().Message().find("Object tags cannot be greater than 10") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, CopyObjectWithDuplicatedTagsTest) +{ + auto key = TestUtils::GetObjectKey("CopyObjectWithDuplicatedTagsTest"); + auto content = std::make_shared("Tagging Test"); + + auto putOutcome = Client->PutObject(PutObjectRequest(BucketName, key, content)); + EXPECT_EQ(putOutcome.isSuccess(), true); + + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key1", "value2")); + + //replace + auto key_cp = TestUtils::GetObjectKey("CopyObjectWithDuplicatedTagsTest-COPY"); + CopyObjectRequest cpRequest(BucketName, key_cp); + cpRequest.setCopySource(BucketName, key); + cpRequest.setTagging(tagging.toQueryParameters()); + cpRequest.setTaggingDirective(CopyActionList::Replace); + auto outcome = Client->CopyObject(cpRequest); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "InvalidArgument"); + EXPECT_TRUE(outcome.error().Message().find("query parameters without tag name duplicates") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, CopyObjectWithUnsupportTagsTest) +{ + auto key = TestUtils::GetObjectKey("CopyObjectWithUnsupportTagsTest"); + auto content = std::make_shared("Tagging Test"); + + auto putOutcome = Client->PutObject(PutObjectRequest(BucketName, key, content)); + EXPECT_EQ(putOutcome.isSuccess(), true); + + Tagging tagging; + tagging.addTag(Tag("key1&", "value1")); + tagging.addTag(Tag("key2", "value2")); + + //replace + auto key_cp = TestUtils::GetObjectKey("CopyObjectWithUnsupportTagsTest-COPY"); + CopyObjectRequest cpRequest(BucketName, key_cp); + cpRequest.setCopySource(BucketName, key); + cpRequest.setTagging(tagging.toQueryParameters()); + cpRequest.setTaggingDirective(CopyActionList::Replace); + auto outcome = Client->CopyObject(cpRequest); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "InvalidTag"); + EXPECT_TRUE(outcome.error().Message().find("The TagKey you have provided is invalid") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, CreateSymlinkWithDefaultTest) +{ + auto key = TestUtils::GetObjectKey("CreateSymlinkWithDefaultTest"); + auto content = std::make_shared("Tagging Test"); + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + + PutObjectRequest request(BucketName, key, content); + request.setTagging(tagging.toQueryParameters()); + auto outcome = Client->PutObject(request); + EXPECT_EQ(outcome.isSuccess(), true); + + auto key_ln = TestUtils::GetObjectKey("CreateSymlinkWithDefaultTest-LINK"); + CreateSymlinkRequest csRequest(BucketName, key_ln); + csRequest.SetSymlinkTarget(key); + auto csOutcome = Client->CreateSymlink(csRequest); + EXPECT_EQ(csOutcome.isSuccess(), true); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key_ln)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 0U); + + EXPECT_EQ(outcome.result().ETag(), Client->HeadObject(BucketName, key_ln).result().ETag()); +} + +TEST_F(ObjectTaggingTest, CreateSymlinkWithNormalCharTagsTest) +{ + auto key = TestUtils::GetObjectKey("CreateSymlinkWithNormalCharTagsTest"); + auto content = std::make_shared("Tagging Test"); + + auto outcome = Client->PutObject(PutObjectRequest(BucketName, key, content)); + EXPECT_EQ(outcome.isSuccess(), true); + + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + + auto key_ln = TestUtils::GetObjectKey("CreateSymlinkWithNormalCharTagsTest-LINK"); + CreateSymlinkRequest csRequest(BucketName, key_ln); + csRequest.SetSymlinkTarget(key); + csRequest.setTagging(tagging.toQueryParameters()); + auto csOutcome = Client->CreateSymlink(csRequest); + EXPECT_EQ(csOutcome.isSuccess(), true); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key_ln)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 2U); + + size_t i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging.Tags()[i].Value(), tag.Value()); + i++; + } + EXPECT_EQ(outcome.result().ETag(), Client->HeadObject(BucketName, key_ln).result().ETag()); +} + +TEST_F(ObjectTaggingTest, CreateSymlinkWithSpecialCharTagsTest) +{ + auto key = TestUtils::GetObjectKey("CreateSymlinkWithSpecialCharTagsTest"); + auto content = std::make_shared("Tagging Test"); + + auto outcome = Client->PutObject(PutObjectRequest(BucketName, key, content)); + EXPECT_EQ(outcome.isSuccess(), true); + + Tagging tagging; + tagging.addTag(Tag("key1=", "value 1+")); + tagging.addTag(Tag("key2-", "value2.")); + tagging.addTag(Tag("key3:/", "")); + + auto key_ln = TestUtils::GetObjectKey("CreateSymlinkWithSpecialCharTagsTest-LINK"); + CreateSymlinkRequest csRequest(BucketName, key_ln); + csRequest.SetSymlinkTarget(key); + csRequest.setTagging(tagging.toQueryParameters()); + auto csOutcome = Client->CreateSymlink(csRequest); + EXPECT_EQ(csOutcome.isSuccess(), true); + + auto getTaggingOutcome = Client->GetObjectTagging(GetObjectTaggingRequest(BucketName, key_ln)); + EXPECT_EQ(getTaggingOutcome.isSuccess(), true); + EXPECT_EQ(getTaggingOutcome.result().Tagging().Tags().size(), 3U); + + size_t i = 0; + for (const auto& tag : getTaggingOutcome.result().Tagging().Tags()) { + EXPECT_EQ(tagging.Tags()[i].Key(), tag.Key()); + EXPECT_EQ(tagging.Tags()[i].Value(), tag.Value()); + i++; + } + + EXPECT_EQ(outcome.result().ETag(), Client->HeadObject(BucketName, key_ln).result().ETag()); +} + +TEST_F(ObjectTaggingTest, CreateSymlinkWithGreaterThan10TagsTest) +{ + auto key = TestUtils::GetObjectKey("CreateSymlinkWithGreaterThan10TagsTest"); + auto content = std::make_shared("Tagging Test"); + + auto putOutcome = Client->PutObject(PutObjectRequest(BucketName, key, content)); + EXPECT_EQ(putOutcome.isSuccess(), true); + + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key2", "value2")); + tagging.addTag(Tag("key3", "value3")); + tagging.addTag(Tag("key4", "value4")); + tagging.addTag(Tag("key5", "value5")); + tagging.addTag(Tag("key6", "value6")); + tagging.addTag(Tag("key7", "value7")); + tagging.addTag(Tag("key8", "value8")); + tagging.addTag(Tag("key9", "value9")); + tagging.addTag(Tag("key10", "value10")); + tagging.addTag(Tag("key11", "value11")); + + auto key_ln = TestUtils::GetObjectKey("CreateSymlinkWithGreaterThan10TagsTest-LINK"); + CreateSymlinkRequest csRequest(BucketName, key_ln); + csRequest.SetSymlinkTarget(key); + csRequest.setTagging(tagging.toQueryParameters()); + auto outcome = Client->CreateSymlink(csRequest); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "BadRequest"); + EXPECT_TRUE(outcome.error().Message().find("Object tags cannot be greater than 10") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, CreateSymlinkWithDuplicatedTagsTest) +{ + auto key = TestUtils::GetObjectKey("CreateSymlinkWithDuplicatedTagsTest"); + auto content = std::make_shared("Tagging Test"); + + auto putOutcome = Client->PutObject(PutObjectRequest(BucketName, key, content)); + EXPECT_EQ(putOutcome.isSuccess(), true); + + Tagging tagging; + tagging.addTag(Tag("key1", "value1")); + tagging.addTag(Tag("key1", "value2")); + + auto key_ln = TestUtils::GetObjectKey("CreateSymlinkWithDuplicatedTagsTest-LINK"); + CreateSymlinkRequest csRequest(BucketName, key_ln); + csRequest.SetSymlinkTarget(key); + csRequest.setTagging(tagging.toQueryParameters()); + auto outcome = Client->CreateSymlink(csRequest); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "InvalidArgument"); + EXPECT_TRUE(outcome.error().Message().find("query parameters without tag name duplicates") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, CreateSymlinkWithUnsupportTagsTest) +{ + auto key = TestUtils::GetObjectKey("CreateSymlinkWithDuplicatedTagsTest"); + auto content = std::make_shared("Tagging Test"); + + auto putOutcome = Client->PutObject(PutObjectRequest(BucketName, key, content)); + EXPECT_EQ(putOutcome.isSuccess(), true); + + Tagging tagging; + tagging.addTag(Tag("key1&", "value1")); + tagging.addTag(Tag("key2", "value2")); + + auto key_ln = TestUtils::GetObjectKey("CreateSymlinkWithDuplicatedTagsTest-LINK"); + CreateSymlinkRequest csRequest(BucketName, key_ln); + csRequest.SetSymlinkTarget(key); + csRequest.setTagging(tagging.toQueryParameters()); + auto outcome = Client->CreateSymlink(csRequest); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "InvalidTag"); + EXPECT_TRUE(outcome.error().Message().find("The TagKey you have provided is invalid") != std::string::npos); +} + +TEST_F(ObjectTaggingTest, LifecycleNormalCharTagsTest) +{ + auto rule = LifecycleRule(); + rule.setID("StandardExpireRule-001"); + rule.setPrefix("test"); + rule.addTag(Tag("key1", "value1")); + rule.addTag(Tag("key2", "value2")); + rule.setStatus(RuleStatus::Enabled); + rule.Expiration().setDays(200); + + SetBucketLifecycleRequest request(BucketName); + request.addLifecycleRule(rule); + auto outcome = Client->SetBucketLifecycle(request); + EXPECT_EQ(outcome.isSuccess(), true); + + TestUtils::WaitForCacheExpire(5); + auto gOutcome = Client->GetBucketLifecycle(BucketName); + EXPECT_EQ(gOutcome.isSuccess(), true); + EXPECT_TRUE(*(gOutcome.result().LifecycleRules().begin()) == rule); +} + + +TEST_F(ObjectTaggingTest, LifecycleWithSpecialCharTagsTest) +{ + TagSet tagSet; + tagSet.push_back(Tag("key1=", "value 1+")); + tagSet.push_back(Tag("key2-", "value2.")); + tagSet.push_back(Tag("key3:/", "")); + + auto rule = LifecycleRule(); + rule.setID("StandardExpireRule-001"); + rule.setPrefix("test"); + rule.setStatus(RuleStatus::Enabled); + rule.Expiration().setDays(200); + rule.setTags(tagSet); + + SetBucketLifecycleRequest request(BucketName); + request.addLifecycleRule(rule); + auto outcome = Client->SetBucketLifecycle(request); + EXPECT_EQ(outcome.isSuccess(), true); + + TestUtils::WaitForCacheExpire(5); + auto gOutcome = Client->GetBucketLifecycle(BucketName); + EXPECT_EQ(gOutcome.isSuccess(), true); + EXPECT_TRUE(*(gOutcome.result().LifecycleRules().begin()) == rule); +} + +TEST_F(ObjectTaggingTest, LifecycleWithGreaterThan10TagsTest) +{ + TagSet tagSet; + tagSet.push_back(Tag("key1", "value1")); + tagSet.push_back(Tag("key2", "value2")); + tagSet.push_back(Tag("key3", "value3")); + tagSet.push_back(Tag("key4", "value4")); + tagSet.push_back(Tag("key5", "value5")); + tagSet.push_back(Tag("key6", "value6")); + tagSet.push_back(Tag("key7", "value7")); + tagSet.push_back(Tag("key8", "value8")); + tagSet.push_back(Tag("key9", "value9")); + tagSet.push_back(Tag("key10", "value10")); + tagSet.push_back(Tag("key11", "value11")); + + auto rule = LifecycleRule(); + rule.setID("StandardExpireRule-001"); + rule.setPrefix("test"); + rule.setStatus(RuleStatus::Enabled); + rule.Expiration().setDays(200); + rule.setTags(tagSet); + + SetBucketLifecycleRequest request(BucketName); + request.addLifecycleRule(rule); + auto outcome = Client->SetBucketLifecycle(request); + EXPECT_EQ(outcome.isSuccess(), true); + + TestUtils::WaitForCacheExpire(5); + auto gOutcome = Client->GetBucketLifecycle(BucketName); + EXPECT_EQ(gOutcome.isSuccess(), true); + EXPECT_TRUE(*(gOutcome.result().LifecycleRules().begin()) == rule); +} + +TEST_F(ObjectTaggingTest, LifecycleWithDuplicatedTagsTest) +{ + TagSet tagSet; + tagSet.push_back(Tag("key1", "value1")); + tagSet.push_back(Tag("key1", "value2")); + + auto rule = LifecycleRule(); + rule.setID("StandardExpireRule-001"); + rule.setPrefix("test"); + rule.setStatus(RuleStatus::Enabled); + rule.Expiration().setDays(200); + rule.setTags(tagSet); + + SetBucketLifecycleRequest request(BucketName); + request.addLifecycleRule(rule); + auto outcome = Client->SetBucketLifecycle(request); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "MalformedXML"); +} + +TEST_F(ObjectTaggingTest, LifecycleWithUnsupportTagsTest) +{ + TagSet tagSet; + tagSet.push_back(Tag("key1&", "value1")); + tagSet.push_back(Tag("key2", "value2")); + + auto rule = LifecycleRule(); + rule.setID("StandardExpireRule-001"); + rule.setPrefix("test"); + rule.setStatus(RuleStatus::Enabled); + rule.Expiration().setDays(200); + rule.setTags(tagSet); + + SetBucketLifecycleRequest request(BucketName); + request.addLifecycleRule(rule); + auto outcome = Client->SetBucketLifecycle(request); + EXPECT_EQ(outcome.isSuccess(), false); + EXPECT_EQ(outcome.error().Code(), "MalformedXML"); +} + +} +}