def test_bucket_acl(self): print(self.bucket_name) self.client.get_bucket_acl(self.bucket_name) bucketAcl = AccessControlList() bucketAcl.add_grant(Grant(Grantee("111"), Permission.READ)) bucketAcl.add_grant(Grant(Grantee('109901'), Permission.FULL_CONTROL)) bucketAcl.add_grant(Grant(Grantee('123456'), Permission.SSO_WRITE)) bucketAcl.add_grant(Grant(Grantee(appid), Permission.FULL_CONTROL)) self.client.set_bucket_acl(self.bucket_name, bucketAcl) aclListGot = self.client.get_bucket_acl(self.bucket_name) readAclCnt = 0 fullControlCnt = 0 writeWithSSOCnt = 0 for i in aclListGot.get_grant_list(): if i['grantee']['id'] == '111': self.assertTrue(i['permission'].to_string() == Permission( Permission.READ).to_string()) readAclCnt += 1 elif i['grantee']['id'] == '109901': self.assertTrue(i['permission'].to_string() == Permission( Permission.FULL_CONTROL).to_string()) fullControlCnt += 1 elif i['grantee']['id'] == '123456': self.assertTrue(i['permission'].to_string() == Permission( Permission.SSO_WRITE).to_string()) writeWithSSOCnt += 1 self.assertTrue(readAclCnt == 1) self.assertTrue(fullControlCnt == 1) self.assertTrue(writeWithSSOCnt == 1) # self.client.set_bucket_acl(self.bucket_name, bucketAcl) acl = self.client.get_bucket_acl(self.bucket_name) self.assertTrue(bucketAcl.is_subset(acl)) acl_client = GalaxyFDSClient( acl_ak, acl_access_secret, FDSClientConfiguration(region_name, False, False, False, endpoint=endpoint)) object_name = "testBucketAcl7" acl_client.put_object(self.bucket_name, object_name, "hahhah") self.assertTrue( self.client.does_object_exists(self.bucket_name, object_name)) acl_client.list_objects(self.bucket_name) acl_client.delete_object(self.bucket_name, object_name) self.assertFalse( self.client.does_object_exists(self.bucket_name, object_name)) self.assertTrue(acl_client.does_bucket_exist(self.bucket_name)) try: acl_client.delete_bucket(self.bucket_name) except GalaxyFDSClientException as e: print(e.message) self.assertTrue(self.client.does_bucket_exist(self.bucket_name))
def test_bucket_acl(self): print(self.bucket_name) self.client.get_bucket_acl(self.bucket_name) bucketAcl = AccessControlList() bucketAcl.add_grant(Grant(Grantee("111"), Permission.READ)) bucketAcl.add_grant(Grant(Grantee('109901'), Permission.FULL_CONTROL)) bucketAcl.add_grant(Grant(Grantee('123456'), Permission.SSO_WRITE)) bucketAcl.add_grant(Grant(Grantee(app_id), Permission.FULL_CONTROL)) self.client.set_bucket_acl(self.bucket_name, bucketAcl) aclListGot = self.client.get_bucket_acl(self.bucket_name) readAclCnt = 0 fullControlCnt = 0 writeWithSSOCnt = 0 for i in aclListGot.get_grant_list(): if i['grantee']['id'] == '111': self.assertTrue(i['permission'].to_string() == Permission(Permission.READ).to_string()) readAclCnt += 1 elif i['grantee']['id'] == '109901': self.assertTrue( i['permission'].to_string() == Permission(Permission.FULL_CONTROL).to_string()) fullControlCnt += 1 elif i['grantee']['id'] == '123456': self.assertTrue(i['permission'].to_string() == Permission(Permission.SSO_WRITE).to_string()) writeWithSSOCnt += 1 self.assertTrue(readAclCnt == 1) self.assertTrue(fullControlCnt == 1) self.assertTrue(writeWithSSOCnt == 1) # self.client.set_bucket_acl(self.bucket_name, bucketAcl) acl = self.client.get_bucket_acl(self.bucket_name) self.assertTrue(bucketAcl.is_subset(acl)) acl_client = GalaxyFDSClient(acl_ak, acl_access_secret, FDSClientConfiguration(region_name, False, False, False, endpoint=endpoint)) object_name = "testBucketAcl7" acl_client.put_object(self.bucket_name, object_name, "hahhah") self.assertTrue( self.client.does_object_exists(self.bucket_name, object_name)) acl_client.list_objects(self.bucket_name) acl_client.delete_object(self.bucket_name, object_name) self.assertFalse( self.client.does_object_exists(self.bucket_name, object_name)) self.assertTrue(acl_client.does_bucket_exist(self.bucket_name))
buckets = fds_client.list_buckets() print('buckets list:') for bucket in buckets: print(bucket) print("---end---") # Check and create the bucket if not fds_client.does_bucket_exist(bucket_name): fds_client.create_bucket(bucket_name) ##################### ##################### # Put a string object object_name = 'test1.txt' object_content = 'Hello world! This is a simple test!' fds_client.put_object(bucket_name, object_name, object_content) # Get the object content obj = fds_client.get_object(bucket_name, object_name) for chunk in obj.stream: sys.stdout.write(chunk) print('\n') # Download the object file data_file = "/tmp/fds_file" fds_client.download(bucket_name, object_name, data_file) data_file2 = "/tmp/fds_file2" fds_client.download_object_with_uri("fds://" + bucket_name + "/" + object_name, data_file2) # Delete the object
buckets = fds_client.list_buckets() print 'buckets list:' for bucket in buckets: print bucket print # Check and create the bucket if not fds_client.does_bucket_exist(bucket_name): fds_client.create_bucket(bucket_name) ##################### ##################### # Put a string object object_name = 'test1.txt' object_content = 'Hello world! This is a simple test!' fds_client.put_object(bucket_name, object_name, object_content) # Get the object content obj = fds_client.get_object(bucket_name, object_name) for chunk in obj.stream: sys.stdout.write(chunk) print '\n' # Download the object file data_file = "/tmp/fds_file" client.download(bucket_name, object_name, data_file) data_file2 = "/tmp/fds_file2" client.download_object_with_uri("fds://" + bucket_name + "/" + object_name, data_file2) # Delete the object fds_client.delete_object(bucket_name, object_name)