Ejemplo n.º 1
0
        public object Execute(ExecutorContext context)
        {
            var cmdletContext = context as CmdletContext;
            var request       = new PutBucketRequest();

            if (cmdletContext.BucketName != null)
            {
                request.BucketName = cmdletContext.BucketName;
            }

            if (cmdletContext.CannedACL != null)
            {
                request.CannedACL = cmdletContext.CannedACL.Value;
            }

            // Forcibly set a location constraint to match whatever Region argument was used
            // with the cmdlet; this will prevent S3 issuing the "unspecified location constraint
            // didn't match" message, potentially confusing new users.
            request.BucketRegionName = _RegionEndpoint.SystemName;

            if (cmdletContext.ObjectLockEnabledForBucket != null)
            {
                request.ObjectLockEnabledForBucket = cmdletContext.ObjectLockEnabledForBucket.Value;
            }

            ServiceCalls.PushServiceRequest(request, this.MyInvocation);

            using (var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint))
            {
                CmdletOutput output;
                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
                    };
                    this.WriteError(new ErrorRecord(e, $"Failed to create the specified bucket.\r\nAmazon S3 error: {e.Message}", ErrorCategory.InvalidOperation, this));
                }

                return(output);
            }
        }