1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #include <aws/s3-crt/model/PutBucketOwnershipControlsRequest.h>
7 #include <aws/core/utils/xml/XmlSerializer.h>
8 #include <aws/core/utils/memory/stl/AWSStringStream.h>
9 #include <aws/core/http/URI.h>
10 #include <aws/core/utils/memory/stl/AWSStringStream.h>
11
12 #include <utility>
13
14 using namespace Aws::S3Crt::Model;
15 using namespace Aws::Utils::Xml;
16 using namespace Aws::Utils;
17 using namespace Aws::Http;
18
PutBucketOwnershipControlsRequest()19 PutBucketOwnershipControlsRequest::PutBucketOwnershipControlsRequest() :
20 m_bucketHasBeenSet(false),
21 m_contentMD5HasBeenSet(false),
22 m_expectedBucketOwnerHasBeenSet(false),
23 m_ownershipControlsHasBeenSet(false),
24 m_customizedAccessLogTagHasBeenSet(false)
25 {
26 }
27
SerializePayload() const28 Aws::String PutBucketOwnershipControlsRequest::SerializePayload() const
29 {
30 XmlDocument payloadDoc = XmlDocument::CreateWithRootNode("OwnershipControls");
31
32 XmlNode parentNode = payloadDoc.GetRootElement();
33 parentNode.SetAttributeValue("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
34
35 m_ownershipControls.AddToNode(parentNode);
36 if(parentNode.HasChildren())
37 {
38 return payloadDoc.ConvertToString();
39 }
40
41 return {};
42 }
43
AddQueryStringParameters(URI & uri) const44 void PutBucketOwnershipControlsRequest::AddQueryStringParameters(URI& uri) const
45 {
46 Aws::StringStream ss;
47 if(!m_customizedAccessLogTag.empty())
48 {
49 // only accept customized LogTag which starts with "x-"
50 Aws::Map<Aws::String, Aws::String> collectedLogTags;
51 for(const auto& entry: m_customizedAccessLogTag)
52 {
53 if (!entry.first.empty() && !entry.second.empty() && entry.first.substr(0, 2) == "x-")
54 {
55 collectedLogTags.emplace(entry.first, entry.second);
56 }
57 }
58
59 if (!collectedLogTags.empty())
60 {
61 uri.AddQueryStringParameter(collectedLogTags);
62 }
63 }
64 }
65
GetRequestSpecificHeaders() const66 Aws::Http::HeaderValueCollection PutBucketOwnershipControlsRequest::GetRequestSpecificHeaders() const
67 {
68 Aws::Http::HeaderValueCollection headers;
69 Aws::StringStream ss;
70 if(m_contentMD5HasBeenSet)
71 {
72 ss << m_contentMD5;
73 headers.emplace("content-md5", ss.str());
74 ss.str("");
75 }
76
77 if(m_expectedBucketOwnerHasBeenSet)
78 {
79 ss << m_expectedBucketOwner;
80 headers.emplace("x-amz-expected-bucket-owner", ss.str());
81 ss.str("");
82 }
83
84 return headers;
85 }
86