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 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 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_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(); }