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/SetBucketEncryptionRequest.h>
18 #include "utils/Utils.h"
19 #include <sstream>
20 
21 using namespace AlibabaCloud::OSS;
22 
23 
SetBucketEncryptionRequest(const std::string & bucket,SSEAlgorithm sse,const std::string & key)24 SetBucketEncryptionRequest::SetBucketEncryptionRequest(const std::string& bucket, SSEAlgorithm sse, const std::string& key):
25     OssBucketRequest(bucket),
26     SSEAlgorithm_(sse),
27     KMSMasterKeyID_(key)
28 {
29     setFlags(Flags() | REQUEST_FLAG_CONTENTMD5);
30 }
31 
setSSEAlgorithm(SSEAlgorithm sse)32 void SetBucketEncryptionRequest::setSSEAlgorithm(SSEAlgorithm sse)
33 {
34     SSEAlgorithm_ = sse;
35 }
36 
setKMSMasterKeyID(const std::string & key)37 void SetBucketEncryptionRequest::setKMSMasterKeyID(const std::string& key)
38 {
39     KMSMasterKeyID_ = key;
40 }
41 
specialParameters() const42 ParameterCollection SetBucketEncryptionRequest::specialParameters() const
43 {
44     ParameterCollection parameters;
45     parameters["encryption"] = "";
46     return parameters;
47 }
48 
payload() const49 std::string SetBucketEncryptionRequest::payload() const
50 {
51     std::stringstream ss;
52     ss << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
53     ss << "<ServerSideEncryptionRule>" << std::endl;
54     ss << "  <ApplyServerSideEncryptionByDefault>" << std::endl;
55     ss << "<SSEAlgorithm>" << ToSSEAlgorithmName(SSEAlgorithm_) << "</SSEAlgorithm>" << std::endl;
56     ss << "<KMSMasterKeyID>" << KMSMasterKeyID_ << "</KMSMasterKeyID>" << std::endl;
57     ss << "</ApplyServerSideEncryptionByDefault>" << std::endl;
58     ss << "</ServerSideEncryptionRule>" << std::endl;
59     return ss.str();
60 }
61 
62