Пример #1
0
        public override GetObjectAclResponse ParseGetObjectAclResponse(HttpResponse httpResponse)
        {
            GetObjectAclResponse response = new GetObjectAclResponse();

            response.AccessControlList = this.ParseAccessControlList(httpResponse, false);
            return(response);
        }
        static void GetObjectACL()
        {
            try
            {
                GetObjectAclRequest request = new GetObjectAclRequest()
                {
                    BucketName = bucketName,
                    ObjectKey  = objectName
                };
                GetObjectAclResponse response = client.GetObjectAcl(request);

                Console.WriteLine("Get object acl response: {0}.", response.StatusCode);

                foreach (Grant grant in response.AccessControlList.Grants)
                {
                    CanonicalGrantee grantee = (CanonicalGrantee)grant.Grantee;
                    Console.WriteLine("Grantee canonical user id: {0}", grantee.Id);
                    Console.WriteLine("Grantee canonical user display name: {0}", grantee.DisplayName);
                    Console.WriteLine("Grant permission: {0}", grant.Permission);
                }
            }
            catch (ObsException ex)
            {
                Console.WriteLine("Exception errorcode: {0}, when get object acl.", ex.ErrorCode);
                Console.WriteLine("Exception errormessage: {0}", ex.ErrorMessage);
            }
        }
Пример #3
0
        public async Task PutGetObjectAcl()
        {
            string objectKey = nameof(PutGetObjectAcl);

            //Create an object
            await UploadAsync(objectKey).ConfigureAwait(false);

            //Get the ACL, which should be the default one (owner has ACL)
            GetObjectAclResponse getResp = await ObjectClient.GetObjectAclAsync(BucketName, objectKey).ConfigureAwait(false);

            Assert.True(getResp.IsSuccess);

            S3Grant grant = Assert.Single(getResp.Grants);

            Assert.Equal(TestConstants.TestUserId, grant.Id);
            Assert.Equal(TestConstants.TestUsername, grant.Name);
            Assert.Equal(Permission.FullControl, grant.Permission);
            Assert.Equal(GrantType.User, grant.Type);

            //Update the object to have another ACL using Canned ACLs
            PutObjectAclResponse putResp = await ObjectClient.PutObjectAclAsync(BucketName, objectKey, req => req.Acl = ObjectCannedAcl.PublicReadWrite).ConfigureAwait(false);

            Assert.True(putResp.IsSuccess);

            GetObjectAclResponse getResp2 = await ObjectClient.GetObjectAclAsync(BucketName, objectKey).ConfigureAwait(false);

            Assert.True(getResp2.IsSuccess);

            Assert.Equal(TestConstants.TestUserId, getResp2.Owner.Id);
            Assert.Equal(TestConstants.TestUsername, getResp2.Owner.Name);

            Assert.Equal(3, getResp2.Grants.Count);

            //This is the default owner ACL
            S3Grant first = getResp2.Grants[0];

            Assert.Equal(TestConstants.TestUserId, first.Id);
            Assert.Equal(TestConstants.TestUsername, first.Name);
            Assert.Equal(Permission.FullControl, first.Permission);
            Assert.Equal(GrantType.User, first.Type);

            //Next 2 ACLs should be READ + WRITE for AllUsers
            S3Grant second = getResp2.Grants[1];

            Assert.Equal("http://acs.amazonaws.com/groups/global/AllUsers", second.Uri);
            Assert.Equal(Permission.Read, second.Permission);
            Assert.Equal(GrantType.Group, second.Type);

            S3Grant third = getResp2.Grants[2];

            Assert.Equal("http://acs.amazonaws.com/groups/global/AllUsers", third.Uri);
            Assert.Equal(Permission.Write, third.Permission);
            Assert.Equal(GrantType.Group, third.Type);
        }
Пример #4
0
    public async Task PutGetObjectAcl(S3Provider provider, string bucket, ISimpleClient client)
    {
        string objectKey = nameof(PutGetObjectAcl);

        //Create an object
        PutObjectResponse putResp1 = await client.PutObjectAsync(bucket, objectKey, null).ConfigureAwait(false);

        Assert.Equal(200, putResp1.StatusCode);

        //Get the ACL, which should be the default one (owner has ACL)
        GetObjectAclResponse getResp = await client.GetObjectAclAsync(bucket, objectKey).ConfigureAwait(false);

        Assert.Equal(200, getResp.StatusCode);

        S3Grant?grant = Assert.Single(getResp.Grants);

        Assert.Equal(S3Permission.FullControl, grant.Permission);

        if (provider == S3Provider.AmazonS3)
        {
            Assert.Equal(GrantType.CanonicalUser, grant.Grantee.Type);
            Assert.Equal(TestConstants.TestUserId, grant.Grantee.Id);
            Assert.Equal(TestConstants.TestUsername, grant.Grantee.DisplayName);
        }

        //Update the object to have another ACL using Canned ACLs
        PutObjectAclResponse putResp2 = await client.PutObjectAclAsync(bucket, objectKey, r => r.Acl = ObjectCannedAcl.PublicRead).ConfigureAwait(false);

        Assert.Equal(200, putResp2.StatusCode);

        GetObjectAclResponse getResp2 = await client.GetObjectAclAsync(bucket, objectKey).ConfigureAwait(false);

        Assert.Equal(200, getResp2.StatusCode);
        Assert.Equal(2, getResp2.Grants.Count);

        if (provider == S3Provider.AmazonS3)
        {
            Assert.Equal(TestConstants.TestUserId, getResp2.Owner.Id);
            Assert.Equal(TestConstants.TestUsername, getResp2.Owner.Name);
        }

        //This is the default owner ACL
        S3Grant first = getResp2.Grants[0];

        if (provider == S3Provider.AmazonS3)
        {
            Assert.Equal(TestConstants.TestUserId, first.Grantee.Id);
            Assert.Equal(TestConstants.TestUsername, first.Grantee.DisplayName);
            Assert.Equal(GrantType.CanonicalUser, first.Grantee.Type);
        }

        Assert.Equal(S3Permission.FullControl, first.Permission);

        //Next 2 ACLs should be READ + WRITE for AllUsers
        S3Grant second = getResp2.Grants[1];

        Assert.Equal("http://acs.amazonaws.com/groups/global/AllUsers", second.Grantee.Uri);
        Assert.Equal(S3Permission.Read, second.Permission);
        Assert.Equal(GrantType.Group, second.Grantee.Type);

        //if (provider == S3Provider.AmazonS3)
        //{
        //    S3Grant third = getResp2.Grants[2];
        //    Assert.Equal("http://acs.amazonaws.com/groups/global/AllUsers", third.Grantee.Uri);
        //    Assert.Equal(S3Permission.Write, third.Permission);
        //    Assert.Equal(GrantType.Group, third.Grantee.Type);
        //}
    }