本文整理汇总了Python中pynimbusauthz.objects.File类的典型用法代码示例。如果您正苦于以下问题:Python File类的具体用法?Python File怎么用?Python File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_single_change
def test_single_change(self):
name = "/file/name"
old_base = "/OLD"
new_base = "/NEW"
data = "/etc/group"
key = old_base + data
file1 = File.create_file(self.db, name, self.user1, key, pynimbusauthz.object_type_s3)
self.db.commit()
rc = pynimbusauthz.rebase.main([old_base, new_base])
self.assertEqual(rc, 0, "rc should be 0, is %d" % (rc))
f2a = File.find_files_from_data(self.db, key)
f2a = list(f2a)
self.assertEqual(len(f2a), 0, "should be no values with key %s len is %d" % (old_base, len(f2a)))
key = new_base + data
f2a = File.find_files_from_data(self.db, key)
f2a = list(f2a)
self.assertNotEqual(len(f2a), 0, "length should be greater than 0 is %d" % (len(f2a)))
found = False
for f2 in f2a:
tst_key = f2.get_data_key()
if tst_key == key:
found = True
self.assertTrue(found, "key not found")
示例2: main
def main(argv=sys.argv[1:]):
try:
con_str = pynimbusauthz.get_db_connection_string()
db_obj = DB(con_str=con_str)
(opts,args) = setup_options(argv)
if len(args) > 0:
u_pattern = args[0]
else:
u_pattern = ""
parent = None
if opts.parent != None:
parent = File.get_file(db_obj, opts.parent, opts.type)
if parent == None:
raise AuthzException(['FILE_EXISTS'], "parent %s not found" % (opts.parent))
if opts.type == "all":
types = pynimbusauthz.object_types.keys()
else:
types = [opts.type]
for t in types:
files = File.find_files(db_obj, u_pattern, t, parent)
for f in files:
print_file(opts, f)
except AuthzException, ae:
print ae
return ae.get_rc()
示例3: main
def main(argv=sys.argv[1:]):
try:
con_str = pynimbusauthz.get_db_connection_string()
db_obj = DB(con_str=con_str)
(opts,args) = setup_options(argv)
if len(args) != 3:
raise AuthzException('CLI_PARAMETER', "You must specify a username filename permssions")
user_name = args[0]
object_name = args[1]
requested_perms = args[2]
parent = None
if opts.parent != None:
parent = File.get_file(db_obj, opts.parent, opts.type)
if parent == None:
raise AuthzException('FILE_EXISTS', "parent %s not found" % (opts.parent))
file1 = File.get_file(db_obj, object_name, opts.type, parent=parent)
if file1 == None:
raise AuthzException('FILE_EXISTS', "file %s:%s not found" % (opts.type, object_name))
user = User(db_obj, uu=user_name)
uf = UserFile(file1) # create a uesrfile with owner so we can chmod
uf.chmod(requested_perms, user=user)
pynimbusauthz.print_msg(opts, 0, "changed %s to %s for %s" % (str(file1), requested_perms, str(user)))
db_obj.commit()
except AuthzException, ae:
print ae
return ae.get_rc()
示例4: main
def main(argv=sys.argv[1:]):
try:
con_str = pynimbusauthz.get_db_connection_string()
db_obj = DB(con_str=con_str)
(opts, args) = setup_options(argv)
if len(args) != 3:
raise AuthzException("CLI_PARAMETER", "You must specify a username filename and a datakey\nTry --help")
user_name = args[0]
object_name = args[1]
data = args[2]
user = User(db_obj, uu=user_name)
parent = None
if opts.parent != None:
parent = File.get_file(db_obj, opts.parent, opts.type)
if parent == None:
raise AuthzException("FILE_EXISTS", "parent %s not found" % (opts.parent))
File.create_file(db_obj, object_name, user, data, opts.type, parent=parent)
except AuthzException, ae:
print ae
return ae.get_rc()
示例5: get_file_obj
def get_file_obj(self, bucketName, objectName=None):
file = File.get_file(self.db_obj, bucketName, pynimbusauthz.object_type_s3)
if file == None:
return None
if objectName != None:
file = File.get_file(self.db_obj, objectName, pynimbusauthz.object_type_s3, file)
return file
示例6: test_basic_touch
def test_basic_touch(self):
fname = str(uuid.uuid1())
data = str(uuid.uuid1())
f = File.get_file(self.db, fname, pynimbusauthz.object_type_s3)
self.assertEqual(f, None)
rc = pynimbusauthz.touch.main([self.user1.get_id(), fname, data])
self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
f = File.get_file(self.db, fname, pynimbusauthz.object_type_s3)
self.assertNotEqual(f, None)
示例7: test_bucket
def test_bucket(self):
# create a file and a bucket
b1 = File.create_file(self.db, "bucket", self.user1, self.data, pynimbusauthz.object_type_s3)
f2 = File.create_file(self.db, self.name, self.user1, self.data, pynimbusauthz.object_type_s3, parent=b1)
self.db.commit()
new_perms = "WR"
rc = pynimbusauthz.chmod.main(["-t", f2.get_object_type(), "-p", b1.get_name(), self.user1.get_id(), f2.get_name(), new_perms])
self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
示例8: get_file_obj
def get_file_obj(self, bucketName, objectName=None):
pycb.log(logging.INFO, "===== def get_file_obj of cbAuthzSecurity.py")
file = File.get_file(self.db_obj, bucketName, pynimbusauthz.object_type_s3)
pycb.log(logging.INFO, "=====## file is %s"%file)
if file == None:
return None
if objectName != None:
file = File.get_file(self.db_obj, objectName, pynimbusauthz.object_type_s3, file)
pycb.log(logging.INFO, "=====## file is %s"%file)
return file
示例9: test_under_bucket_touch
def test_under_bucket_touch(self):
bname = str(uuid.uuid1())
fname = str(uuid.uuid1())
data = str(uuid.uuid1())
rc = pynimbusauthz.touch.main(["-t", pynimbusauthz.object_type_s3, self.user1.get_id(), bname, data])
self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
rc = pynimbusauthz.touch.main(["-p", bname, self.user1.get_id(), fname, data])
self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
b1 = File.get_file(self.db, bname, pynimbusauthz.object_type_s3)
f1 = File.get_file(self.db, fname, pynimbusauthz.object_type_s3, parent=b1)
self.assertNotEqual(b1, None)
self.assertNotEqual(f1, None)
示例10: test_find_by_key
def test_find_by_key(self):
user1 = User(self.db)
name = "/file/name"
key = "/old/path/base"
f = File.create_file(self.db, name, user1, key, pynimbusauthz.object_type_s3)
self.db.commit()
f2a = File.find_files_from_data(self.db, key)
found = False
for f2 in f2a:
tst_key = f2.get_data_key()
if tst_key == key:
found = True
self.assertTrue(found, "key not found")
示例11: validate_perms
def validate_perms(self, new):
f = File.get_file_from_db_id(self.db, self.file1.get_id())
uf = UserFile(f, self.user1)
perms = uf.get_perms(force=True)
for p in new:
self.assertTrue(p in perms, "bad perms set %s != %s" % (new, perms))
self.assertEqual(len(perms), len(new), "perms dont match %s != %s" % (new, perms))
示例12: get_my_buckets
def get_my_buckets(self):
try:
file_iterater = File.get_user_files(self.db_obj, self.user, root=True)
new_it = itertools.imap(lambda r: _convert_bucket_to_cbObject(self, r), file_iterater)
return list(new_it)
finally:
self.db_obj.commit()
示例13: list_bucket
def list_bucket(self, bucketName, args):
clause = " ORDER BY name"
prefix = None
if 'prefix' in args:
prefix = args['prefix'][0]
prefix = "%s%%" % (prefix)
limit = None
if 'max-keys' in args:
max_a = args['max-keys']
limit = int(max_a[0])
if 'delimiter' in args:
pass
if 'key-marker' in args:
km = args['key-marker'][0]
clause = " and name > '%s'" % (km)
try:
bucket = File.get_file(self.db_obj, bucketName, pynimbusauthz.alias_type_s3)
iter = bucket.get_all_children(limit=limit, match_str=prefix, clause=clause)
new_it = itertools.imap(lambda r: _convert_File_to_cbObject(self, r), iter)
return list(new_it)
finally:
self.db_obj.commit()
示例14: get_my_buckets
def get_my_buckets(self):
pycb.log(logging.INFO, "===== def get_my_buckets of cbAuthzSecurity.py")
try:
file_iterater = File.get_user_files(self.db_obj, self.user, root=True)
new_it = itertools.imap(lambda r: _convert_bucket_to_cbObject(self, r), file_iterater)
return list(new_it)
finally:
self.db_obj.commit()
示例15: main
def main(argv=sys.argv[1:]):
try:
repo_dir = argv[0]
con_str = pynimbusauthz.get_db_connection_string()
db_obj = DB(con_str=con_str)
user = User(db_obj, uu="CumulusPublicUser")
if user == None:
raise Exception("No public user")
File.create_file(db_obj, repo_dir, user, repo_dir, pynimbusauthz.alias_type_s3)
db_obj.commit()
except:
raise
return 0