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/PutBucketVersioningRequest.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
29PutBucketVersioningRequest::PutBucketVersioningRequest() :
30 m_bucketHasBeenSet(false),
31 m_contentMD5HasBeenSet(false),
32 m_mFAHasBeenSet(false),
33 m_versioningConfigurationHasBeenSet(false),
34 m_customizedAccessLogTagHasBeenSet(false)
35{
36}
37
38Aws::String PutBucketVersioningRequest::SerializePayload() const
39{
40 XmlDocument payloadDoc = XmlDocument::CreateWithRootNode("VersioningConfiguration");
41
42 XmlNode parentNode = payloadDoc.GetRootElement();
43 parentNode.SetAttributeValue("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
44
45 m_versioningConfiguration.AddToNode(parentNode);
46 if(parentNode.HasChildren())
47 {
48 return payloadDoc.ConvertToString();
49 }
50
51 return {};
52}
53
54void PutBucketVersioningRequest::AddQueryStringParameters(URI& uri) const
55{
56 Aws::StringStream ss;
57 if(!m_customizedAccessLogTag.empty())
58 {
59 // only accept customized LogTag which starts with "x-"
60 Aws::Map<Aws::String, Aws::String> collectedLogTags;
61 for(const auto& entry: m_customizedAccessLogTag)
62 {
63 if (!entry.first.empty() && !entry.second.empty() && entry.first.substr(0, 2) == "x-")
64 {
65 collectedLogTags.emplace(entry.first, entry.second);
66 }
67 }
68
69 if (!collectedLogTags.empty())
70 {
71 uri.AddQueryStringParameter(collectedLogTags);
72 }
73 }
74}
75
76Aws::Http::HeaderValueCollection PutBucketVersioningRequest::GetRequestSpecificHeaders() const
77{
78 Aws::Http::HeaderValueCollection headers;
79 Aws::StringStream ss;
80 if(m_contentMD5HasBeenSet)
81 {
82 ss << m_contentMD5;
83 headers.emplace("content-md5", ss.str());
84 ss.str("");
85 }
86
87 if(m_mFAHasBeenSet)
88 {
89 ss << m_mFA;
90 headers.emplace("x-amz-mfa", ss.str());
91 ss.str("");
92 }
93
94 return headers;
95}
96