Example #1
0
        public IRequest Marshall(InitiateMultipartUploadRequest initiateMultipartUploadRequest)
        {
            //IL_0006: Unknown result type (might be due to invalid IL or missing references)
            //IL_000c: Expected O, but got Unknown
            IRequest val = new DefaultRequest(initiateMultipartUploadRequest, "AmazonS3");

            val.set_HttpMethod("POST");
            if (initiateMultipartUploadRequest.IsSetCannedACL())
            {
                val.get_Headers().Add("x-amz-acl", S3Transforms.ToStringValue(ConstantClass.op_Implicit(initiateMultipartUploadRequest.CannedACL)));
            }
            HeadersCollection headers = initiateMultipartUploadRequest.Headers;

            foreach (string key in headers.Keys)
            {
                val.get_Headers().Add(key, headers[key]);
            }
            HeaderACLRequestMarshaller.Marshall(val, initiateMultipartUploadRequest);
            if (initiateMultipartUploadRequest.IsSetServerSideEncryptionMethod())
            {
                val.get_Headers().Add("x-amz-server-side-encryption", S3Transforms.ToStringValue(ConstantClass.op_Implicit(initiateMultipartUploadRequest.ServerSideEncryptionMethod)));
            }
            if (initiateMultipartUploadRequest.IsSetServerSideEncryptionCustomerMethod())
            {
                val.get_Headers().Add("x-amz-server-side-encryption-customer-algorithm", ConstantClass.op_Implicit(initiateMultipartUploadRequest.ServerSideEncryptionCustomerMethod));
            }
            if (initiateMultipartUploadRequest.IsSetServerSideEncryptionCustomerProvidedKey())
            {
                val.get_Headers().Add("x-amz-server-side-encryption-customer-key", initiateMultipartUploadRequest.ServerSideEncryptionCustomerProvidedKey);
                if (initiateMultipartUploadRequest.IsSetServerSideEncryptionCustomerProvidedKeyMD5())
                {
                    val.get_Headers().Add("x-amz-server-side-encryption-customer-key-MD5", initiateMultipartUploadRequest.ServerSideEncryptionCustomerProvidedKeyMD5);
                }
                else
                {
                    val.get_Headers().Add("x-amz-server-side-encryption-customer-key-MD5", AmazonS3Util.ComputeEncodedMD5FromEncodedString(initiateMultipartUploadRequest.ServerSideEncryptionCustomerProvidedKey));
                }
            }
            if (initiateMultipartUploadRequest.IsSetServerSideEncryptionKeyManagementServiceKeyId())
            {
                val.get_Headers().Add("x-amz-server-side-encryption-aws-kms-key-id", initiateMultipartUploadRequest.ServerSideEncryptionKeyManagementServiceKeyId);
            }
            if (initiateMultipartUploadRequest.IsSetStorageClass())
            {
                val.get_Headers().Add("x-amz-storage-class", S3Transforms.ToStringValue(ConstantClass.op_Implicit(initiateMultipartUploadRequest.StorageClass)));
            }
            if (initiateMultipartUploadRequest.IsSetWebsiteRedirectLocation())
            {
                val.get_Headers().Add("x-amz-website-redirect-location", S3Transforms.ToStringValue(initiateMultipartUploadRequest.WebsiteRedirectLocation));
            }
            if (initiateMultipartUploadRequest.IsSetRequestPayer())
            {
                val.get_Headers().Add(S3Constants.AmzHeaderRequestPayer, S3Transforms.ToStringValue(((object)initiateMultipartUploadRequest.RequestPayer).ToString()));
            }
            AmazonS3Util.SetMetadataHeaders(val, initiateMultipartUploadRequest.Metadata);
            val.set_ResourcePath(string.Format(CultureInfo.InvariantCulture, "/{0}/{1}", S3Transforms.ToStringValue(initiateMultipartUploadRequest.BucketName), S3Transforms.ToStringValue(initiateMultipartUploadRequest.Key)));
            val.AddSubResource("uploads");
            val.set_UseQueryString(true);
            return(val);
        }
Example #2
0
        public IRequest Marshall(InitiateMultipartUploadRequest initiateMultipartUploadRequest)
        {
            IRequest request = new DefaultRequest(initiateMultipartUploadRequest, "AmazonS3");

            request.HttpMethod = "POST";

            if (initiateMultipartUploadRequest.IsSetCannedACL())
            {
                request.Headers.Add("x-amz-acl", S3Transforms.ToStringValue(initiateMultipartUploadRequest.CannedACL));
            }

            var headers = initiateMultipartUploadRequest.Headers;

            foreach (var key in headers.Keys)
            {
                request.Headers.Add(key, headers[key]);
            }

            HeaderACLRequestMarshaller.Marshall(request, initiateMultipartUploadRequest);

            if (initiateMultipartUploadRequest.IsSetServerSideEncryptionMethod())
            {
                request.Headers.Add("x-amz-server-side-encryption", S3Transforms.ToStringValue(initiateMultipartUploadRequest.ServerSideEncryptionMethod));
            }

            if (initiateMultipartUploadRequest.IsSetStorageClass())
            {
                request.Headers.Add("x-amz-storage-class", S3Transforms.ToStringValue(initiateMultipartUploadRequest.StorageClass));
            }

            if (initiateMultipartUploadRequest.IsSetWebsiteRedirectLocation())
            {
                request.Headers.Add("x-amz-website-redirect-location", S3Transforms.ToStringValue(initiateMultipartUploadRequest.WebsiteRedirectLocation));
            }

            AmazonS3Util.SetMetadataHeaders(request, initiateMultipartUploadRequest.Metadata);

            var uriResourcePath = string.Format(CultureInfo.InvariantCulture, "/{0}/{1}",
                                                S3Transforms.ToStringValue(initiateMultipartUploadRequest.BucketName),
                                                S3Transforms.ToStringValue(initiateMultipartUploadRequest.Key));

            request.Parameters.Add("uploads", null);

            request.CanonicalResource = S3Transforms.GetCanonicalResource(uriResourcePath, request.Parameters);
            request.ResourcePath      = S3Transforms.FormatResourcePath(uriResourcePath, request.Parameters);
            request.UseQueryString    = true;

            return(request);
        }
Example #3
0
        /// <summary>
        /// Marshalls the parameters for a presigned url for a preferred signing protocol.
        /// </summary>
        /// <param name="getPreSignedUrlRequest"></param>
        /// <param name="accessKey"></param>
        /// <param name="token"></param>
        /// <param name="aws4Signing">
        /// True if AWS4 signing will be used; if the expiry period in the request exceeds the
        /// maximum allowed for AWS4 (one week), an ArgumentException is thrown.
        /// </param>
        /// <returns></returns>
        private static IRequest Marshall(GetPreSignedUrlRequest getPreSignedUrlRequest,
                                         string accessKey,
                                         string token,
                                         bool aws4Signing)
        {
            IRequest request = new DefaultRequest(getPreSignedUrlRequest, "AmazonS3");

            request.HttpMethod = getPreSignedUrlRequest.Verb.ToString();

            var headers = getPreSignedUrlRequest.Headers;

            foreach (var key in headers.Keys)
            {
                request.Headers[key] = headers[key];
            }

            AmazonS3Util.SetMetadataHeaders(request, getPreSignedUrlRequest.Metadata);

            if (!string.IsNullOrEmpty(token))
            {
                request.Headers[HeaderKeys.XAmzSecurityTokenHeader] = token;
            }

            if (getPreSignedUrlRequest.ServerSideEncryptionMethod != null && getPreSignedUrlRequest.ServerSideEncryptionMethod != ServerSideEncryptionMethod.None)
            {
                request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionHeader, S3Transforms.ToStringValue(getPreSignedUrlRequest.ServerSideEncryptionMethod));
            }
            if (getPreSignedUrlRequest.IsSetServerSideEncryptionCustomerMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzSSECustomerAlgorithmHeader, getPreSignedUrlRequest.ServerSideEncryptionCustomerMethod);
            }
            if (getPreSignedUrlRequest.IsSetServerSideEncryptionKeyManagementServiceKeyId())
            {
                request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader, getPreSignedUrlRequest.ServerSideEncryptionKeyManagementServiceKeyId);
            }

            var queryParameters = request.Parameters;

            var uriResourcePath = new StringBuilder("/");

            if (!string.IsNullOrEmpty(getPreSignedUrlRequest.BucketName))
            {
                uriResourcePath.Append(S3Transforms.ToStringValue(getPreSignedUrlRequest.BucketName));
            }
            if (!string.IsNullOrEmpty(getPreSignedUrlRequest.Key))
            {
                if (uriResourcePath.Length > 1)
                {
                    uriResourcePath.Append("/");
                }
                uriResourcePath.Append(S3Transforms.ToStringValue(getPreSignedUrlRequest.Key));
            }

            var expires = GetSecondsUntilExpiration(getPreSignedUrlRequest, aws4Signing);

            if (aws4Signing && expires > AWS4PreSignedUrlSigner.MaxAWS4PreSignedUrlExpiry)
            {
                var msg = string.Format(CultureInfo.InvariantCulture, "The maximum expiry period for a presigned url using AWS4 signing is {0} seconds",
                                        AWS4PreSignedUrlSigner.MaxAWS4PreSignedUrlExpiry);
                throw new ArgumentException(msg);
            }

            queryParameters.Add(aws4Signing ? "X-Amz-Expires" : "Expires", expires.ToString(CultureInfo.InvariantCulture));

            if (!string.IsNullOrEmpty(token))
            {
                queryParameters.Add("x-amz-security-token", token);
            }
            if (!aws4Signing)
            {
                queryParameters.Add("AWSAccessKeyId", accessKey);
            }
            if (getPreSignedUrlRequest.IsSetVersionId())
            {
                request.AddSubResource("versionId", S3Transforms.ToStringValue(getPreSignedUrlRequest.VersionId));
            }

            var responseHeaderOverrides = getPreSignedUrlRequest.ResponseHeaderOverrides;

            if (!string.IsNullOrEmpty(responseHeaderOverrides.CacheControl))
            {
                queryParameters.Add("response-cache-control", responseHeaderOverrides.CacheControl);
            }
            if (!string.IsNullOrEmpty(responseHeaderOverrides.ContentType))
            {
                queryParameters.Add("response-content-type", responseHeaderOverrides.ContentType);
            }
            if (!string.IsNullOrEmpty(responseHeaderOverrides.ContentLanguage))
            {
                queryParameters.Add("response-content-language", responseHeaderOverrides.ContentLanguage);
            }
            if (!string.IsNullOrEmpty(responseHeaderOverrides.Expires))
            {
                queryParameters.Add("response-expires", responseHeaderOverrides.Expires);
            }
            if (!string.IsNullOrEmpty(responseHeaderOverrides.ContentDisposition))
            {
                queryParameters.Add("response-content-disposition", responseHeaderOverrides.ContentDisposition);
            }
            if (!string.IsNullOrEmpty(responseHeaderOverrides.ContentEncoding))
            {
                queryParameters.Add("response-content-encoding", responseHeaderOverrides.ContentEncoding);
            }

            request.ResourcePath   = uriResourcePath.ToString();
            request.UseQueryString = true;

            return(request);
        }
        public IRequest Marshall(InitiateMultipartUploadRequest initiateMultipartUploadRequest)
        {
            IRequest request = new DefaultRequest(initiateMultipartUploadRequest, "AmazonS3");

            request.HttpMethod = "POST";

            if (initiateMultipartUploadRequest.IsSetCannedACL())
            {
                request.Headers.Add(HeaderKeys.XAmzAclHeader, S3Transforms.ToStringValue(initiateMultipartUploadRequest.CannedACL));
            }

            var headers = initiateMultipartUploadRequest.Headers;

            foreach (var key in headers.Keys)
            {
                request.Headers.Add(key, headers[key]);
            }

            HeaderACLRequestMarshaller.Marshall(request, initiateMultipartUploadRequest);

            if (initiateMultipartUploadRequest.IsSetServerSideEncryptionMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionHeader, S3Transforms.ToStringValue(initiateMultipartUploadRequest.ServerSideEncryptionMethod));
            }
            if (initiateMultipartUploadRequest.IsSetServerSideEncryptionCustomerMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzSSECustomerAlgorithmHeader, initiateMultipartUploadRequest.ServerSideEncryptionCustomerMethod);
            }
            if (initiateMultipartUploadRequest.IsSetServerSideEncryptionCustomerProvidedKey())
            {
                request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyHeader, initiateMultipartUploadRequest.ServerSideEncryptionCustomerProvidedKey);
                if (initiateMultipartUploadRequest.IsSetServerSideEncryptionCustomerProvidedKeyMD5())
                {
                    request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, initiateMultipartUploadRequest.ServerSideEncryptionCustomerProvidedKeyMD5);
                }
                else
                {
                    request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, AmazonS3Util.ComputeEncodedMD5FromEncodedString(initiateMultipartUploadRequest.ServerSideEncryptionCustomerProvidedKey));
                }
            }

            if (initiateMultipartUploadRequest.IsSetServerSideEncryptionKeyManagementServiceKeyId())
            {
                request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader, initiateMultipartUploadRequest.ServerSideEncryptionKeyManagementServiceKeyId);
            }

            if (initiateMultipartUploadRequest.IsSetServerSideEncryptionKeyManagementServiceEncryptionContext())
            {
                request.Headers.Add("x-amz-server-side-encryption-context", initiateMultipartUploadRequest.ServerSideEncryptionKeyManagementServiceEncryptionContext);
            }

            if (initiateMultipartUploadRequest.IsSetStorageClass())
            {
                request.Headers.Add(HeaderKeys.XAmzStorageClassHeader, S3Transforms.ToStringValue(initiateMultipartUploadRequest.StorageClass));
            }

            if (initiateMultipartUploadRequest.IsSetWebsiteRedirectLocation())
            {
                request.Headers.Add(HeaderKeys.XAmzWebsiteRedirectLocationHeader, S3Transforms.ToStringValue(initiateMultipartUploadRequest.WebsiteRedirectLocation));
            }
            if (initiateMultipartUploadRequest.IsSetRequestPayer())
            {
                request.Headers.Add(S3Constants.AmzHeaderRequestPayer, S3Transforms.ToStringValue(initiateMultipartUploadRequest.RequestPayer.ToString()));
            }

            if (initiateMultipartUploadRequest.IsSetObjectLockLegalHoldStatus())
            {
                request.Headers.Add("x-amz-object-lock-legal-hold", S3Transforms.ToStringValue(initiateMultipartUploadRequest.ObjectLockLegalHoldStatus));
            }
            if (initiateMultipartUploadRequest.IsSetObjectLockMode())
            {
                request.Headers.Add("x-amz-object-lock-mode", S3Transforms.ToStringValue(initiateMultipartUploadRequest.ObjectLockMode));
            }
            if (initiateMultipartUploadRequest.IsSetObjectLockRetainUntilDate())
            {
                request.Headers.Add("x-amz-object-lock-retain-until-date", S3Transforms.ToStringValue(initiateMultipartUploadRequest.ObjectLockRetainUntilDate, AWSSDKUtils.ISO8601DateFormat));
            }

            if (initiateMultipartUploadRequest.IsSetTagSet())
            {
                request.Headers.Add(S3Constants.AmzHeaderTagging, AmazonS3Util.TagSetToQueryString(initiateMultipartUploadRequest.TagSet));
            }

            AmazonS3Util.SetMetadataHeaders(request, initiateMultipartUploadRequest.Metadata);

            if (string.IsNullOrEmpty(initiateMultipartUploadRequest.BucketName))
            {
                throw new System.ArgumentException("BucketName is a required property and must be set before making this call.", "InitiateMultipartUploadRequest.BucketName");
            }
            if (string.IsNullOrEmpty(initiateMultipartUploadRequest.Key))
            {
                throw new System.ArgumentException("Key is a required property and must be set before making this call.", "InitiateMultipartUploadRequest.Key");
            }

            request.ResourcePath = string.Format(CultureInfo.InvariantCulture, "/{0}/{1}",
                                                 S3Transforms.ToStringValue(initiateMultipartUploadRequest.BucketName),
                                                 S3Transforms.ToStringValue(initiateMultipartUploadRequest.Key));

            request.AddSubResource("uploads");

            request.UseQueryString = true;

            return(request);
        }
        public IRequest Marshall(InitiateMultipartUploadRequest initiateMultipartUploadRequest)
        {
            IRequest request = new DefaultRequest(initiateMultipartUploadRequest, "AmazonS3");

            request.HttpMethod = "POST";

            if (initiateMultipartUploadRequest.IsSetCannedACL())
            {
                request.Headers.Add(HeaderKeys.XAmzAclHeader, S3Transforms.ToStringValue(initiateMultipartUploadRequest.CannedACL));
            }

            var headers = initiateMultipartUploadRequest.Headers;

            foreach (var key in headers.Keys)
            {
                request.Headers.Add(key, headers[key]);
            }

            HeaderACLRequestMarshaller.Marshall(request, initiateMultipartUploadRequest);

            if (initiateMultipartUploadRequest.IsSetServerSideEncryptionMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionHeader, S3Transforms.ToStringValue(initiateMultipartUploadRequest.ServerSideEncryptionMethod));
            }
            if (initiateMultipartUploadRequest.IsSetServerSideEncryptionCustomerMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzSSECustomerAlgorithmHeader, initiateMultipartUploadRequest.ServerSideEncryptionCustomerMethod);
            }
            if (initiateMultipartUploadRequest.IsSetServerSideEncryptionCustomerProvidedKey())
            {
                request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyHeader, initiateMultipartUploadRequest.ServerSideEncryptionCustomerProvidedKey);
                if (initiateMultipartUploadRequest.IsSetServerSideEncryptionCustomerProvidedKeyMD5())
                {
                    request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, initiateMultipartUploadRequest.ServerSideEncryptionCustomerProvidedKeyMD5);
                }
                else
                {
                    request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, AmazonS3Util.ComputeEncodedMD5FromEncodedString(initiateMultipartUploadRequest.ServerSideEncryptionCustomerProvidedKey));
                }
            }

            if (initiateMultipartUploadRequest.IsSetServerSideEncryptionKeyManagementServiceKeyId())
            {
                request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader, initiateMultipartUploadRequest.ServerSideEncryptionKeyManagementServiceKeyId);
            }

            if (initiateMultipartUploadRequest.IsSetStorageClass())
            {
                request.Headers.Add(HeaderKeys.XAmzStorageClassHeader, S3Transforms.ToStringValue(initiateMultipartUploadRequest.StorageClass));
            }

            if (initiateMultipartUploadRequest.IsSetWebsiteRedirectLocation())
            {
                request.Headers.Add(HeaderKeys.XAmzWebsiteRedirectLocationHeader, S3Transforms.ToStringValue(initiateMultipartUploadRequest.WebsiteRedirectLocation));
            }

            AmazonS3Util.SetMetadataHeaders(request, initiateMultipartUploadRequest.Metadata);

            request.ResourcePath = string.Format(CultureInfo.InvariantCulture, "/{0}/{1}",
                                                 S3Transforms.ToStringValue(initiateMultipartUploadRequest.BucketName),
                                                 S3Transforms.ToStringValue(initiateMultipartUploadRequest.Key));

            request.AddSubResource("uploads");

            request.UseQueryString = true;

            return(request);
        }
Example #6
0
        public IRequest Marshall(PutObjectRequest putObjectRequest)
        {
            IRequest request = new DefaultRequest(putObjectRequest, "AmazonS3");

            request.HttpMethod = "PUT";

            if (putObjectRequest.IsSetCannedACL())
            {
                request.Headers.Add(HeaderKeys.XAmzAclHeader, S3Transforms.ToStringValue(putObjectRequest.CannedACL));
            }

            var headers = putObjectRequest.Headers;

            foreach (var key in headers.Keys)
            {
                request.Headers[key] = headers[key];
            }

            if (putObjectRequest.IsSetMD5Digest())
            {
                request.Headers[HeaderKeys.ContentMD5Header] = putObjectRequest.MD5Digest;
            }

            HeaderACLRequestMarshaller.Marshall(request, putObjectRequest);

            if (putObjectRequest.IsSetServerSideEncryptionMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionHeader, S3Transforms.ToStringValue(putObjectRequest.ServerSideEncryptionMethod));
            }

            if (putObjectRequest.IsSetStorageClass())
            {
                request.Headers.Add(HeaderKeys.XAmzStorageClassHeader, S3Transforms.ToStringValue(putObjectRequest.StorageClass));
            }

            if (putObjectRequest.IsSetWebsiteRedirectLocation())
            {
                request.Headers.Add(HeaderKeys.XAmzWebsiteRedirectLocationHeader, S3Transforms.ToStringValue(putObjectRequest.WebsiteRedirectLocation));
            }

            if (putObjectRequest.IsSetServerSideEncryptionCustomerMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzSSECustomerAlgorithmHeader, putObjectRequest.ServerSideEncryptionCustomerMethod);
            }
            if (putObjectRequest.IsSetServerSideEncryptionCustomerProvidedKey())
            {
                request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyHeader, putObjectRequest.ServerSideEncryptionCustomerProvidedKey);
                if (putObjectRequest.IsSetServerSideEncryptionCustomerProvidedKeyMD5())
                {
                    request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, putObjectRequest.ServerSideEncryptionCustomerProvidedKeyMD5);
                }
                else
                {
                    request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, AmazonS3Util.ComputeEncodedMD5FromEncodedString(putObjectRequest.ServerSideEncryptionCustomerProvidedKey));
                }
            }

            if (putObjectRequest.IsSetServerSideEncryptionKeyManagementServiceKeyId())
            {
                request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader, putObjectRequest.ServerSideEncryptionKeyManagementServiceKeyId);
            }

            if (putObjectRequest.IsSetServerSideEncryptionKeyManagementServiceEncryptionContext())
            {
                request.Headers.Add("x-amz-server-side-encryption-context", putObjectRequest.ServerSideEncryptionKeyManagementServiceEncryptionContext);
            }

            if (putObjectRequest.IsSetObjectLockLegalHoldStatus())
            {
                request.Headers.Add("x-amz-object-lock-legal-hold", S3Transforms.ToStringValue(putObjectRequest.ObjectLockLegalHoldStatus));
            }

            if (putObjectRequest.IsSetObjectLockMode())
            {
                request.Headers.Add("x-amz-object-lock-mode", S3Transforms.ToStringValue(putObjectRequest.ObjectLockMode));
            }

            if (putObjectRequest.IsSetObjectLockRetainUntilDate())
            {
                request.Headers.Add("x-amz-object-lock-retain-until-date", S3Transforms.ToStringValue(putObjectRequest.ObjectLockRetainUntilDate, AWSSDKUtils.ISO8601DateFormat));
            }

            if (putObjectRequest.IsSetRequestPayer())
            {
                request.Headers.Add(S3Constants.AmzHeaderRequestPayer, S3Transforms.ToStringValue(putObjectRequest.RequestPayer.ToString()));
            }

            if (putObjectRequest.IsSetTagSet())
            {
                request.Headers.Add(S3Constants.AmzHeaderTagging, AmazonS3Util.TagSetToQueryString(putObjectRequest.TagSet));
            }

            if (putObjectRequest.IsSetExpectedBucketOwner())
            {
                request.Headers.Add(S3Constants.AmzHeaderExpectedBucketOwner, S3Transforms.ToStringValue(putObjectRequest.ExpectedBucketOwner));
            }

            if (putObjectRequest.IsSetBucketKeyEnabled())
            {
                request.Headers.Add(S3Constants.AmzHeaderBucketKeyEnabled, S3Transforms.ToStringValue(putObjectRequest.BucketKeyEnabled));
            }

            AmazonS3Util.SetMetadataHeaders(request, putObjectRequest.Metadata);

            if (string.IsNullOrEmpty(putObjectRequest.BucketName))
            {
                throw new System.ArgumentException("BucketName is a required property and must be set before making this call.", "PutObjectRequest.BucketName");
            }
            if (string.IsNullOrEmpty(putObjectRequest.Key))
            {
                throw new System.ArgumentException("Key is a required property and must be set before making this call.", "PutObjectRequest.Key");
            }

            request.ResourcePath = string.Format(CultureInfo.InvariantCulture, "/{0}/{1}",
                                                 S3Transforms.ToStringValue(putObjectRequest.BucketName),
                                                 S3Transforms.ToStringValue(putObjectRequest.Key));


            if (putObjectRequest.InputStream != null)
            {
                // Wrap the stream in a stream that has a length
                var streamWithLength = GetStreamWithLength(putObjectRequest.InputStream, putObjectRequest.Headers.ContentLength);
                if (streamWithLength.Length > 0 && !(putObjectRequest.DisablePayloadSigning ?? false))
                {
                    request.UseChunkEncoding = putObjectRequest.UseChunkEncoding;
                }
                var length = streamWithLength.Length - streamWithLength.Position;
                if (!request.Headers.ContainsKey(HeaderKeys.ContentLengthHeader))
                {
                    request.Headers.Add(HeaderKeys.ContentLengthHeader, length.ToString(CultureInfo.InvariantCulture));
                }

                request.DisablePayloadSigning = putObjectRequest.DisablePayloadSigning;

                if (!(putObjectRequest.DisableMD5Stream ?? AWSConfigsS3.DisableMD5Stream))
                {
                    // Wrap input stream in MD5Stream
                    var hashStream = new MD5Stream(streamWithLength, null, length);
                    putObjectRequest.InputStream = hashStream;
                }
                else
                {
                    putObjectRequest.InputStream = streamWithLength;
                }
            }

            request.ContentStream = putObjectRequest.InputStream;
            if (!request.Headers.ContainsKey(HeaderKeys.ContentTypeHeader))
            {
                request.Headers.Add(HeaderKeys.ContentTypeHeader, "text/plain");
            }

            return(request);
        }
        public IRequest Marshall(CopyObjectRequest copyObjectRequest)
        {
            var sourceKey      = AmazonS3Util.RemoveLeadingSlash(copyObjectRequest.SourceKey);
            var destinationKey = AmazonS3Util.RemoveLeadingSlash(copyObjectRequest.DestinationKey);

            IRequest request = new DefaultRequest(copyObjectRequest, "AmazonS3");

            request.HttpMethod = "PUT";

            if (copyObjectRequest.IsSetCannedACL())
            {
                request.Headers.Add(HeaderKeys.XAmzAclHeader, S3Transforms.ToStringValue(copyObjectRequest.CannedACL));
            }

            var headers = copyObjectRequest.Headers;

            foreach (var key in headers.Keys)
            {
                request.Headers[key] = headers[key];
            }

            HeaderACLRequestMarshaller.Marshall(request, copyObjectRequest);

            if (copyObjectRequest.IsSetSourceBucket())
            {
                request.Headers.Add(HeaderKeys.XAmzCopySourceHeader, ConstructCopySourceHeaderValue(copyObjectRequest.SourceBucket, sourceKey, copyObjectRequest.SourceVersionId));
            }

            if (copyObjectRequest.IsSetETagToMatch())
            {
                request.Headers.Add(HeaderKeys.XAmzCopySourceIfMatchHeader, S3Transforms.ToStringValue(copyObjectRequest.ETagToMatch));
            }

            if (copyObjectRequest.IsSetModifiedSinceDateUtc())
            {
                request.Headers.Add(HeaderKeys.XAmzCopySourceIfModifiedSinceHeader, S3Transforms.ToStringValue(copyObjectRequest.ModifiedSinceDateUtc));
            }

            if (copyObjectRequest.IsSetETagToNotMatch())
            {
                request.Headers.Add(HeaderKeys.XAmzCopySourceIfNoneMatchHeader, S3Transforms.ToStringValue(copyObjectRequest.ETagToNotMatch));
            }

            if (copyObjectRequest.IsSetUnmodifiedSinceDateUtc())
            {
                request.Headers.Add(HeaderKeys.XAmzCopySourceIfUnmodifiedSinceHeader, S3Transforms.ToStringValue(copyObjectRequest.UnmodifiedSinceDateUtc));
            }

            if (copyObjectRequest.IsSetTagSet())
            {
                request.Headers.Add(S3Constants.AmzHeaderTagging, AmazonS3Util.TagSetToQueryString(copyObjectRequest.TagSet));
                request.Headers.Add(S3Constants.AmzHeaderTaggingDirective, TaggingDirective.REPLACE.Value);
            }
            else
            {
                request.Headers.Add(S3Constants.AmzHeaderTaggingDirective, TaggingDirective.COPY.Value);
            }

            request.Headers.Add(HeaderKeys.XAmzMetadataDirectiveHeader, S3Transforms.ToStringValue(copyObjectRequest.MetadataDirective.ToString()));

            if (copyObjectRequest.IsSetObjectLockLegalHoldStatus())
            {
                request.Headers.Add("x-amz-object-lock-legal-hold", S3Transforms.ToStringValue(copyObjectRequest.ObjectLockLegalHoldStatus));
            }
            if (copyObjectRequest.IsSetObjectLockMode())
            {
                request.Headers.Add("x-amz-object-lock-mode", S3Transforms.ToStringValue(copyObjectRequest.ObjectLockMode));
            }
            if (copyObjectRequest.IsSetObjectLockRetainUntilDate())
            {
                request.Headers.Add("x-amz-object-lock-retain-until-date", S3Transforms.ToStringValue(copyObjectRequest.ObjectLockRetainUntilDate, AWSSDKUtils.ISO8601DateFormat));
            }

            if (copyObjectRequest.IsSetServerSideEncryptionMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionHeader, S3Transforms.ToStringValue(copyObjectRequest.ServerSideEncryptionMethod));
            }
            if (copyObjectRequest.IsSetServerSideEncryptionCustomerMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzSSECustomerAlgorithmHeader, copyObjectRequest.ServerSideEncryptionCustomerMethod);
            }
            if (copyObjectRequest.IsSetServerSideEncryptionCustomerProvidedKey())
            {
                request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyHeader, copyObjectRequest.ServerSideEncryptionCustomerProvidedKey);
                if (copyObjectRequest.IsSetServerSideEncryptionCustomerProvidedKeyMD5())
                {
                    request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, copyObjectRequest.ServerSideEncryptionCustomerProvidedKeyMD5);
                }
                else
                {
                    request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, AmazonS3Util.ComputeEncodedMD5FromEncodedString(copyObjectRequest.ServerSideEncryptionCustomerProvidedKey));
                }
            }
            if (copyObjectRequest.IsSetCopySourceServerSideEncryptionCustomerMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerAlgorithmHeader, copyObjectRequest.CopySourceServerSideEncryptionCustomerMethod);
            }
            if (copyObjectRequest.IsSetCopySourceServerSideEncryptionCustomerProvidedKey())
            {
                request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerKeyHeader, copyObjectRequest.CopySourceServerSideEncryptionCustomerProvidedKey);
                if (copyObjectRequest.IsSetCopySourceServerSideEncryptionCustomerProvidedKeyMD5())
                {
                    request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerKeyMD5Header, copyObjectRequest.CopySourceServerSideEncryptionCustomerProvidedKeyMD5);
                }
                else
                {
                    request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerKeyMD5Header, AmazonS3Util.ComputeEncodedMD5FromEncodedString(copyObjectRequest.CopySourceServerSideEncryptionCustomerProvidedKey));
                }
            }
            if (copyObjectRequest.IsSetServerSideEncryptionKeyManagementServiceKeyId())
            {
                request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader, copyObjectRequest.ServerSideEncryptionKeyManagementServiceKeyId);
            }

            if (copyObjectRequest.IsSetServerSideEncryptionKeyManagementServiceEncryptionContext())
            {
                request.Headers.Add("x-amz-server-side-encryption-context", copyObjectRequest.ServerSideEncryptionKeyManagementServiceEncryptionContext);
            }

            if (copyObjectRequest.IsSetStorageClass())
            {
                request.Headers.Add(HeaderKeys.XAmzStorageClassHeader, S3Transforms.ToStringValue(copyObjectRequest.StorageClass));
            }

            if (copyObjectRequest.IsSetWebsiteRedirectLocation())
            {
                request.Headers.Add(HeaderKeys.XAmzWebsiteRedirectLocationHeader, S3Transforms.ToStringValue(copyObjectRequest.WebsiteRedirectLocation));
            }

            if (copyObjectRequest.IsSetRequestPayer())
            {
                request.Headers.Add(S3Constants.AmzHeaderRequestPayer, S3Transforms.ToStringValue(copyObjectRequest.RequestPayer.ToString()));
            }

            if (copyObjectRequest.IsSetExpectedBucketOwner())
            {
                request.Headers.Add(S3Constants.AmzHeaderExpectedBucketOwner, S3Transforms.ToStringValue(copyObjectRequest.ExpectedBucketOwner));
            }

            if (copyObjectRequest.IsSetExpectedSourceBucketOwner())
            {
                request.Headers.Add(S3Constants.AmzHeaderExpectedSourceBucketOwner, S3Transforms.ToStringValue(copyObjectRequest.ExpectedSourceBucketOwner));
            }

            if (copyObjectRequest.IsSetBucketKeyEnabled())
            {
                request.Headers.Add(S3Constants.AmzHeaderBucketKeyEnabled, S3Transforms.ToStringValue(copyObjectRequest.BucketKeyEnabled));
            }


            AmazonS3Util.SetMetadataHeaders(request, copyObjectRequest.Metadata);

            if (string.IsNullOrEmpty(copyObjectRequest.DestinationBucket))
            {
                throw new System.ArgumentException("DestinationBucket is a required property and must be set before making this call.", "CopyObjectRequest.DestinationBucket");
            }
            if (string.IsNullOrEmpty(destinationKey))
            {
                throw new System.ArgumentException("DestinationKey is a required property and must be set before making this call.", "CopyObjectRequest.DestinationKey");
            }


            request.MarshallerVersion = 2;
            request.ResourcePath      = string.Format(CultureInfo.InvariantCulture, "/{0}/{1}",
                                                      S3Transforms.ToStringValue(copyObjectRequest.DestinationBucket),
                                                      S3Transforms.ToStringValue(destinationKey));


            request.UseQueryString = true;

            return(request);
        }
        public IRequest Marshall(CopyObjectRequest copyObjectRequest)
        {
            IRequest request = new DefaultRequest(copyObjectRequest, "AmazonS3");

            request.HttpMethod = "PUT";

            if (copyObjectRequest.IsSetCannedACL())
            {
                request.Headers.Add(HeaderKeys.XAmzAclHeader, S3Transforms.ToStringValue(copyObjectRequest.CannedACL));
            }

            var headers = copyObjectRequest.Headers;

            foreach (var key in headers.Keys)
            {
                request.Headers[key] = headers[key];
            }

            HeaderACLRequestMarshaller.Marshall(request, copyObjectRequest);

            if (copyObjectRequest.IsSetSourceBucket())
            {
                request.Headers.Add(HeaderKeys.XAmzCopySourceHeader, ConstructCopySourceHeaderValue(copyObjectRequest.SourceBucket, copyObjectRequest.SourceKey, copyObjectRequest.SourceVersionId));
            }

            if (copyObjectRequest.IsSetETagToMatch())
            {
                request.Headers.Add(HeaderKeys.XAmzCopySourceIfMatchHeader, S3Transforms.ToStringValue(copyObjectRequest.ETagToMatch));
            }

            if (copyObjectRequest.IsSetModifiedSinceDate())
            {
                request.Headers.Add(HeaderKeys.XAmzCopySourceIfModifiedSinceHeader, S3Transforms.ToStringValue(copyObjectRequest.ModifiedSinceDate));
            }

            if (copyObjectRequest.IsSetETagToNotMatch())
            {
                request.Headers.Add(HeaderKeys.XAmzCopySourceIfNoneMatchHeader, S3Transforms.ToStringValue(copyObjectRequest.ETagToNotMatch));
            }

            if (copyObjectRequest.IsSetUnmodifiedSinceDate())
            {
                request.Headers.Add(HeaderKeys.XAmzCopySourceIfUnmodifiedSinceHeader, S3Transforms.ToStringValue(copyObjectRequest.UnmodifiedSinceDate));
            }

            request.Headers.Add(HeaderKeys.XAmzMetadataDirectiveHeader, S3Transforms.ToStringValue(copyObjectRequest.MetadataDirective.ToString()));

            if (copyObjectRequest.IsSetServerSideEncryptionMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionHeader, S3Transforms.ToStringValue(copyObjectRequest.ServerSideEncryptionMethod));
            }
            if (copyObjectRequest.IsSetServerSideEncryptionCustomerMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzSSECustomerAlgorithmHeader, copyObjectRequest.ServerSideEncryptionCustomerMethod);
            }
            if (copyObjectRequest.IsSetServerSideEncryptionCustomerProvidedKey())
            {
                request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyHeader, copyObjectRequest.ServerSideEncryptionCustomerProvidedKey);
                if (copyObjectRequest.IsSetServerSideEncryptionCustomerProvidedKeyMD5())
                {
                    request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, copyObjectRequest.ServerSideEncryptionCustomerProvidedKeyMD5);
                }
                else
                {
                    request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, AmazonS3Util.ComputeEncodedMD5FromEncodedString(copyObjectRequest.ServerSideEncryptionCustomerProvidedKey));
                }
            }
            if (copyObjectRequest.IsSetCopySourceServerSideEncryptionCustomerMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerAlgorithmHeader, copyObjectRequest.CopySourceServerSideEncryptionCustomerMethod);
            }
            if (copyObjectRequest.IsSetCopySourceServerSideEncryptionCustomerProvidedKey())
            {
                request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerKeyHeader, copyObjectRequest.CopySourceServerSideEncryptionCustomerProvidedKey);
                if (copyObjectRequest.IsSetCopySourceServerSideEncryptionCustomerProvidedKeyMD5())
                {
                    request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerKeyMD5Header, copyObjectRequest.CopySourceServerSideEncryptionCustomerProvidedKeyMD5);
                }
                else
                {
                    request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerKeyMD5Header, AmazonS3Util.ComputeEncodedMD5FromEncodedString(copyObjectRequest.CopySourceServerSideEncryptionCustomerProvidedKey));
                }
            }
            if (copyObjectRequest.IsSetServerSideEncryptionKeyManagementServiceKeyId())
            {
                request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader, copyObjectRequest.ServerSideEncryptionKeyManagementServiceKeyId);
            }

            if (copyObjectRequest.IsSetStorageClass())
            {
                request.Headers.Add(HeaderKeys.XAmzStorageClassHeader, S3Transforms.ToStringValue(copyObjectRequest.StorageClass));
            }

            if (copyObjectRequest.IsSetWebsiteRedirectLocation())
            {
                request.Headers.Add(HeaderKeys.XAmzWebsiteRedirectLocationHeader, S3Transforms.ToStringValue(copyObjectRequest.WebsiteRedirectLocation));
            }

            AmazonS3Util.SetMetadataHeaders(request, copyObjectRequest.Metadata);

            var destinationKey = copyObjectRequest.DestinationKey.StartsWith("/", StringComparison.Ordinal)
                                    ? copyObjectRequest.DestinationKey.Substring(1)
                                    : copyObjectRequest.DestinationKey;

            request.ResourcePath = string.Format(CultureInfo.InvariantCulture, "/{0}/{1}",
                                                 S3Transforms.ToStringValue(copyObjectRequest.DestinationBucket),
                                                 S3Transforms.ToStringValue(destinationKey));


            request.UseQueryString = true;

            return(request);
        }
Example #9
0
        /// <summary>
        /// Marshalls the parameters for a presigned url for a preferred signing protocol.
        /// </summary>
        /// <param name="config">service client configuration</param>
        /// <param name="getPreSignedUrlRequest"></param>
        /// <param name="accessKey"></param>
        /// <param name="token"></param>
        /// <param name="signatureVersion">Signature version to use.
        /// If AWS4 signing will be used and if the expiry period in the request exceeds the
        /// maximum allowed for AWS4 (one week), an ArgumentException is thrown.
        /// </param>
        /// <returns>Internal request</returns>
        private static IRequest Marshall(IClientConfig config,
                                         GetPreSignedUrlRequest getPreSignedUrlRequest,
                                         string accessKey,
                                         string token,
                                         SignatureVersion signatureVersion)
        {
            IRequest request = new DefaultRequest(getPreSignedUrlRequest, "AmazonS3");

            request.HttpMethod = getPreSignedUrlRequest.Verb.ToString();

            var headers = getPreSignedUrlRequest.Headers;

            foreach (var key in headers.Keys)
            {
                request.Headers[key] = headers[key];
            }

            AmazonS3Util.SetMetadataHeaders(request, getPreSignedUrlRequest.Metadata);

            if (getPreSignedUrlRequest.ServerSideEncryptionMethod != null && getPreSignedUrlRequest.ServerSideEncryptionMethod != ServerSideEncryptionMethod.None)
            {
                request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionHeader, S3Transforms.ToStringValue(getPreSignedUrlRequest.ServerSideEncryptionMethod));
            }
            if (getPreSignedUrlRequest.IsSetServerSideEncryptionCustomerMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzSSECustomerAlgorithmHeader, getPreSignedUrlRequest.ServerSideEncryptionCustomerMethod);
            }
            if (getPreSignedUrlRequest.IsSetServerSideEncryptionKeyManagementServiceKeyId())
            {
                request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader, getPreSignedUrlRequest.ServerSideEncryptionKeyManagementServiceKeyId);
            }

            if (getPreSignedUrlRequest.IsSetRequestPayer() && getPreSignedUrlRequest.RequestPayer == RequestPayer.Requester)
            {
                request.Parameters.Add("x-amz-request-payer", RequestPayer.Requester.Value);
            }

            var queryParameters = request.Parameters;

            var uriResourcePath = new StringBuilder("/");

            if (!string.IsNullOrEmpty(getPreSignedUrlRequest.BucketName))
            {
                uriResourcePath.Append(S3Transforms.ToStringValue(getPreSignedUrlRequest.BucketName));
            }
            if (!string.IsNullOrEmpty(getPreSignedUrlRequest.Key))
            {
                if (uriResourcePath.Length > 1)
                {
                    uriResourcePath.Append("/");
                }
                uriResourcePath.Append(S3Transforms.ToStringValue(getPreSignedUrlRequest.Key));
            }

            var expires = GetSecondsUntilExpiration(config, getPreSignedUrlRequest, signatureVersion);

            if ((signatureVersion == SignatureVersion.SigV4 || signatureVersion == SignatureVersion.SigV4a) &&
                expires > AWS4PreSignedUrlSigner.MaxAWS4PreSignedUrlExpiry)
            {
                var msg = string.Format(CultureInfo.InvariantCulture, "The maximum expiry period for a presigned url using AWS4 signing is {0} seconds",
                                        AWS4PreSignedUrlSigner.MaxAWS4PreSignedUrlExpiry);
                throw new ArgumentException(msg);
            }

            if (signatureVersion == SignatureVersion.SigV2)
            {
                queryParameters.Add("Expires", expires.ToString(CultureInfo.InvariantCulture));
                queryParameters.Add("AWSAccessKeyId", accessKey);
                if (!string.IsNullOrEmpty(token))
                {
                    queryParameters.Add("x-amz-security-token", token);
                }
            }
            else // SigV4 or SigV4a
            {
                queryParameters.Add(HeaderKeys.XAmzExpires, expires.ToString(CultureInfo.InvariantCulture));
                if (!string.IsNullOrEmpty(token))
                {
                    queryParameters.Add("X-Amz-Security-Token", token);
                }
            }

            if (getPreSignedUrlRequest.IsSetVersionId())
            {
                request.AddSubResource("versionId", S3Transforms.ToStringValue(getPreSignedUrlRequest.VersionId));
            }
            if (getPreSignedUrlRequest.IsSetUploadId())
            {
                request.AddSubResource("uploadId", S3Transforms.ToStringValue(getPreSignedUrlRequest.UploadId));
            }
            if (getPreSignedUrlRequest.IsSetPartNumber())
            {
                request.AddSubResource("partNumber", S3Transforms.ToStringValue(getPreSignedUrlRequest.PartNumber));
            }

            var responseHeaderOverrides = getPreSignedUrlRequest.ResponseHeaderOverrides;

            if (!string.IsNullOrEmpty(responseHeaderOverrides.CacheControl))
            {
                queryParameters.Add("response-cache-control", responseHeaderOverrides.CacheControl);
            }
            if (!string.IsNullOrEmpty(responseHeaderOverrides.ContentType))
            {
                queryParameters.Add("response-content-type", responseHeaderOverrides.ContentType);
            }
            if (!string.IsNullOrEmpty(responseHeaderOverrides.ContentLanguage))
            {
                queryParameters.Add("response-content-language", responseHeaderOverrides.ContentLanguage);
            }
            if (!string.IsNullOrEmpty(responseHeaderOverrides.Expires))
            {
                queryParameters.Add("response-expires", responseHeaderOverrides.Expires);
            }
            if (!string.IsNullOrEmpty(responseHeaderOverrides.ContentDisposition))
            {
                queryParameters.Add("response-content-disposition", responseHeaderOverrides.ContentDisposition);
            }
            if (!string.IsNullOrEmpty(responseHeaderOverrides.ContentEncoding))
            {
                queryParameters.Add("response-content-encoding", responseHeaderOverrides.ContentEncoding);
            }

            // Add custom parameters to be included and signed
            foreach (string k in getPreSignedUrlRequest.Parameters.Keys)
            {
                queryParameters.Add(k, getPreSignedUrlRequest.Parameters[k]);
            }

            request.ResourcePath   = uriResourcePath.ToString();
            request.UseQueryString = true;

            return(request);
        }
Example #10
0
        public IRequest Marshall(PutObjectRequest putObjectRequest)
        {
            IRequest request = new DefaultRequest(putObjectRequest, "AmazonS3");

            request.HttpMethod = "PUT";

            if (putObjectRequest.IsSetCannedACL())
            {
                request.Headers.Add(HeaderKeys.XAmzAclHeader, S3Transforms.ToStringValue(putObjectRequest.CannedACL));
            }

            var headers = putObjectRequest.Headers;

            foreach (var key in headers.Keys)
            {
                request.Headers[key] = headers[key];
            }

            if (putObjectRequest.IsSetMD5Digest())
            {
                request.Headers[HeaderKeys.ContentMD5Header] = putObjectRequest.MD5Digest;
            }

            HeaderACLRequestMarshaller.Marshall(request, putObjectRequest);

            if (putObjectRequest.IsSetServerSideEncryptionMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionHeader, S3Transforms.ToStringValue(putObjectRequest.ServerSideEncryptionMethod));
            }

            if (putObjectRequest.IsSetStorageClass())
            {
                request.Headers.Add(HeaderKeys.XAmzStorageClassHeader, S3Transforms.ToStringValue(putObjectRequest.StorageClass));
            }

            if (putObjectRequest.IsSetWebsiteRedirectLocation())
            {
                request.Headers.Add(HeaderKeys.XAmzWebsiteRedirectLocationHeader, S3Transforms.ToStringValue(putObjectRequest.WebsiteRedirectLocation));
            }

            if (putObjectRequest.IsSetServerSideEncryptionCustomerMethod())
            {
                request.Headers.Add(HeaderKeys.XAmzSSECustomerAlgorithmHeader, putObjectRequest.ServerSideEncryptionCustomerMethod);
            }
            if (putObjectRequest.IsSetServerSideEncryptionCustomerProvidedKey())
            {
                request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyHeader, putObjectRequest.ServerSideEncryptionCustomerProvidedKey);
                if (putObjectRequest.IsSetServerSideEncryptionCustomerProvidedKeyMD5())
                {
                    request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, putObjectRequest.ServerSideEncryptionCustomerProvidedKeyMD5);
                }
                else
                {
                    request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, AmazonS3Util.ComputeEncodedMD5FromEncodedString(putObjectRequest.ServerSideEncryptionCustomerProvidedKey));
                }
            }

            AmazonS3Util.SetMetadataHeaders(request, putObjectRequest.Metadata);

            request.ResourcePath = string.Format(CultureInfo.InvariantCulture, "/{0}/{1}",
                                                 S3Transforms.ToStringValue(putObjectRequest.BucketName),
                                                 S3Transforms.ToStringValue(putObjectRequest.Key));


            if (putObjectRequest.InputStream != null)
            {
                // Wrap the stream in a stream that has a length
                var streamWithLength = GetStreamWithLength(putObjectRequest.InputStream, putObjectRequest.Headers.ContentLength);
                if (streamWithLength.Length > 0)
                {
                    request.UseChunkEncoding = true;
                }
                var length = streamWithLength.Length - streamWithLength.Position;
                if (!request.Headers.ContainsKey(HeaderKeys.ContentLengthHeader))
                {
                    request.Headers.Add(HeaderKeys.ContentLengthHeader, length.ToString(CultureInfo.InvariantCulture));
                }

                // Wrap input stream in MD5Stream
                var hashStream = new MD5Stream(streamWithLength, null, length);
                putObjectRequest.InputStream = hashStream;
            }

            request.ContentStream = putObjectRequest.InputStream;
            if (!request.Headers.ContainsKey(HeaderKeys.ContentTypeHeader))
            {
                request.Headers.Add(HeaderKeys.ContentTypeHeader, "text/plain");
            }

            return(request);
        }
Example #11
0
        public IRequest Marshall(WriteGetObjectResponseRequest writeGetObjectResponseRequest)
        {
            IRequest request = new DefaultRequest(writeGetObjectResponseRequest, "AmazonS3");

            request.HttpMethod = "POST";

            if (!writeGetObjectResponseRequest.IsSetRequestRoute())
            {
                throw new System.ArgumentException("RequestRoute is a required property and must be set before making this call.", "WriteGetObjectResponseRequest.RequestRoute");
            }
            if (!writeGetObjectResponseRequest.IsSetRequestToken())
            {
                throw new System.ArgumentException("RequestToken is a required property and must be set before making this call.", "WriteGetObjectResponseRequest.RequestToken");
            }

            if (writeGetObjectResponseRequest.IsSetRequestRoute())
            {
                request.Headers["x-amz-request-route"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.RequestRoute);
            }

            if (writeGetObjectResponseRequest.IsSetRequestToken())
            {
                request.Headers["x-amz-request-token"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.RequestToken);
            }

            if (writeGetObjectResponseRequest.IsSetStatusCode())
            {
                request.Headers["x-amz-fwd-status"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.StatusCode.Value);
            }

            if (writeGetObjectResponseRequest.IsSetErrorCode())
            {
                request.Headers["x-amz-fwd-error-code"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ErrorCode);
            }

            if (writeGetObjectResponseRequest.IsSetErrorMessage())
            {
                request.Headers["x-amz-fwd-error-message"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ErrorMessage);
            }

            if (writeGetObjectResponseRequest.IsSetAcceptRanges())
            {
                request.Headers["x-amz-fwd-header-accept-ranges"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.AcceptRanges);
            }

            if (writeGetObjectResponseRequest.IsSetCacheControl())
            {
                request.Headers["x-amz-fwd-header-Cache-Control"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.CacheControl);
            }

            if (writeGetObjectResponseRequest.IsSetChecksumCRC32())
            {
                request.Headers["x-amz-fwd-header-x-amz-checksum-crc32"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ChecksumCRC32);
            }

            if (writeGetObjectResponseRequest.IsSetChecksumCRC32C())
            {
                request.Headers["x-amz-fwd-header-x-amz-checksum-crc32c"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ChecksumCRC32C);
            }

            if (writeGetObjectResponseRequest.IsSetChecksumSHA1())
            {
                request.Headers["x-amz-fwd-header-x-amz-checksum-sha1"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ChecksumSHA1);
            }

            if (writeGetObjectResponseRequest.IsSetChecksumSHA256())
            {
                request.Headers["x-amz-fwd-header-x-amz-checksum-sha256"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ChecksumSHA256);
            }

            if (writeGetObjectResponseRequest.IsSetContentDisposition())
            {
                request.Headers["x-amz-fwd-header-Content-Disposition"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ContentDisposition);
            }

            if (writeGetObjectResponseRequest.IsSetContentEncoding())
            {
                request.Headers["x-amz-fwd-header-Content-Encoding"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ContentEncoding);
            }

            if (writeGetObjectResponseRequest.IsSetContentLanguage())
            {
                request.Headers["x-amz-fwd-header-Content-Language"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ContentLanguage);
            }

            if (writeGetObjectResponseRequest.IsSetContentRange())
            {
                request.Headers["x-amz-fwd-header-Content-Range"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ContentRange);
            }

            if (writeGetObjectResponseRequest.IsSetContentType())
            {
                request.Headers["x-amz-fwd-header-Content-Type"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ContentType);
            }

            if (writeGetObjectResponseRequest.IsSetDeleteMarker())
            {
                request.Headers["x-amz-fwd-header-x-amz-delete-marker"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.DeleteMarker);
            }

            if (writeGetObjectResponseRequest.IsSetETag())
            {
                request.Headers["x-amz-fwd-header-ETag"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ETag);
            }

            if (writeGetObjectResponseRequest.IsSetExpires())
            {
                request.Headers["x-amz-fwd-header-Expires"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.Expires);
            }

            if (writeGetObjectResponseRequest.IsSetExpiration())
            {
                request.Headers["x-amz-fwd-header-x-amz-expiration"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.Expiration);
            }

            if (writeGetObjectResponseRequest.IsSetLastModified())
            {
                request.Headers["x-amz-fwd-header-Last-Modified"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.LastModified);
            }

            if (writeGetObjectResponseRequest.IsSetMissingMeta())
            {
                request.Headers["x-amz-fwd-header-x-amz-missing-meta"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.MissingMeta.Value);
            }

            AmazonS3Util.SetMetadataHeaders(request, writeGetObjectResponseRequest.Metadata);

            if (writeGetObjectResponseRequest.IsSetObjectLockMode())
            {
                request.Headers["x-amz-fwd-header-x-amz-object-lock-mode"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ObjectLockMode);
            }

            if (writeGetObjectResponseRequest.IsSetObjectLockLegalHoldStatus())
            {
                request.Headers["x-amz-fwd-header-x-amz-object-lock-legal-hold"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ObjectLockLegalHoldStatus);
            }

            if (writeGetObjectResponseRequest.IsSetObjectLockRetainUntilDate())
            {
                request.Headers["x-amz-fwd-header-x-amz-object-lock-retain-until-date"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ObjectLockRetainUntilDate);
            }

            if (writeGetObjectResponseRequest.IsSetPartsCount())
            {
                request.Headers["x-amz-fwd-header-x-amz-mp-parts-count"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.PartsCount.Value);
            }

            if (writeGetObjectResponseRequest.IsSetReplicationStatus())
            {
                request.Headers["x-amz-fwd-header-x-amz-replication-status"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ReplicationStatus);
            }

            if (writeGetObjectResponseRequest.IsSetRequestCharged())
            {
                request.Headers["x-amz-fwd-header-x-amz-request-charged"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.RequestCharged);
            }

            if (writeGetObjectResponseRequest.IsSetRestore())
            {
                request.Headers["x-amz-fwd-header-x-amz-restore"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.Restore);
            }

            if (writeGetObjectResponseRequest.IsSetServerSideEncryptionMethod())
            {
                request.Headers["x-amz-fwd-header-x-amz-server-side-encryption"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.ServerSideEncryptionMethod);
            }

            if (writeGetObjectResponseRequest.IsSetSSECustomerAlgorithm())
            {
                request.Headers["x-amz-fwd-header-x-amz-server-side-encryption-customer-algorithm"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.SSECustomerAlgorithm);
            }

            if (writeGetObjectResponseRequest.IsSetSSEKMSKeyId())
            {
                request.Headers["x-amz-fwd-header-x-amz-server-side-encryption-aws-kms-key-id"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.SSEKMSKeyId);
            }

            if (writeGetObjectResponseRequest.IsSetSSECustomerKeyMD5())
            {
                request.Headers["x-amz-fwd-header-x-amz-server-side-encryption-customer-key-MD5"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.SSECustomerKeyMD5);
            }

            if (writeGetObjectResponseRequest.IsSetStorageClass())
            {
                request.Headers["x-amz-fwd-header-x-amz-storage-class"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.StorageClass);
            }

            if (writeGetObjectResponseRequest.IsSetTagCount())
            {
                request.Headers["x-amz-fwd-header-x-amz-tagging-count"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.TagCount.Value);
            }

            if (writeGetObjectResponseRequest.IsSetVersionId())
            {
                request.Headers["x-amz-fwd-header-x-amz-version-id"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.VersionId);
            }

            if (writeGetObjectResponseRequest.IsSetBucketKeyEnabled())
            {
                request.Headers["x-amz-fwd-header-x-amz-server-side-encryption-bucket-key-enabled"] = S3Transforms.ToStringValue(writeGetObjectResponseRequest.BucketKeyEnabled);
            }

            var stream = writeGetObjectResponseRequest.Body ?? new MemoryStream();

            request.ContentStream = stream;
            if (writeGetObjectResponseRequest.IsSetContentLength())
            {
                var length = writeGetObjectResponseRequest.ContentLength.Value;
                request.Headers["Content-Length"] = length.ToString(CultureInfo.InvariantCulture);
            }
            else if (request.ContentStream.CanSeek)
            {
                request.Headers["Content-Length"] = request.ContentStream.Length.ToString(CultureInfo.InvariantCulture);
            }
            else
            {
                request.Headers[HeaderKeys.TransferEncodingHeader] = "chunked";
            }

            request.DisablePayloadSigning = true;

            if (!writeGetObjectResponseRequest.IsSetContentType())
            {
                request.Headers["x-amz-fwd-header-Content-Type"] = "binary/octet-stream";
            }

            var hostPrefixLabels = new
            {
                RequestRoute = StringUtils.FromString(writeGetObjectResponseRequest.RequestRoute)
            };

            if (!HostPrefixUtils.IsValidLabelValue(hostPrefixLabels.RequestRoute))
            {
                throw new AmazonS3Exception("RequestRoute can only contain alphanumeric characters and dashes and must be between 1 and 63 characters long.");
            }

            request.HostPrefix = $"{hostPrefixLabels.RequestRoute}.";

            request.ResourcePath = string.Format(CultureInfo.InvariantCulture, "/{0}",
                                                 S3Transforms.ToStringValue("WriteGetObjectResponse"));

            return(request);
        }
Example #12
0
        public IRequest Marshall(PutObjectRequest putObjectRequest)
        {
            IRequest request = new DefaultRequest(putObjectRequest, "AmazonS3");

            request.HttpMethod = "PUT";

            if (putObjectRequest.IsSetCannedACL())
            {
                request.Headers.Add("x-amz-acl", S3Transforms.ToStringValue(putObjectRequest.CannedACL));
            }

            var headers = putObjectRequest.Headers;

            foreach (var key in headers.Keys)
            {
                request.Headers[key] = headers[key];
            }

            if (putObjectRequest.IsSetMD5Digest())
            {
                request.Headers["Content-MD5"] = putObjectRequest.MD5Digest;
            }

            HeaderACLRequestMarshaller.Marshall(request, putObjectRequest);

            if (putObjectRequest.IsSetServerSideEncryptionMethod())
            {
                request.Headers.Add("x-amz-server-side-encryption", S3Transforms.ToStringValue(putObjectRequest.ServerSideEncryptionMethod));
            }

            if (putObjectRequest.IsSetStorageClass())
            {
                request.Headers.Add("x-amz-storage-class", S3Transforms.ToStringValue(putObjectRequest.StorageClass));
            }

            if (putObjectRequest.IsSetWebsiteRedirectLocation())
            {
                request.Headers.Add("x-amz-website-redirect-location", S3Transforms.ToStringValue(putObjectRequest.WebsiteRedirectLocation));
            }

            AmazonS3Util.SetMetadataHeaders(request, putObjectRequest.Metadata);

            var uriResourcePath = string.Format(CultureInfo.InvariantCulture, "/{0}/{1}",
                                                S3Transforms.ToStringValue(putObjectRequest.BucketName),
                                                S3Transforms.ToStringValue(putObjectRequest.Key));


            request.CanonicalResource = S3Transforms.GetCanonicalResource(uriResourcePath, request.Parameters);
            request.ResourcePath      = S3Transforms.FormatResourcePath(uriResourcePath, request.Parameters);

            if (putObjectRequest.InputStream != null)
            {
                // Wrap the stream in a stream that has a length
                var streamWithLength = GetStreamWithLength(putObjectRequest.InputStream, putObjectRequest.Headers.ContentLength);
                if (streamWithLength.Length > 0)
                {
                    request.UseChunkEncoding = true;
                }
                var length = streamWithLength.Length - streamWithLength.Position;
                if (!request.Headers.ContainsKey("Content-Length"))
                {
                    request.Headers.Add("Content-Length", length.ToString(CultureInfo.InvariantCulture));
                }

                // Wrap input stream in MD5Stream
                var hashStream = new MD5Stream(streamWithLength, null, length);
                putObjectRequest.InputStream = hashStream;
            }

            request.ContentStream = putObjectRequest.InputStream;
            if (!request.Headers.ContainsKey("Content-Type"))
            {
                request.Headers.Add("Content-Type", "text/plain");
            }

            if (!request.UseQueryString)
            {
                var queryString = AWSSDKUtils.GetParametersAsString(request.Parameters);
                if (!string.IsNullOrEmpty(queryString))
                {
                    request.ResourcePath = string.Concat(request.ResourcePath, request.ResourcePath.Contains("?") ? "&" : "?", queryString);
                }
            }

            return(request);
        }
Example #13
0
        public IRequest Marshall(CopyObjectRequest copyObjectRequest)
        {
            //IL_0006: Unknown result type (might be due to invalid IL or missing references)
            //IL_000c: Expected O, but got Unknown
            IRequest val = new DefaultRequest(copyObjectRequest, "AmazonS3");

            val.set_HttpMethod("PUT");
            if (copyObjectRequest.IsSetCannedACL())
            {
                val.get_Headers().Add("x-amz-acl", S3Transforms.ToStringValue(ConstantClass.op_Implicit(copyObjectRequest.CannedACL)));
            }
            HeadersCollection headers = copyObjectRequest.Headers;

            foreach (string key in headers.Keys)
            {
                val.get_Headers()[key] = headers[key];
            }
            HeaderACLRequestMarshaller.Marshall(val, copyObjectRequest);
            if (copyObjectRequest.IsSetSourceBucket())
            {
                val.get_Headers().Add("x-amz-copy-source", ConstructCopySourceHeaderValue(copyObjectRequest.SourceBucket, copyObjectRequest.SourceKey, copyObjectRequest.SourceVersionId));
            }
            if (copyObjectRequest.IsSetETagToMatch())
            {
                val.get_Headers().Add("x-amz-copy-source-if-match", S3Transforms.ToStringValue(copyObjectRequest.ETagToMatch));
            }
            if (copyObjectRequest.IsSetModifiedSinceDate())
            {
                val.get_Headers().Add("x-amz-copy-source-if-modified-since", S3Transforms.ToStringValue(copyObjectRequest.ModifiedSinceDate));
            }
            if (copyObjectRequest.IsSetETagToNotMatch())
            {
                val.get_Headers().Add("x-amz-copy-source-if-none-match", S3Transforms.ToStringValue(copyObjectRequest.ETagToNotMatch));
            }
            if (copyObjectRequest.IsSetUnmodifiedSinceDate())
            {
                val.get_Headers().Add("x-amz-copy-source-if-unmodified-since", S3Transforms.ToStringValue(copyObjectRequest.UnmodifiedSinceDate));
            }
            if (copyObjectRequest.IsSetTagSet())
            {
                val.get_Headers().Add(S3Constants.AmzHeaderTagging, AmazonS3Util.TagSetToQueryString(copyObjectRequest.TagSet));
                val.get_Headers().Add(S3Constants.AmzHeaderTaggingDirective, TaggingDirective.REPLACE.get_Value());
            }
            else
            {
                val.get_Headers().Add(S3Constants.AmzHeaderTaggingDirective, TaggingDirective.COPY.get_Value());
            }
            val.get_Headers().Add("x-amz-metadata-directive", S3Transforms.ToStringValue(copyObjectRequest.MetadataDirective.ToString()));
            if (copyObjectRequest.IsSetServerSideEncryptionMethod())
            {
                val.get_Headers().Add("x-amz-server-side-encryption", S3Transforms.ToStringValue(ConstantClass.op_Implicit(copyObjectRequest.ServerSideEncryptionMethod)));
            }
            if (copyObjectRequest.IsSetServerSideEncryptionCustomerMethod())
            {
                val.get_Headers().Add("x-amz-server-side-encryption-customer-algorithm", ConstantClass.op_Implicit(copyObjectRequest.ServerSideEncryptionCustomerMethod));
            }
            if (copyObjectRequest.IsSetServerSideEncryptionCustomerProvidedKey())
            {
                val.get_Headers().Add("x-amz-server-side-encryption-customer-key", copyObjectRequest.ServerSideEncryptionCustomerProvidedKey);
                if (copyObjectRequest.IsSetServerSideEncryptionCustomerProvidedKeyMD5())
                {
                    val.get_Headers().Add("x-amz-server-side-encryption-customer-key-MD5", copyObjectRequest.ServerSideEncryptionCustomerProvidedKeyMD5);
                }
                else
                {
                    val.get_Headers().Add("x-amz-server-side-encryption-customer-key-MD5", AmazonS3Util.ComputeEncodedMD5FromEncodedString(copyObjectRequest.ServerSideEncryptionCustomerProvidedKey));
                }
            }
            if (copyObjectRequest.IsSetCopySourceServerSideEncryptionCustomerMethod())
            {
                val.get_Headers().Add("x-amz-copy-source-server-side-encryption-customer-algorithm", ConstantClass.op_Implicit(copyObjectRequest.CopySourceServerSideEncryptionCustomerMethod));
            }
            if (copyObjectRequest.IsSetCopySourceServerSideEncryptionCustomerProvidedKey())
            {
                val.get_Headers().Add("x-amz-copy-source-server-side-encryption-customer-key", copyObjectRequest.CopySourceServerSideEncryptionCustomerProvidedKey);
                if (copyObjectRequest.IsSetCopySourceServerSideEncryptionCustomerProvidedKeyMD5())
                {
                    val.get_Headers().Add("x-amz-copy-source-server-side-encryption-customer-key-MD5", copyObjectRequest.CopySourceServerSideEncryptionCustomerProvidedKeyMD5);
                }
                else
                {
                    val.get_Headers().Add("x-amz-copy-source-server-side-encryption-customer-key-MD5", AmazonS3Util.ComputeEncodedMD5FromEncodedString(copyObjectRequest.CopySourceServerSideEncryptionCustomerProvidedKey));
                }
            }
            if (copyObjectRequest.IsSetServerSideEncryptionKeyManagementServiceKeyId())
            {
                val.get_Headers().Add("x-amz-server-side-encryption-aws-kms-key-id", copyObjectRequest.ServerSideEncryptionKeyManagementServiceKeyId);
            }
            if (copyObjectRequest.IsSetStorageClass())
            {
                val.get_Headers().Add("x-amz-storage-class", S3Transforms.ToStringValue(ConstantClass.op_Implicit(copyObjectRequest.StorageClass)));
            }
            if (copyObjectRequest.IsSetWebsiteRedirectLocation())
            {
                val.get_Headers().Add("x-amz-website-redirect-location", S3Transforms.ToStringValue(copyObjectRequest.WebsiteRedirectLocation));
            }
            if (copyObjectRequest.IsSetRequestPayer())
            {
                val.get_Headers().Add(S3Constants.AmzHeaderRequestPayer, S3Transforms.ToStringValue(((object)copyObjectRequest.RequestPayer).ToString()));
            }
            AmazonS3Util.SetMetadataHeaders(val, copyObjectRequest.Metadata);
            string value = copyObjectRequest.DestinationKey.StartsWith("/", StringComparison.Ordinal) ? copyObjectRequest.DestinationKey.Substring(1) : copyObjectRequest.DestinationKey;

            val.set_ResourcePath(string.Format(CultureInfo.InvariantCulture, "/{0}/{1}", S3Transforms.ToStringValue(copyObjectRequest.DestinationBucket), S3Transforms.ToStringValue(value)));
            val.set_UseQueryString(true);
            return(val);
        }
        public IRequest Marshall(PutObjectRequest putObjectRequest)
        {
            //IL_0006: Unknown result type (might be due to invalid IL or missing references)
            //IL_000c: Expected O, but got Unknown
            //IL_02b8: Unknown result type (might be due to invalid IL or missing references)
            //IL_02bf: Expected O, but got Unknown
            IRequest val = new DefaultRequest(putObjectRequest, "AmazonS3");

            val.set_HttpMethod("PUT");
            if (putObjectRequest.IsSetCannedACL())
            {
                val.get_Headers().Add("x-amz-acl", S3Transforms.ToStringValue(ConstantClass.op_Implicit(putObjectRequest.CannedACL)));
            }
            HeadersCollection headers = putObjectRequest.Headers;

            foreach (string key in headers.Keys)
            {
                val.get_Headers()[key] = headers[key];
            }
            if (putObjectRequest.IsSetMD5Digest())
            {
                val.get_Headers()["Content-MD5"] = putObjectRequest.MD5Digest;
            }
            HeaderACLRequestMarshaller.Marshall(val, putObjectRequest);
            if (putObjectRequest.IsSetServerSideEncryptionMethod())
            {
                val.get_Headers().Add("x-amz-server-side-encryption", S3Transforms.ToStringValue(ConstantClass.op_Implicit(putObjectRequest.ServerSideEncryptionMethod)));
            }
            if (putObjectRequest.IsSetStorageClass())
            {
                val.get_Headers().Add("x-amz-storage-class", S3Transforms.ToStringValue(ConstantClass.op_Implicit(putObjectRequest.StorageClass)));
            }
            if (putObjectRequest.IsSetWebsiteRedirectLocation())
            {
                val.get_Headers().Add("x-amz-website-redirect-location", S3Transforms.ToStringValue(putObjectRequest.WebsiteRedirectLocation));
            }
            if (putObjectRequest.IsSetServerSideEncryptionCustomerMethod())
            {
                val.get_Headers().Add("x-amz-server-side-encryption-customer-algorithm", ConstantClass.op_Implicit(putObjectRequest.ServerSideEncryptionCustomerMethod));
            }
            if (putObjectRequest.IsSetServerSideEncryptionCustomerProvidedKey())
            {
                val.get_Headers().Add("x-amz-server-side-encryption-customer-key", putObjectRequest.ServerSideEncryptionCustomerProvidedKey);
                if (putObjectRequest.IsSetServerSideEncryptionCustomerProvidedKeyMD5())
                {
                    val.get_Headers().Add("x-amz-server-side-encryption-customer-key-MD5", putObjectRequest.ServerSideEncryptionCustomerProvidedKeyMD5);
                }
                else
                {
                    val.get_Headers().Add("x-amz-server-side-encryption-customer-key-MD5", AmazonS3Util.ComputeEncodedMD5FromEncodedString(putObjectRequest.ServerSideEncryptionCustomerProvidedKey));
                }
            }
            if (putObjectRequest.IsSetServerSideEncryptionKeyManagementServiceKeyId())
            {
                val.get_Headers().Add("x-amz-server-side-encryption-aws-kms-key-id", putObjectRequest.ServerSideEncryptionKeyManagementServiceKeyId);
            }
            if (putObjectRequest.IsSetRequestPayer())
            {
                val.get_Headers().Add(S3Constants.AmzHeaderRequestPayer, S3Transforms.ToStringValue(((object)putObjectRequest.RequestPayer).ToString()));
            }
            if (putObjectRequest.IsSetTagSet())
            {
                val.get_Headers().Add(S3Constants.AmzHeaderTagging, AmazonS3Util.TagSetToQueryString(putObjectRequest.TagSet));
            }
            AmazonS3Util.SetMetadataHeaders(val, putObjectRequest.Metadata);
            val.set_ResourcePath(string.Format(CultureInfo.InvariantCulture, "/{0}/{1}", S3Transforms.ToStringValue(putObjectRequest.BucketName), S3Transforms.ToStringValue(putObjectRequest.Key)));
            if (putObjectRequest.InputStream != null)
            {
                Stream streamWithLength = GetStreamWithLength(putObjectRequest.InputStream, putObjectRequest.Headers.ContentLength);
                if (streamWithLength.Length > 0)
                {
                    val.set_UseChunkEncoding(true);
                }
                long num = streamWithLength.Length - streamWithLength.Position;
                if (!val.get_Headers().ContainsKey("Content-Length"))
                {
                    val.get_Headers().Add("Content-Length", num.ToString(CultureInfo.InvariantCulture));
                }
                MD5Stream val2 = putObjectRequest.InputStream = (Stream) new MD5Stream(streamWithLength, (byte[])null, num);
            }
            val.set_ContentStream(putObjectRequest.InputStream);
            if (!val.get_Headers().ContainsKey("Content-Type"))
            {
                val.get_Headers().Add("Content-Type", "text/plain");
            }
            return(val);
        }
Example #15
0
        public IRequest Marshall(CopyObjectRequest copyObjectRequest)
        {
            IRequest request = new DefaultRequest(copyObjectRequest, "AmazonS3");

            request.HttpMethod = "PUT";

            if (copyObjectRequest.IsSetCannedACL())
            {
                request.Headers.Add("x-amz-acl", S3Transforms.ToStringValue(copyObjectRequest.CannedACL));
            }

            var headers = copyObjectRequest.Headers;

            foreach (var key in headers.Keys)
            {
                request.Headers[key] = headers[key];
            }

            HeaderACLRequestMarshaller.Marshall(request, copyObjectRequest);

            if (copyObjectRequest.IsSetSourceBucket())
            {
                request.Headers.Add("x-amz-copy-source", ConstructCopySourceHeaderValue(copyObjectRequest.SourceBucket, copyObjectRequest.SourceKey, copyObjectRequest.SourceVersionId));
            }

            if (copyObjectRequest.IsSetETagToMatch())
            {
                request.Headers.Add("x-amz-copy-source-if-match", S3Transforms.ToStringValue(copyObjectRequest.ETagToMatch));
            }

            if (copyObjectRequest.IsSetModifiedSinceDate())
            {
                request.Headers.Add("x-amz-copy-source-if-modified-since", S3Transforms.ToStringValue(copyObjectRequest.ModifiedSinceDate));
            }

            if (copyObjectRequest.IsSetETagToNotMatch())
            {
                request.Headers.Add("x-amz-copy-source-if-none-match", S3Transforms.ToStringValue(copyObjectRequest.ETagToNotMatch));
            }

            if (copyObjectRequest.IsSetUnmodifiedSinceDate())
            {
                request.Headers.Add("x-amz-copy-source-if-unmodified-since", S3Transforms.ToStringValue(copyObjectRequest.UnmodifiedSinceDate));
            }

            request.Headers.Add("x-amz-metadata-directive", S3Transforms.ToStringValue(copyObjectRequest.MetadataDirective.ToString()));

            if (copyObjectRequest.IsSetServerSideEncryptionMethod())
            {
                request.Headers.Add("x-amz-server-side-encryption", S3Transforms.ToStringValue(copyObjectRequest.ServerSideEncryptionMethod));
            }

            if (copyObjectRequest.IsSetStorageClass())
            {
                request.Headers.Add("x-amz-storage-class", S3Transforms.ToStringValue(copyObjectRequest.StorageClass));
            }

            if (copyObjectRequest.IsSetWebsiteRedirectLocation())
            {
                request.Headers.Add("x-amz-website-redirect-location", S3Transforms.ToStringValue(copyObjectRequest.WebsiteRedirectLocation));
            }

            AmazonS3Util.SetMetadataHeaders(request, copyObjectRequest.Metadata);

            var uriResourcePath = string.Format(CultureInfo.InvariantCulture, "/{0}/{1}",
                                                S3Transforms.ToStringValue(copyObjectRequest.DestinationBucket),
                                                S3Transforms.ToStringValue(copyObjectRequest.DestinationKey));


            request.CanonicalResource = S3Transforms.GetCanonicalResource(uriResourcePath, request.Parameters);
            request.ResourcePath      = S3Transforms.FormatResourcePath(uriResourcePath, request.Parameters);
            request.UseQueryString    = true;

            return(request);
        }