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/PutBucketAclRequest.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
29PutBucketAclRequest::PutBucketAclRequest() :
30 m_aCL(BucketCannedACL::NOT_SET),
31 m_aCLHasBeenSet(false),
32 m_accessControlPolicyHasBeenSet(false),
33 m_bucketHasBeenSet(false),
34 m_contentMD5HasBeenSet(false),
35 m_grantFullControlHasBeenSet(false),
36 m_grantReadHasBeenSet(false),
37 m_grantReadACPHasBeenSet(false),
38 m_grantWriteHasBeenSet(false),
39 m_grantWriteACPHasBeenSet(false),
40 m_customizedAccessLogTagHasBeenSet(false)
41{
42}
43
44Aws::String PutBucketAclRequest::SerializePayload() const
45{
46 XmlDocument payloadDoc = XmlDocument::CreateWithRootNode("AccessControlPolicy");
47
48 XmlNode parentNode = payloadDoc.GetRootElement();
49 parentNode.SetAttributeValue("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
50
51 m_accessControlPolicy.AddToNode(parentNode);
52 if(parentNode.HasChildren())
53 {
54 return payloadDoc.ConvertToString();
55 }
56
57 return {};
58}
59
60void PutBucketAclRequest::AddQueryStringParameters(URI& uri) const
61{
62 Aws::StringStream ss;
63 if(!m_customizedAccessLogTag.empty())
64 {
65 // only accept customized LogTag which starts with "x-"
66 Aws::Map<Aws::String, Aws::String> collectedLogTags;
67 for(const auto& entry: m_customizedAccessLogTag)
68 {
69 if (!entry.first.empty() && !entry.second.empty() && entry.first.substr(0, 2) == "x-")
70 {
71 collectedLogTags.emplace(entry.first, entry.second);
72 }
73 }
74
75 if (!collectedLogTags.empty())
76 {
77 uri.AddQueryStringParameter(collectedLogTags);
78 }
79 }
80}
81
82Aws::Http::HeaderValueCollection PutBucketAclRequest::GetRequestSpecificHeaders() const
83{
84 Aws::Http::HeaderValueCollection headers;
85 Aws::StringStream ss;
86 if(m_aCLHasBeenSet)
87 {
88 headers.emplace("x-amz-acl", BucketCannedACLMapper::GetNameForBucketCannedACL(m_aCL));
89 }
90
91 if(m_contentMD5HasBeenSet)
92 {
93 ss << m_contentMD5;
94 headers.emplace("content-md5", ss.str());
95 ss.str("");
96 }
97
98 if(m_grantFullControlHasBeenSet)
99 {
100 ss << m_grantFullControl;
101 headers.emplace("x-amz-grant-full-control", ss.str());
102 ss.str("");
103 }
104
105 if(m_grantReadHasBeenSet)
106 {
107 ss << m_grantRead;
108 headers.emplace("x-amz-grant-read", ss.str());
109 ss.str("");
110 }
111
112 if(m_grantReadACPHasBeenSet)
113 {
114 ss << m_grantReadACP;
115 headers.emplace("x-amz-grant-read-acp", ss.str());
116 ss.str("");
117 }
118
119 if(m_grantWriteHasBeenSet)
120 {
121 ss << m_grantWrite;
122 headers.emplace("x-amz-grant-write", ss.str());
123 ss.str("");
124 }
125
126 if(m_grantWriteACPHasBeenSet)
127 {
128 ss << m_grantWriteACP;
129 headers.emplace("x-amz-grant-write-acp", ss.str());
130 ss.str("");
131 }
132
133 return headers;
134}
135