1/*
2* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. 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* A copy of the License is located at
7*
8* http://aws.amazon.com/apache2.0
9*
10* or in the "license" file accompanying this file. This file is distributed
11* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12* express or implied. See the License for the specific language governing
13* permissions and limitations under the License.
14*/
15
16#include <aws/s3/model/CreateBucketRequest.h>
17#include <aws/core/utils/xml/XmlSerializer.h>
18#include <aws/core/utils/memory/stl/AWSStringStream.h>
19#include <aws/core/http/URI.h>
20#include <aws/core/utils/memory/stl/AWSStringStream.h>
21
22#include <utility>
23
24using namespace Aws::S3::Model;
25using namespace Aws::Utils::Xml;
26using namespace Aws::Utils;
27using namespace Aws::Http;
28
29CreateBucketRequest::CreateBucketRequest() :
30 m_aCL(BucketCannedACL::NOT_SET),
31 m_aCLHasBeenSet(false),
32 m_bucketHasBeenSet(false),
33 m_createBucketConfigurationHasBeenSet(false),
34 m_grantFullControlHasBeenSet(false),
35 m_grantReadHasBeenSet(false),
36 m_grantReadACPHasBeenSet(false),
37 m_grantWriteHasBeenSet(false),
38 m_grantWriteACPHasBeenSet(false),
39 m_objectLockEnabledForBucket(false),
40 m_objectLockEnabledForBucketHasBeenSet(false),
41 m_customizedAccessLogTagHasBeenSet(false)
42{
43}
44
45Aws::String CreateBucketRequest::SerializePayload() const
46{
47 XmlDocument payloadDoc = XmlDocument::CreateWithRootNode("CreateBucketConfiguration");
48
49 XmlNode parentNode = payloadDoc.GetRootElement();
50 parentNode.SetAttributeValue("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
51
52 m_createBucketConfiguration.AddToNode(parentNode);
53 if(parentNode.HasChildren())
54 {
55 return payloadDoc.ConvertToString();
56 }
57
58 return {};
59}
60
61void CreateBucketRequest::AddQueryStringParameters(URI& uri) const
62{
63 Aws::StringStream ss;
64 if(!m_customizedAccessLogTag.empty())
65 {
66 // only accept customized LogTag which starts with "x-"
67 Aws::Map<Aws::String, Aws::String> collectedLogTags;
68 for(const auto& entry: m_customizedAccessLogTag)
69 {
70 if (!entry.first.empty() && !entry.second.empty() && entry.first.substr(0, 2) == "x-")
71 {
72 collectedLogTags.emplace(entry.first, entry.second);
73 }
74 }
75
76 if (!collectedLogTags.empty())
77 {
78 uri.AddQueryStringParameter(collectedLogTags);
79 }
80 }
81}
82
83Aws::Http::HeaderValueCollection CreateBucketRequest::GetRequestSpecificHeaders() const
84{
85 Aws::Http::HeaderValueCollection headers;
86 Aws::StringStream ss;
87 if(m_aCLHasBeenSet)
88 {
89 headers.emplace("x-amz-acl", BucketCannedACLMapper::GetNameForBucketCannedACL(m_aCL));
90 }
91
92 if(m_grantFullControlHasBeenSet)
93 {
94 ss << m_grantFullControl;
95 headers.emplace("x-amz-grant-full-control", ss.str());
96 ss.str("");
97 }
98
99 if(m_grantReadHasBeenSet)
100 {
101 ss << m_grantRead;
102 headers.emplace("x-amz-grant-read", ss.str());
103 ss.str("");
104 }
105
106 if(m_grantReadACPHasBeenSet)
107 {
108 ss << m_grantReadACP;
109 headers.emplace("x-amz-grant-read-acp", ss.str());
110 ss.str("");
111 }
112
113 if(m_grantWriteHasBeenSet)
114 {
115 ss << m_grantWrite;
116 headers.emplace("x-amz-grant-write", ss.str());
117 ss.str("");
118 }
119
120 if(m_grantWriteACPHasBeenSet)
121 {
122 ss << m_grantWriteACP;
123 headers.emplace("x-amz-grant-write-acp", ss.str());
124 ss.str("");
125 }
126
127 if(m_objectLockEnabledForBucketHasBeenSet)
128 {
129 ss << m_objectLockEnabledForBucket;
130 headers.emplace("x-amz-bucket-object-lock-enabled", ss.str());
131 ss.str("");
132 }
133
134 return headers;
135}
136