Exemple #1
0
 private Amazon.S3.Model.PutObjectRetentionResponse CallAWSServiceOperation(IAmazonS3 client, Amazon.S3.Model.PutObjectRetentionRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Simple Storage Service (S3)", "PutObjectRetention");
     try
     {
         #if DESKTOP
         return(client.PutObjectRetention(request));
         #elif CORECLR
         return(client.PutObjectRetentionAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
Exemple #2
0
        public object Execute(ExecutorContext context)
        {
            var cmdletContext = context as CmdletContext;
            // create request
            var request = new Amazon.S3.Model.PutObjectRetentionRequest();

            if (cmdletContext.BucketName != null)
            {
                request.BucketName = cmdletContext.BucketName;
            }
            if (cmdletContext.BypassGovernanceRetention != null)
            {
                request.BypassGovernanceRetention = cmdletContext.BypassGovernanceRetention.Value;
            }
            if (cmdletContext.ContentMD5 != null)
            {
                request.ContentMD5 = cmdletContext.ContentMD5;
            }
            if (cmdletContext.Key != null)
            {
                request.Key = cmdletContext.Key;
            }
            if (cmdletContext.RequestPayer != null)
            {
                request.RequestPayer = cmdletContext.RequestPayer;
            }

            // populate Retention
            var requestRetentionIsNull = true;

            request.Retention = new Amazon.S3.Model.ObjectLockRetention();
            Amazon.S3.ObjectLockRetentionMode requestRetention_retention_Mode = null;
            if (cmdletContext.Retention_Mode != null)
            {
                requestRetention_retention_Mode = cmdletContext.Retention_Mode;
            }
            if (requestRetention_retention_Mode != null)
            {
                request.Retention.Mode = requestRetention_retention_Mode;
                requestRetentionIsNull = false;
            }
            System.DateTime?requestRetention_retention_RetainUntilDate = null;
            if (cmdletContext.Retention_RetainUntilDate != null)
            {
                requestRetention_retention_RetainUntilDate = cmdletContext.Retention_RetainUntilDate.Value;
            }
            if (requestRetention_retention_RetainUntilDate != null)
            {
                request.Retention.RetainUntilDate = requestRetention_retention_RetainUntilDate.Value;
                requestRetentionIsNull            = false;
            }
            // determine if request.Retention should be set to null
            if (requestRetentionIsNull)
            {
                request.Retention = null;
            }
            if (cmdletContext.VersionId != null)
            {
                request.VersionId = cmdletContext.VersionId;
            }
            if (cmdletContext.ExpectedBucketOwner != null)
            {
                request.ExpectedBucketOwner = cmdletContext.ExpectedBucketOwner;
            }

            CmdletOutput output;

            // issue call
            var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);

            try
            {
                var    response       = CallAWSServiceOperation(client, request);
                object pipelineOutput = null;
                pipelineOutput = cmdletContext.Select(response, this);
                output         = new CmdletOutput
                {
                    PipelineOutput  = pipelineOutput,
                    ServiceResponse = response
                };
            }
            catch (Exception e)
            {
                output = new CmdletOutput {
                    ErrorResponse = e
                };
            }

            return(output);
        }