public object Execute(ExecutorContext context)
        {
            var cmdletContext = context as CmdletContext;
            // create request
            var request = new Amazon.S3.Model.RestoreObjectRequest();

            if (cmdletContext.BucketName != null)
            {
                request.BucketName = cmdletContext.BucketName;
            }
            if (cmdletContext.Key != null)
            {
                request.Key = cmdletContext.Key;
            }
            if (cmdletContext.CopyLifetimeInDays != null)
            {
                request.Days = cmdletContext.CopyLifetimeInDays.Value;
            }
            if (cmdletContext.VersionId != null)
            {
                request.VersionId = cmdletContext.VersionId;
            }
            if (cmdletContext.RequestPayer != null)
            {
                request.RequestPayer = cmdletContext.RequestPayer;
            }
            if (cmdletContext.Tier != null)
            {
                request.Tier = cmdletContext.Tier;
            }
            if (cmdletContext.RetrievalTier != null)
            {
                request.RetrievalTier = cmdletContext.RetrievalTier;
            }
            if (cmdletContext.RestoreRequestType != null)
            {
                request.RestoreRequestType = cmdletContext.RestoreRequestType;
            }
            if (cmdletContext.Description != null)
            {
                request.Description = cmdletContext.Description;
            }
            if (cmdletContext.SelectParameter != null)
            {
                request.SelectParameters = cmdletContext.SelectParameter;
            }

            // populate OutputLocation
            var requestOutputLocationIsNull = true;

            request.OutputLocation = new Amazon.S3.Model.OutputLocation();
            Amazon.S3.Model.S3Location requestOutputLocation_outputLocation_S3 = null;

            // populate S3
            var requestOutputLocation_outputLocation_S3IsNull = true;

            requestOutputLocation_outputLocation_S3 = new Amazon.S3.Model.S3Location();
            System.String requestOutputLocation_outputLocation_S3_s3_BucketName = null;
            if (cmdletContext.S3_BucketName != null)
            {
                requestOutputLocation_outputLocation_S3_s3_BucketName = cmdletContext.S3_BucketName;
            }
            if (requestOutputLocation_outputLocation_S3_s3_BucketName != null)
            {
                requestOutputLocation_outputLocation_S3.BucketName = requestOutputLocation_outputLocation_S3_s3_BucketName;
                requestOutputLocation_outputLocation_S3IsNull      = false;
            }
            System.String requestOutputLocation_outputLocation_S3_s3_Prefix = null;
            if (cmdletContext.S3_Prefix != null)
            {
                requestOutputLocation_outputLocation_S3_s3_Prefix = cmdletContext.S3_Prefix;
            }
            if (requestOutputLocation_outputLocation_S3_s3_Prefix != null)
            {
                requestOutputLocation_outputLocation_S3.Prefix = requestOutputLocation_outputLocation_S3_s3_Prefix;
                requestOutputLocation_outputLocation_S3IsNull  = false;
            }
            Amazon.S3.S3CannedACL requestOutputLocation_outputLocation_S3_s3_CannedACL = null;
            if (cmdletContext.S3_CannedACL != null)
            {
                requestOutputLocation_outputLocation_S3_s3_CannedACL = cmdletContext.S3_CannedACL;
            }
            if (requestOutputLocation_outputLocation_S3_s3_CannedACL != null)
            {
                requestOutputLocation_outputLocation_S3.CannedACL = requestOutputLocation_outputLocation_S3_s3_CannedACL;
                requestOutputLocation_outputLocation_S3IsNull     = false;
            }
            Amazon.S3.Model.MetadataCollection requestOutputLocation_outputLocation_S3_s3_UserMetadata = null;
            if (cmdletContext.S3_UserMetadata != null)
            {
                requestOutputLocation_outputLocation_S3_s3_UserMetadata = cmdletContext.S3_UserMetadata;
            }
            if (requestOutputLocation_outputLocation_S3_s3_UserMetadata != null)
            {
                requestOutputLocation_outputLocation_S3.UserMetadata = requestOutputLocation_outputLocation_S3_s3_UserMetadata;
                requestOutputLocation_outputLocation_S3IsNull        = false;
            }
            Amazon.S3.S3StorageClass requestOutputLocation_outputLocation_S3_s3_StorageClass = null;
            if (cmdletContext.S3_StorageClass != null)
            {
                requestOutputLocation_outputLocation_S3_s3_StorageClass = cmdletContext.S3_StorageClass;
            }
            if (requestOutputLocation_outputLocation_S3_s3_StorageClass != null)
            {
                requestOutputLocation_outputLocation_S3.StorageClass = requestOutputLocation_outputLocation_S3_s3_StorageClass;
                requestOutputLocation_outputLocation_S3IsNull        = false;
            }
            Amazon.S3.Model.Tagging requestOutputLocation_outputLocation_S3_outputLocation_S3_Tagging = null;

            // populate Tagging
            var requestOutputLocation_outputLocation_S3_outputLocation_S3_TaggingIsNull = true;

            requestOutputLocation_outputLocation_S3_outputLocation_S3_Tagging = new Amazon.S3.Model.Tagging();
            List <Amazon.S3.Model.Tag> requestOutputLocation_outputLocation_S3_outputLocation_S3_Tagging_tagging_TagSet = null;

            if (cmdletContext.Tagging_TagSet != null)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_Tagging_tagging_TagSet = cmdletContext.Tagging_TagSet;
            }
            if (requestOutputLocation_outputLocation_S3_outputLocation_S3_Tagging_tagging_TagSet != null)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_Tagging.TagSet = requestOutputLocation_outputLocation_S3_outputLocation_S3_Tagging_tagging_TagSet;
                requestOutputLocation_outputLocation_S3_outputLocation_S3_TaggingIsNull  = false;
            }
            // determine if requestOutputLocation_outputLocation_S3_outputLocation_S3_Tagging should be set to null
            if (requestOutputLocation_outputLocation_S3_outputLocation_S3_TaggingIsNull)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_Tagging = null;
            }
            if (requestOutputLocation_outputLocation_S3_outputLocation_S3_Tagging != null)
            {
                requestOutputLocation_outputLocation_S3.Tagging = requestOutputLocation_outputLocation_S3_outputLocation_S3_Tagging;
                requestOutputLocation_outputLocation_S3IsNull   = false;
            }
            Amazon.S3.Model.S3AccessControlList requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList = null;

            // populate AccessControlList
            var requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlListIsNull = true;

            requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList = new Amazon.S3.Model.S3AccessControlList();
            List <Amazon.S3.Model.S3Grant> requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_accessControlList_Grant = null;

            if (cmdletContext.AccessControlList_Grant != null)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_accessControlList_Grant = cmdletContext.AccessControlList_Grant;
            }
            if (requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_accessControlList_Grant != null)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList.Grants = requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_accessControlList_Grant;
                requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlListIsNull  = false;
            }
            Amazon.S3.Model.Owner requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner = null;

            // populate Owner
            var requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_OwnerIsNull = true;

            requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner = new Amazon.S3.Model.Owner();
            System.String requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner_owner_DisplayName = null;
            if (cmdletContext.Owner_DisplayName != null)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner_owner_DisplayName = cmdletContext.Owner_DisplayName;
            }
            if (requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner_owner_DisplayName != null)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner.DisplayName = requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner_owner_DisplayName;
                requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_OwnerIsNull       = false;
            }
            System.String requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner_owner_Id = null;
            if (cmdletContext.Owner_Id != null)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner_owner_Id = cmdletContext.Owner_Id;
            }
            if (requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner_owner_Id != null)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner.Id    = requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner_owner_Id;
                requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_OwnerIsNull = false;
            }
            // determine if requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner should be set to null
            if (requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_OwnerIsNull)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner = null;
            }
            if (requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner != null)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList.Owner = requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList_outputLocation_S3_AccessControlList_Owner;
                requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlListIsNull = false;
            }
            // determine if requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList should be set to null
            if (requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlListIsNull)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList = null;
            }
            if (requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList != null)
            {
                requestOutputLocation_outputLocation_S3.AccessControlList = requestOutputLocation_outputLocation_S3_outputLocation_S3_AccessControlList;
                requestOutputLocation_outputLocation_S3IsNull             = false;
            }
            Amazon.S3.Model.S3Encryption requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption = null;

            // populate Encryption
            var requestOutputLocation_outputLocation_S3_outputLocation_S3_EncryptionIsNull = true;

            requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption = new Amazon.S3.Model.S3Encryption();
            Amazon.S3.ServerSideEncryptionMethod requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption_encryption_EncryptionType = null;
            if (cmdletContext.Encryption_EncryptionType != null)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption_encryption_EncryptionType = cmdletContext.Encryption_EncryptionType;
            }
            if (requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption_encryption_EncryptionType != null)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption.EncryptionType = requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption_encryption_EncryptionType;
                requestOutputLocation_outputLocation_S3_outputLocation_S3_EncryptionIsNull          = false;
            }
            System.String requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption_encryption_KMSKeyId = null;
            if (cmdletContext.Encryption_KMSKeyId != null)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption_encryption_KMSKeyId = cmdletContext.Encryption_KMSKeyId;
            }
            if (requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption_encryption_KMSKeyId != null)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption.KMSKeyId = requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption_encryption_KMSKeyId;
                requestOutputLocation_outputLocation_S3_outputLocation_S3_EncryptionIsNull    = false;
            }
            System.String requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption_encryption_KMSContext = null;
            if (cmdletContext.Encryption_KMSContext != null)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption_encryption_KMSContext = cmdletContext.Encryption_KMSContext;
            }
            if (requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption_encryption_KMSContext != null)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption.KMSContext = requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption_encryption_KMSContext;
                requestOutputLocation_outputLocation_S3_outputLocation_S3_EncryptionIsNull      = false;
            }
            // determine if requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption should be set to null
            if (requestOutputLocation_outputLocation_S3_outputLocation_S3_EncryptionIsNull)
            {
                requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption = null;
            }
            if (requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption != null)
            {
                requestOutputLocation_outputLocation_S3.Encryption = requestOutputLocation_outputLocation_S3_outputLocation_S3_Encryption;
                requestOutputLocation_outputLocation_S3IsNull      = false;
            }
            // determine if requestOutputLocation_outputLocation_S3 should be set to null
            if (requestOutputLocation_outputLocation_S3IsNull)
            {
                requestOutputLocation_outputLocation_S3 = null;
            }
            if (requestOutputLocation_outputLocation_S3 != null)
            {
                request.OutputLocation.S3   = requestOutputLocation_outputLocation_S3;
                requestOutputLocationIsNull = false;
            }
            // determine if request.OutputLocation should be set to null
            if (requestOutputLocationIsNull)
            {
                request.OutputLocation = null;
            }

            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);
        }
 /// <summary>
 /// Sets the ACL property for this request.
 /// The S3 Object or S3 Bucket will be set to this
 /// S3AccessControlList.
 /// </summary>
 /// <param name="acl">The Canned ACL to be set on the object</param>
 /// <returns>The request with the ACL set</returns>
 public SetACLRequest WithACL(S3AccessControlList acl)
 {
     this.acl = acl;
     return this;
 }
Exemple #3
0
        public static void ACLSerial(String filePath)
        {
            System.Console.WriteLine("\nhello,ACL!!");
            NameValueCollection appConfig = ConfigurationManager.AppSettings;

            AmazonS3 s3Client = AWSClientFactory.CreateAmazonS3Client(appConfig["AWSAccessKey"], appConfig["AWSSecretKey"]);
            String bucketName = "chutest";
            String objectName = "hello";
            //versioning test
            String vbucketName = "netversion";

            //**********************************************************************************************************************************************************
            // Set Version test 環境,目前新增一專用 bucket = netversion,內有兩筆 Object 資訊(Object 已刪除,帶有 delete marker),為了測試方便,此環境不共用也不刪除
            // 若於佈板後刪除環境,請預先建立環境,執行132~150行程式
            //**********************************************************************************************************************************************************

            //PutBucket
            /*    System.Console.WriteLine("PutBucket-version: {0}\n", vbucketName);
                s3Client.PutBucket(new PutBucketRequest().WithBucketName(vbucketName));

                //PutBucketVersioning
                SetBucketVersioningResponse putVersioningResult = s3Client.SetBucketVersioning(new SetBucketVersioningRequest().WithBucketName(vbucketName).WithVersioningConfig(new S3BucketVersioningConfig().WithStatus("Enabled")));
                System.Console.WriteLine("PutBucketVersioning, requestID:{0}\n", putVersioningResult.RequestId);

                //PutObject
                System.Console.WriteLine("PutObject!");
                PutObjectRequest objectVersionRequest = new PutObjectRequest();
                objectVersionRequest.WithBucketName(vbucketName);
                objectVersionRequest.WithKey(objectName);
                objectVersionRequest.WithFilePath(filePath);
                PutObjectResponse objectVersionResult = s3Client.PutObject(objectVersionRequest);
                System.Console.WriteLine("Uploaded Object Etag: {0}\n", objectVersionResult.ETag);

                //DeleteObject
                System.Console.WriteLine("Delete Object!");
                s3Client.DeleteObject(new DeleteObjectRequest().WithBucketName(vbucketName).WithKey(objectName));
            */

            //PutBucket
            System.Console.WriteLine("PutBucket: {0}\n", bucketName);
            s3Client.PutBucket(new PutBucketRequest().WithBucketName(bucketName));

            //PutObject
            System.Console.WriteLine("PutObject!");
            PutObjectRequest request = new PutObjectRequest();
            request.WithBucketName(bucketName);
            request.WithKey(objectName);
            request.WithFilePath(filePath);
            PutObjectResponse PutResult = s3Client.PutObject(request);
            System.Console.WriteLine("Uploaded Object Etag: {0}\n", PutResult.ETag);

            //PutBucketACL
            SetACLRequest aclRequest = new SetACLRequest();
            S3AccessControlList aclConfig = new S3AccessControlList();
            aclConfig.WithOwner(new Owner().WithDisplayName("hrchu").WithId("canonicalidhrchu"));
            aclConfig.WithGrants(new S3Grant().WithGrantee(new S3Grantee().WithCanonicalUser("canonicalidhrchu","hrchu")).WithPermission(S3Permission.FULL_CONTROL));
            aclConfig.WithGrants(new S3Grant().WithGrantee(new S3Grantee().WithCanonicalUser("canonicalidannyren", "annyren")).WithPermission(S3Permission.READ_ACP));

            aclRequest.WithBucketName(bucketName);
            aclRequest.WithACL(aclConfig);

            SetACLResponse putBucketACLResult = s3Client.SetACL(aclRequest);
            System.Console.WriteLine("\nPutBucketACL, requestID:{0}",putBucketACLResult.RequestId);

            //GetBucketACL
            GetACLResponse getBucketACLResult = s3Client.GetACL(new GetACLRequest().WithBucketName(bucketName));
            System.Console.WriteLine("\nGetBucketACL Result:\n{0}\n",getBucketACLResult.ResponseXml);

            //**********************************************************************************************************************************************************

            //PutBucketACL (cannedacl)
            SetACLRequest cannedaclRequest = new SetACLRequest();
            cannedaclRequest.WithBucketName(bucketName);
            cannedaclRequest.WithCannedACL(S3CannedACL.PublicRead);

            SetACLResponse putBucketCannedACLResult = s3Client.SetACL(cannedaclRequest);
            System.Console.WriteLine("\nPutBucketCannedACL, requestID:{0}", putBucketCannedACLResult.RequestId);

            //GetBucketACL
            GetACLResponse getBucketCannedACLResult = s3Client.GetACL(new GetACLRequest().WithBucketName(bucketName));
            System.Console.WriteLine("\nGetBucketCannedACL Result:\n{0}\n", getBucketCannedACLResult.ResponseXml);

            //**********************************************************************************************************************************************************

            //PutObjectACL
            SetACLRequest objectACLRequest = new SetACLRequest();
            S3AccessControlList objectACLConfig = new S3AccessControlList();
            objectACLConfig.WithOwner(new Owner().WithDisplayName("hrchu").WithId("canonicalidhrchu"));
            objectACLConfig.WithGrants(new S3Grant().WithGrantee(new S3Grantee().WithCanonicalUser("canonicalidhrchu", "hrchu")).WithPermission(S3Permission.FULL_CONTROL));
            objectACLConfig.WithGrants(new S3Grant().WithGrantee(new S3Grantee().WithCanonicalUser("canonicalidannyren", "annyren")).WithPermission(S3Permission.WRITE_ACP));

            objectACLRequest.WithBucketName(bucketName);
            objectACLRequest.WithKey(objectName);
            objectACLRequest.WithACL(objectACLConfig);

            SetACLResponse putObjectACLResult = s3Client.SetACL(objectACLRequest);
            System.Console.WriteLine("\nPutObjectACL, requestID:{0}", putObjectACLResult.RequestId);

            //GetObjectACl
            GetACLResponse getObjectACLResult = s3Client.GetACL(new GetACLRequest().WithBucketName(bucketName).WithKey(objectName));
            System.Console.WriteLine("\nGetObjectACL Result:\n{0}\n", getObjectACLResult.ResponseXml);

            //**********************************************************************************************************************************************************

            //PutObjectACL (cannedacl)
            SetACLRequest objectCannedACLRequest = new SetACLRequest();

            objectCannedACLRequest.WithBucketName(bucketName);
            objectCannedACLRequest.WithKey(objectName);
            objectCannedACLRequest.WithCannedACL(S3CannedACL.PublicRead);

            SetACLResponse putObjectCannedACLResult = s3Client.SetACL(objectCannedACLRequest);
            System.Console.WriteLine("\nPutObjectCannedACL, requestID:{0}", putObjectCannedACLResult.RequestId);

            //GetObjectACl
            GetACLResponse getObjectCannedACLResult = s3Client.GetACL(new GetACLRequest().WithBucketName(bucketName).WithKey(objectName));
            System.Console.WriteLine("\nGetObjectCannedACL Result:\n{0}\n", getObjectCannedACLResult.ResponseXml);

            //**********************************************************************************************************************************************************

            //DeleteObject
            System.Console.WriteLine("Delete Object!");
            s3Client.DeleteObject(new DeleteObjectRequest().WithBucketName(bucketName).WithKey(objectName));
            //DeleteBucket
            System.Console.WriteLine("Delete Bucket!");
            s3Client.DeleteBucket(new DeleteBucketRequest().WithBucketName(bucketName));

            //PutObjectACL-version test*********************************************************************************************************************************
            String versionid = "784cca47e2a7423f97dedde6a72f9b3d";

            //PutObjectACL-versionid
              SetACLRequest objectVersionACLRequest = new SetACLRequest();
              S3AccessControlList objectVersionACLConfig = new S3AccessControlList();
              objectVersionACLConfig.WithOwner(new Owner().WithDisplayName("hrchu").WithId("canonicalidhrchu"));
              objectVersionACLConfig.WithGrants(new S3Grant().WithGrantee(new S3Grantee().WithCanonicalUser("canonicalidhrchu", "hrchu")).WithPermission(S3Permission.FULL_CONTROL));
              objectVersionACLConfig.WithGrants(new S3Grant().WithGrantee(new S3Grantee().WithCanonicalUser("canonicalidannyren", "annyren")).WithPermission(S3Permission.WRITE_ACP));

              objectVersionACLRequest.WithBucketName(vbucketName);
              objectVersionACLRequest.WithKey(objectName);
              objectVersionACLRequest.WithVersionId(versionid);
              objectVersionACLRequest.WithACL(objectVersionACLConfig);

              SetACLResponse putObjectVersionACLResult = s3Client.SetACL(objectVersionACLRequest);
              System.Console.WriteLine("\nPutObjectACL Version, requestID:{0}", putObjectVersionACLResult.RequestId);

              //GetObjectACl-versionid
              GetACLResponse getObjectVersionACLResult = s3Client.GetACL(new GetACLRequest().WithBucketName(vbucketName).WithKey(objectName).WithVersionId(versionid));
              System.Console.WriteLine("\nGetObjectACL Version Result:\n{0}\n", getObjectVersionACLResult.ResponseXml);

              //PutObjectACL (cannedacl)-versionid
              SetACLRequest objectVersionCannedACLRequest = new SetACLRequest();

              objectVersionCannedACLRequest.WithBucketName(vbucketName);
              objectVersionCannedACLRequest.WithKey(objectName);
              objectVersionCannedACLRequest.WithVersionId(versionid);
              objectVersionCannedACLRequest.WithCannedACL(S3CannedACL.PublicRead);

              SetACLResponse putObjectVersionCannedACLResult = s3Client.SetACL(objectVersionCannedACLRequest);
              System.Console.WriteLine("\nPutObjectCannedACL Version, requestID:{0}", putObjectVersionCannedACLResult.RequestId);

              //GetObjectACl(cannedacl)-versionid
              GetACLResponse getObjectVersionCannedACLResult = s3Client.GetACL(new GetACLRequest().WithBucketName(vbucketName).WithKey(objectName).WithVersionId(versionid));
              System.Console.WriteLine("\nGetObjectCannedACL Version Result:\n{0}\n", getObjectVersionCannedACLResult.ResponseXml);

            System.Console.WriteLine("END!");
        }
Exemple #4
0
 /// <summary>
 /// Sets the ACL property for this request.
 /// The S3 Object or S3 Bucket will be set to this
 /// S3AccessControlList.
 /// </summary>
 /// <param name="acl">The Canned ACL to be set on the object</param>
 /// <returns>The request with the ACL set</returns>
 public SetACLRequest WithACL(S3AccessControlList acl)
 {
     this.acl = acl;
     return(this);
 }
Exemple #5
0
 public void SetACL(S3AccessControlList acl)
 {
     var request = new PutACLRequest
     {
         BucketName = this.linker.s3.bucket,
         Key = this.linker.s3.key,
         AccessControlList = acl
     };
     this.s3ClientCache.GetClient(this.RegionAsEndpoint).PutACL(request);
 }
        private void setS3Permission(String bucketName, String key)
        {
            // Get the ACL for the file and retrieve the owner ID (not sure how to get it otherwise).
            GetACLRequest getAclRequest = new GetACLRequest().WithBucketName(bucketName).WithKey(key);
            GetACLResponse aclResponse = s3.GetACL(getAclRequest);
            Owner owner = aclResponse.AccessControlList.Owner;

            // Create a grantee as the MessageGears account
            S3Grantee grantee = new S3Grantee().WithCanonicalUser(properties.MessageGearsAWSCanonicalId, "MessageGears");

            // Grant MessageGears Read-only access
            S3Permission messageGearsPermission = S3Permission.READ;
            S3AccessControlList acl = new S3AccessControlList().WithOwner(owner);
            acl.AddGrant(grantee, messageGearsPermission);

            // Create a new ACL granting the owner full control.
            grantee = new S3Grantee().WithCanonicalUser(owner.Id, "MyAWSId");
            acl.AddGrant(grantee, S3Permission.FULL_CONTROL);
            SetACLRequest aclRequest = new SetACLRequest().WithACL(acl).WithBucketName(bucketName).WithKey(key);
            s3.SetACL(aclRequest);
        }
        public void BucketC_SetACLForBucketTest_ForException_WithoutACLOwner()
        {
            S3AccessControlList list = new S3AccessControlList();
            list.AddGrant(new S3Grantee()
            {
                CanonicalUser = new Amazon.S3.Model.Tuple<string, string> { First = CanonicalUserID, Second = "Me" }
            }, S3Permission.FULL_CONTROL);

            SetACLRequest request = new SetACLRequest { BucketName = _bucketNameForBucketAPIs, ACL = list };

            _client.SetACL(request);
            EnqueueTestComplete();
        }
        public void BucketC_SetACLForBucketTest()
        {
            bool expectedValue = true;
            bool actualValue = false;
            bool hasCallbackArrived = false;

            S3ResponseEventHandler<object, ResponseEventArgs> handler = null;
            handler = delegate(object sender, ResponseEventArgs args)
            {
                IS3Response result = args.Response;
                //Unhook from event.
                _client.OnS3Response -= handler;
                SetACLResponse response = result as SetACLResponse;
                if (null != response)
                    actualValue = response.IsRequestSuccessful;
                hasCallbackArrived = true;
            };

            _client.OnS3Response += handler;

            S3AccessControlList list = new S3AccessControlList();
            list.AddGrant(new S3Grantee()
            {
                CanonicalUser = new Amazon.S3.Model.Tuple<string, string> { First = CanonicalUserID, Second = "Me" }
            }, S3Permission.FULL_CONTROL);

            list.AddGrant(new S3Grantee()
            {
                URI = "http://acs.amazonaws.com/groups/s3/LogDelivery"
            }, S3Permission.WRITE);

            list.AddGrant(new S3Grantee()
            {
                URI = "http://acs.amazonaws.com/groups/s3/LogDelivery",
            }, S3Permission.READ_ACP);

            list.Owner = new Owner { DisplayName = "Me", Id = CanonicalUserID };

            SetACLRequest request = new SetACLRequest { BucketName = _bucketNameForBucketAPIs, ACL = list };

            _client.SetACL(request);

            EnqueueConditional(() => hasCallbackArrived);
            EnqueueCallback(() => Assert.IsTrue(expectedValue == actualValue,
                string.Format("Expected Value = {0}, Actual Value = {1}", expectedValue, actualValue)));
            EnqueueTestComplete();
        }
        public void Test_I_SetObjectACL_With_Invalid_GranteeCanonicalUserID_And_Check_For_Error_Message()
        {
            bool hasCallbackArrived = false;
            string actualValue = string.Empty;
            string expectedValue = "InvalidArgument";
            string invalidGranteeCanonicalUserID = "09876567890"; //For more info on CanonicalUserIDs refer CanonicalUserID variable.

            S3ResponseEventHandler<object, ResponseEventArgs> handler = null;

            handler = delegate(object sender, ResponseEventArgs args)
            {
                IS3Response result = args.Response;
                //Unhook from event.
                _client.OnS3Response -= handler;
                AmazonS3Exception exceptionResponse = result as AmazonS3Exception;

                if (null != exceptionResponse)
                    actualValue = exceptionResponse.ErrorCode;

                hasCallbackArrived = true;
            };

            //Hook to event
            _client.OnS3Response += handler;

            //Create request object.
            S3AccessControlList list = new S3AccessControlList();
            list.AddGrant(new S3Grantee
            {
                CanonicalUser = new Amazon.S3.Model.Tuple<string, string> { First = invalidGranteeCanonicalUserID, Second = "Me" }
            }, S3Permission.FULL_CONTROL);

            list.Owner = new Owner { DisplayName = "Me", Id = CanonicalUserID };
            SetACLRequest request = new SetACLRequest { BucketName = _bucketName, Key = _key, ACL = list };

            _client.SetACL(request);

            EnqueueConditional(() => hasCallbackArrived);
            EnqueueCallback(() => Assert.IsTrue(expectedValue == actualValue));
            EnqueueTestComplete();
        }
        public void Test_G_SetObjectACL_And_Check_For_Boolean_Result()
        {
            bool hasCallbackArrived = false;
            bool actualValue = false;
            bool expectedValue = true;

            S3ResponseEventHandler<object, ResponseEventArgs> handler = null;

            handler = delegate(object sender, ResponseEventArgs args)
            {
                IS3Response result = args.Response;
                //Unhook from event.
                _client.OnS3Response -= handler;
                SetACLResponse response = result as SetACLResponse;

                if (null != response)
                    actualValue = response.IsRequestSuccessful;

                hasCallbackArrived = true;
            };

            //Hook to event
            _client.OnS3Response += handler;

            //Create request object.
            S3AccessControlList list = new S3AccessControlList();
            list.AddGrant(new S3Grantee
            {
                CanonicalUser = new Amazon.S3.Model.Tuple<string, string> { First = CanonicalUserID, Second = "Me" }
            }, S3Permission.FULL_CONTROL);

            list.Owner = new Owner { DisplayName = "Me", Id = CanonicalUserID };
            SetACLRequest request = new SetACLRequest { BucketName = _bucketName, Key = _key, ACL = list };

            _client.SetACL(request);

            EnqueueConditional(() => hasCallbackArrived);
            EnqueueCallback(() => Assert.IsTrue(expectedValue == actualValue));
            EnqueueTestComplete();
        }
        public void AclSamples()
        {
            {
                #region PutACL Sample 1

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Set Canned ACL (PublicRead) for an existing item
                client.PutACL(new PutACLRequest
                {
                    BucketName = "SampleBucket",
                    Key = "Item1",
                    CannedACL = S3CannedACL.PublicRead
                });

                // Set Canned ACL (PublicRead) for an existing item
                // (This reverts ACL back to default for object)
                client.PutACL(new PutACLRequest
                {
                    BucketName = "SampleBucket",
                    Key = "Item1",
                    CannedACL = S3CannedACL.Private
                });

                #endregion
            }

            {
                #region GetACL\PutACL Samples

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Retrieve ACL for object
                S3AccessControlList acl = client.GetACL(new GetACLRequest
                {
                    BucketName = "SampleBucket",
                    Key = "Item1",
                }).AccessControlList;

                // Retrieve owner
                Owner owner = acl.Owner;


                // Describe grant
                S3Grant grant = new S3Grant
                {
                    Grantee = new S3Grantee { EmailAddress = "*****@*****.**" },
                    Permission = S3Permission.WRITE_ACP
                };

                // Create new ACL
                S3AccessControlList newAcl = new S3AccessControlList
                {
                    Grants = new List<S3Grant> { grant },
                    Owner = owner
                };

                // Set new ACL
                PutACLResponse response = client.PutACL(new PutACLRequest
                {
                    BucketName = "SampleBucket",
                    Key = "Item1",
                    AccessControlList = acl
                });

                #endregion
            }
        }