/* * 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 "ModelError.h" using namespace AlibabaCloud::OSS; SetBucketLifecycleRequest::SetBucketLifecycleRequest(const std::string& bucket) : OssBucketRequest(bucket) { setFlags(Flags() | REQUEST_FLAG_CONTENTMD5); } 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 if (!rule.Expiration().CreatedBeforeDate().empty()){ ss << " " << rule.Expiration().CreatedBeforeDate() << "" << std::endl; } if (rule.ExpiredObjectDeleteMarker()) { ss << " true" << 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; } if (rule.hasNoncurrentVersionExpiration()) { ss << " " << std::endl; ss << " " << std::to_string(rule.NoncurrentVersionExpiration().Days()) << "" << std::endl; ss << " " << std::endl; } for (auto const & transition : rule.NoncurrentVersionTransitionList()) { ss << " " << std::endl; if (transition.Expiration().Days() > 0) { ss << " " << std::to_string(transition.Expiration().Days()) << "" << std::endl; } ss << " " << ToStorageClassName(transition.StorageClass()) << "" << 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() && !rule.hasNoncurrentVersionExpiration() && !rule.hasNoncurrentVersionTransitionList()) { 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; }