| 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/PutObjectAclRequest.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 |  | 
|---|
| 24 | using namespace Aws::S3::Model; | 
|---|
| 25 | using namespace Aws::Utils::Xml; | 
|---|
| 26 | using namespace Aws::Utils; | 
|---|
| 27 | using namespace Aws::Http; | 
|---|
| 28 |  | 
|---|
| 29 | PutObjectAclRequest::PutObjectAclRequest() : | 
|---|
| 30 | m_aCL(ObjectCannedACL::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_keyHasBeenSet(false), | 
|---|
| 41 | m_requestPayer(RequestPayer::NOT_SET), | 
|---|
| 42 | m_requestPayerHasBeenSet(false), | 
|---|
| 43 | m_versionIdHasBeenSet(false), | 
|---|
| 44 | m_customizedAccessLogTagHasBeenSet(false) | 
|---|
| 45 | { | 
|---|
| 46 | } | 
|---|
| 47 |  | 
|---|
| 48 | Aws::String PutObjectAclRequest::SerializePayload() const | 
|---|
| 49 | { | 
|---|
| 50 | XmlDocument payloadDoc = XmlDocument::CreateWithRootNode( "AccessControlPolicy"); | 
|---|
| 51 |  | 
|---|
| 52 | XmlNode parentNode = payloadDoc.GetRootElement(); | 
|---|
| 53 | parentNode.SetAttributeValue( "xmlns", "http://s3.amazonaws.com/doc/2006-03-01/"); | 
|---|
| 54 |  | 
|---|
| 55 | m_accessControlPolicy.AddToNode(parentNode); | 
|---|
| 56 | if(parentNode.HasChildren()) | 
|---|
| 57 | { | 
|---|
| 58 | return payloadDoc.ConvertToString(); | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 | return {}; | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | void PutObjectAclRequest::AddQueryStringParameters(URI& uri) const | 
|---|
| 65 | { | 
|---|
| 66 | Aws::StringStream ss; | 
|---|
| 67 | if(m_versionIdHasBeenSet) | 
|---|
| 68 | { | 
|---|
| 69 | ss << m_versionId; | 
|---|
| 70 | uri.AddQueryStringParameter( "versionId", ss.str()); | 
|---|
| 71 | ss.str( ""); | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | if(!m_customizedAccessLogTag.empty()) | 
|---|
| 75 | { | 
|---|
| 76 | // only accept customized LogTag which starts with "x-" | 
|---|
| 77 | Aws::Map<Aws::String, Aws::String> collectedLogTags; | 
|---|
| 78 | for(const auto& entry: m_customizedAccessLogTag) | 
|---|
| 79 | { | 
|---|
| 80 | if (!entry.first.empty() && !entry.second.empty() && entry.first.substr(0, 2) == "x-") | 
|---|
| 81 | { | 
|---|
| 82 | collectedLogTags.emplace(entry.first, entry.second); | 
|---|
| 83 | } | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | if (!collectedLogTags.empty()) | 
|---|
| 87 | { | 
|---|
| 88 | uri.AddQueryStringParameter(collectedLogTags); | 
|---|
| 89 | } | 
|---|
| 90 | } | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | Aws::Http::HeaderValueCollection PutObjectAclRequest::() const | 
|---|
| 94 | { | 
|---|
| 95 | Aws::Http::HeaderValueCollection ; | 
|---|
| 96 | Aws::StringStream ss; | 
|---|
| 97 | if(m_aCLHasBeenSet) | 
|---|
| 98 | { | 
|---|
| 99 | headers.emplace( "x-amz-acl", ObjectCannedACLMapper::GetNameForObjectCannedACL(m_aCL)); | 
|---|
| 100 | } | 
|---|
| 101 |  | 
|---|
| 102 | if(m_contentMD5HasBeenSet) | 
|---|
| 103 | { | 
|---|
| 104 | ss << m_contentMD5; | 
|---|
| 105 | headers.emplace( "content-md5",  ss.str()); | 
|---|
| 106 | ss.str( ""); | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | if(m_grantFullControlHasBeenSet) | 
|---|
| 110 | { | 
|---|
| 111 | ss << m_grantFullControl; | 
|---|
| 112 | headers.emplace( "x-amz-grant-full-control",  ss.str()); | 
|---|
| 113 | ss.str( ""); | 
|---|
| 114 | } | 
|---|
| 115 |  | 
|---|
| 116 | if(m_grantReadHasBeenSet) | 
|---|
| 117 | { | 
|---|
| 118 | ss << m_grantRead; | 
|---|
| 119 | headers.emplace( "x-amz-grant-read",  ss.str()); | 
|---|
| 120 | ss.str( ""); | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|
| 123 | if(m_grantReadACPHasBeenSet) | 
|---|
| 124 | { | 
|---|
| 125 | ss << m_grantReadACP; | 
|---|
| 126 | headers.emplace( "x-amz-grant-read-acp",  ss.str()); | 
|---|
| 127 | ss.str( ""); | 
|---|
| 128 | } | 
|---|
| 129 |  | 
|---|
| 130 | if(m_grantWriteHasBeenSet) | 
|---|
| 131 | { | 
|---|
| 132 | ss << m_grantWrite; | 
|---|
| 133 | headers.emplace( "x-amz-grant-write",  ss.str()); | 
|---|
| 134 | ss.str( ""); | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 | if(m_grantWriteACPHasBeenSet) | 
|---|
| 138 | { | 
|---|
| 139 | ss << m_grantWriteACP; | 
|---|
| 140 | headers.emplace( "x-amz-grant-write-acp",  ss.str()); | 
|---|
| 141 | ss.str( ""); | 
|---|
| 142 | } | 
|---|
| 143 |  | 
|---|
| 144 | if(m_requestPayerHasBeenSet) | 
|---|
| 145 | { | 
|---|
| 146 | headers.emplace( "x-amz-request-payer", RequestPayerMapper::GetNameForRequestPayer(m_requestPayer)); | 
|---|
| 147 | } | 
|---|
| 148 |  | 
|---|
| 149 | return headers; | 
|---|
| 150 | } | 
|---|
| 151 |  | 
|---|