Base class for request used by some of the services.
Наследование: Amazon.Runtime.Internal.IAmazonWebServiceRequest
 internal static PreRequestEventArgs Create(AmazonWebServiceRequest request)
 {
     PreRequestEventArgs args = new PreRequestEventArgs
     {
         Request = request
     };
     return args;
 }
Пример #2
0
        /// <summary>
        /// Constructs a new DefaultRequest with the specified service name and the
        /// original, user facing request object.
        /// </summary>
        /// <param name="request">The orignal request that is being wrapped</param>
        /// <param name="serviceName">The service name</param>
        public DefaultRequest(AmazonWebServiceRequest request, String serviceName)
        {
            if (request == null) throw new ArgumentNullException("request");
            if (string.IsNullOrEmpty(serviceName)) throw new ArgumentNullException("serviceName");

            this.serviceName = serviceName;
            this.originalRequest = request;
            this.requestName = this.originalRequest.GetType().Name;
        }
        protected override void ProcessPreRequestHandlers(AmazonWebServiceRequest request)
        {
            base.ProcessPreRequestHandlers(request);

            var uploadDocumentsRequest = request as UploadDocumentsRequest;
            if (uploadDocumentsRequest != null)
            {
                if(uploadDocumentsRequest.Documents == null && string.IsNullOrEmpty(uploadDocumentsRequest.FilePath))
                    throw new ArgumentException("Please specify one of either a Documents or a FilePath to be uploaded.");

                if (uploadDocumentsRequest.Documents != null && !string.IsNullOrEmpty(uploadDocumentsRequest.FilePath))
                    throw new ArgumentException("Please specify one of either a Documents or a FilePath to be uploaded.");

                if (!string.IsNullOrEmpty(uploadDocumentsRequest.FilePath))
                {
                    uploadDocumentsRequest.SetupForFilePath();
                }
            }
        }
Пример #4
0
 public IRequest Marshall(Amazon.Runtime.AmazonWebServiceRequest input)
 {
     return(this.Marshall((PutPublicAccessBlockRequest)input));
 }
Пример #5
0
 public IRequest Marshall(Amazon.Runtime.AmazonWebServiceRequest input)
 {
     return(this.Marshall((ListBucketsRequest)input));
 }
Пример #6
0
 public IRequest Marshall(Amazon.Runtime.AmazonWebServiceRequest input)
 {
     return(this.Marshall((PutObjectRequest)input));
 }
 public IRequest Marshall(Amazon.Runtime.AmazonWebServiceRequest input)
 {
     return(this.Marshall((ListBucketInventoryConfigurationsRequest)input));
 }
Пример #8
0
 public IRequest Marshall(Amazon.Runtime.AmazonWebServiceRequest input)
 {
     return(this.Marshall((CompleteMultipartUploadRequest)input));
 }
Пример #9
0
 public IRequest Marshall(Amazon.Runtime.AmazonWebServiceRequest input)
 {
     return(this.Marshall((PutBucketIntelligentTieringConfigurationRequest)input));
 }
Пример #10
0
 /// <summary>
 /// Constructs a new DefaultRequest with the specified service name and the
 /// original, user facing request object.
 /// </summary>
 /// <param name="originalRequest">The orignal request that is being wrapped</param>
 /// <param name="serviceName">The service name</param>
 public DefaultRequest(AmazonWebServiceRequest originalRequest, String serviceName)
 {
     this.serviceName = serviceName;
     this.originalRequest = originalRequest;
 }
        /// <summary>
        /// Performs encryption for PutObject and MultiPartUpload,
        /// also adding encryption information to object metadata or
        /// instruction file
        /// </summary>
        /// <param name="request">AmazonWebServiceRequest on which encryption is performed </param>
        protected override void ProcessPreRequestHandlers(AmazonWebServiceRequest request)
        {
            base.ProcessPreRequestHandlers(request);

            var putObjectRequest = request as PutObjectRequest;
            if (putObjectRequest != null)
            {
                if (this.amazonS3CryptoConfig.StorageMode == CryptoStorageMode.InstructionFile)
                {
                    GenerateEncryptedObjectRequestUsingInstructionFile(putObjectRequest);
                }
                else
                {
                    GenerateEncryptedObjectRequestUsingMetadata(putObjectRequest);
                }
            }

            var initiateMultiPartRequest = request as InitiateMultipartUploadRequest;
            if (initiateMultiPartRequest != null)
            {
                EncryptionInstructions instructions = EncryptionUtils.GenerateInstructions(this.encryptionMaterials);

                if (this.amazonS3CryptoConfig.StorageMode == CryptoStorageMode.ObjectMetadata)
                {
                    EncryptionUtils.UpdateMetadataWithEncryptionInstructions(initiateMultiPartRequest, instructions);
                }

                initiateMultiPartRequest.EnvelopeKey = instructions.EnvelopeKey;
                initiateMultiPartRequest.IV = instructions.InitializationVector;
            }

            var uploadPartRequest = request as UploadPartRequest;
            if (uploadPartRequest != null)
            {
                GenerateEncryptedUploadPartRequest(uploadPartRequest);
            }
        }
Пример #12
0
        internal static PutObjectRequest CreateInstructionFileRequest(AmazonWebServiceRequest request, EncryptionInstructions instructions)
        {
            byte[] keyBytesToStoreInInstructionFile = instructions.EncryptedEnvelopeKey;
            string base64EncodedEnvelopeKey = Convert.ToBase64String(keyBytesToStoreInInstructionFile);

            byte[] IVToStoreInInstructionFile = instructions.InitializationVector;
            string base64EncodedIV = Convert.ToBase64String(IVToStoreInInstructionFile);

            JsonData jsonData = new JsonData();
            jsonData["EncryptedEnvelopeKey"] = base64EncodedEnvelopeKey;
            jsonData["IV"] = base64EncodedIV;

            string credentials = jsonData.ToJson();

            var putObjectRequest = request as PutObjectRequest;
            if (putObjectRequest != null)
            {
                PutObjectRequest requestforInstructionFile = new PutObjectRequest()
                {
                    BucketName = putObjectRequest.BucketName,
                    Key = putObjectRequest.Key + instructionfileSuffix,
                    ContentBody = credentials
                };
                requestforInstructionFile.Metadata.Add(instructionFileInfo, "");
                return requestforInstructionFile;
            }

            var completeMultiPartRequest = request as CompleteMultipartUploadRequest;
            if (completeMultiPartRequest != null)
            {
                PutObjectRequest requestforInstructionFile = new PutObjectRequest()
                {
                    BucketName = completeMultiPartRequest.BucketName,
                    Key = completeMultiPartRequest.Key + instructionfileSuffix,
                    ContentBody = credentials
                };
                requestforInstructionFile.Metadata.Add(instructionFileInfo, "");
                return requestforInstructionFile;
            }

            else
                return null;
        }
Пример #13
0
        /// <summary>
        /// Update the request's ObjectMetadata with the necessary information for decrypting the object.
        /// </summary>
        /// <param name="request">
        /// AmazonWebServiceRequest  encrypted using the given instruction
        /// </param>
        /// <param name="instructions">
        /// Non-null instruction used to encrypt the data in this AmazonWebServiceRequest .
        /// </param>
        internal static void UpdateMetadataWithEncryptionInstructions(AmazonWebServiceRequest request, EncryptionInstructions instructions)
        {
            byte[] keyBytesToStoreInMetadata = instructions.EncryptedEnvelopeKey;
            string base64EncodedEnvelopeKey = Convert.ToBase64String(keyBytesToStoreInMetadata);

            byte[] IVToStoreInMetadata = instructions.InitializationVector;
            string base64EncodedIV = Convert.ToBase64String(IVToStoreInMetadata);

            var putObjectRequest = request as PutObjectRequest;
            if (putObjectRequest != null)
            {
                MetadataCollection metadata = putObjectRequest.Metadata;
                metadata.Add(keyInMetadata, base64EncodedEnvelopeKey);
                metadata.Add(initVectorInMetadata, base64EncodedIV);

                Dictionary<string, string> materialsDescription = instructions.MaterialsDescription;
                if (materialsDescription.Count == 0)
                    metadata.Add(encryptionMaterialsDescription, "{}");

                putObjectRequest.Metadata = metadata;
            }

            var initiateMultipartrequest = request as InitiateMultipartUploadRequest;
            if (initiateMultipartrequest != null)
            {
                MetadataCollection metadata = initiateMultipartrequest.Metadata;
                metadata.Add(keyInMetadata, base64EncodedEnvelopeKey);
                metadata.Add(initVectorInMetadata, base64EncodedIV);

                Dictionary<string, string> materialsDescription = instructions.MaterialsDescription;
                if (materialsDescription.Count == 0)
                    metadata.Add(encryptionMaterialsDescription, "{}");

                initiateMultipartrequest.Metadata = metadata;
            }
        }
Пример #14
0
 public IRequest Marshall(Amazon.Runtime.AmazonWebServiceRequest input)
 {
     return(this.Marshall((PutBucketOwnershipControlsRequest)input));
 }
Пример #15
0
 public IRequest Marshall(Amazon.Runtime.AmazonWebServiceRequest input)
 {
     return(this.Marshall((PutBucketNotificationRequest)input));
 }
Пример #16
0
 public IRequest Marshall(Amazon.Runtime.AmazonWebServiceRequest input)
 {
     return(this.Marshall((PutBucketAnalyticsConfigurationRequest)input));
 }
Пример #17
0
 public IRequest Marshall(Amazon.Runtime.AmazonWebServiceRequest input)
 {
     return(this.Marshall((PutBucketLoggingRequest)input));
 }
 public IRequest Marshall(Amazon.Runtime.AmazonWebServiceRequest input)
 {
     return(this.Marshall((PutLifecycleConfigurationRequest)input));
 }