1 /* 2 * Copyright 2009-2017 Alibaba Cloud All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <alibabacloud/oss/model/SetBucketInventoryConfigurationRequest.h> 18 #include "utils/Utils.h" 19 #include <sstream> 20 21 using namespace AlibabaCloud::OSS; 22 SetBucketInventoryConfigurationRequest(const std::string & bucket)23SetBucketInventoryConfigurationRequest::SetBucketInventoryConfigurationRequest(const std::string& bucket) : 24 SetBucketInventoryConfigurationRequest(bucket, InventoryConfiguration()) 25 { 26 } 27 SetBucketInventoryConfigurationRequest(const std::string & bucket,const InventoryConfiguration & conf)28SetBucketInventoryConfigurationRequest::SetBucketInventoryConfigurationRequest(const std::string& bucket, const InventoryConfiguration& conf) : 29 OssBucketRequest(bucket), 30 inventoryConfiguration_(conf) 31 { 32 setFlags(Flags() | REQUEST_FLAG_CONTENTMD5); 33 } 34 setInventoryConfiguration(InventoryConfiguration conf)35void SetBucketInventoryConfigurationRequest::setInventoryConfiguration(InventoryConfiguration conf) 36 { 37 inventoryConfiguration_ = conf; 38 } 39 specialParameters() const40ParameterCollection SetBucketInventoryConfigurationRequest::specialParameters() const 41 { 42 ParameterCollection parameters; 43 parameters["inventory"] = ""; 44 parameters["inventoryId"] = inventoryConfiguration_.Id(); 45 return parameters; 46 } 47 payload() const48std::string SetBucketInventoryConfigurationRequest::payload() const 49 { 50 std::stringstream ss; 51 ss << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl; 52 ss << "<InventoryConfiguration>" << std::endl; 53 ss << " <Id>" << inventoryConfiguration_.Id() << "</Id>" << std::endl; 54 ss << " <IsEnabled>" << (inventoryConfiguration_.IsEnabled() ? "true" : "false") << "</IsEnabled>" << std::endl; 55 56 if (!inventoryConfiguration_.Filter().Prefix().empty()) { 57 ss << " <Filter>" << std::endl; 58 ss << " <Prefix>" << inventoryConfiguration_.Filter().Prefix() << "</Prefix>" << std::endl; 59 ss << " </Filter>" << std::endl; 60 } 61 62 bool hasEncryption = inventoryConfiguration_.Destination().OSSBucketDestination().Encryption().hasSSEKMS() || 63 inventoryConfiguration_.Destination().OSSBucketDestination().Encryption().hasSSEOSS(); 64 65 ss << " <Destination>" << std::endl; 66 ss << " <OSSBucketDestination>" << std::endl; 67 ss << " <Format>" << ToInventoryFormatName(inventoryConfiguration_.Destination().OSSBucketDestination().Format()) << "</Format>" << std::endl; 68 ss << " <AccountId>" << inventoryConfiguration_.Destination().OSSBucketDestination().AccountId() << "</AccountId>" << std::endl; 69 ss << " <RoleArn>" << inventoryConfiguration_.Destination().OSSBucketDestination().RoleArn() << "</RoleArn>" << std::endl; 70 ss << " <Bucket>" << ToInventoryBucketFullName(inventoryConfiguration_.Destination().OSSBucketDestination().Bucket()) << "</Bucket>" << std::endl; 71 ss << " <Prefix>" << inventoryConfiguration_.Destination().OSSBucketDestination().Prefix() << "</Prefix>" << std::endl; 72 if (hasEncryption) { 73 ss << " <Encryption>" << std::endl; 74 if (inventoryConfiguration_.Destination().OSSBucketDestination().Encryption().hasSSEKMS()) { 75 ss << " <SSE-KMS>" << std::endl; 76 ss << " <KeyId>" << inventoryConfiguration_.Destination().OSSBucketDestination().Encryption().SSEKMS().KeyId() << "</KeyId>" << std::endl; 77 ss << " </SSE-KMS>" << std::endl; 78 } 79 if (inventoryConfiguration_.Destination().OSSBucketDestination().Encryption().hasSSEOSS()) { 80 ss << " <SSE-OSS>" << std::endl; 81 ss << " </SSE-OSS>" << std::endl; 82 } 83 ss << " </Encryption>" << std::endl; 84 } 85 ss << " </OSSBucketDestination>" << std::endl; 86 ss << " </Destination>" << std::endl; 87 88 ss << " <Schedule>" << std::endl; 89 ss << " <Frequency>" << ToInventoryFrequencyName(inventoryConfiguration_.Schedule()) << "</Frequency>" << std::endl; 90 ss << " </Schedule>" << std::endl; 91 ss << " <IncludedObjectVersions>" << ToInventoryIncludedObjectVersionsName(inventoryConfiguration_.IncludedObjectVersions()) << "</IncludedObjectVersions>" << std::endl; 92 93 if (!inventoryConfiguration_.OptionalFields().empty()) { 94 ss << " <OptionalFields>" << std::endl; 95 for (const auto& field : inventoryConfiguration_.OptionalFields()) { 96 ss << " <Field>" << ToInventoryOptionalFieldName(field) << "</Field>" << std::endl; 97 } 98 ss << " </OptionalFields>" << std::endl; 99 } 100 101 ss << "</InventoryConfiguration>" << std::endl; 102 return ss.str(); 103 }