本文整理汇总了Python中pynimbusauthz.objects.File.get_file方法的典型用法代码示例。如果您正苦于以下问题:Python File.get_file方法的具体用法?Python File.get_file怎么用?Python File.get_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pynimbusauthz.objects.File
的用法示例。
在下文中一共展示了File.get_file方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_file_obj
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import get_file [as 别名]
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
示例2: main
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import get_file [as 别名]
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()
示例3: test_basic_touch
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import get_file [as 别名]
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)
示例4: get_file_obj
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import get_file [as 别名]
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
示例5: test_under_bucket_touch
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import get_file [as 别名]
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)
示例6: main
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import get_file [as 别名]
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()
示例7: list_bucket
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import get_file [as 别名]
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()
示例8: main
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import get_file [as 别名]
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()
示例9: test_file_and_bucket
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import get_file [as 别名]
def test_file_and_bucket(self):
user1 = User(self.db)
fname = "NAME"
data = "data"
b1 = File.create_file(self.db, "bucket", user1, data, pynimbusauthz.object_type_s3)
f1 = File.create_file(self.db, fname, user1, data, pynimbusauthz.object_type_s3, parent=b1)
f2 = File.create_file(self.db, fname, user1, data, pynimbusauthz.object_type_s3)
self.db.commit()
self.assertNotEqual(f1.get_id(), f2.get_id())
f3 = File.get_file(self.db, fname, pynimbusauthz.object_type_s3, parent=b1)
f4 = File.get_file(self.db, fname, pynimbusauthz.object_type_s3)
self.assertEqual(f1.get_id(), f3.get_id())
self.assertEqual(f2.get_id(), f4.get_id())
self.assertNotEqual(f3.get_id(), f4.get_id())
self.db.commit()
示例10: main
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import get_file [as 别名]
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:
raise AuthzException('CLI_PARAMETER', "You must specify a filename")
parent = None
if opts.parent != None:
parent = File.get_file(db_obj, opts.parent, opts.type)
if parent == None:
raise AuthzException('FILE_EXISTS', "bucket %s not found" % (opts.parent))
object_name = args[0]
file1 = File.get_file(db_obj, object_name, opts.type, parent=parent)
if file1 == None:
pynimbusauthz.print_msg(opts, 0, "File not found")
return
uf = UserFile(file1)
msg = "%10s\t%10s\t%10s\t%10s\t%10s" % ("file", "type", "owner", "user", "perms")
pynimbusauthz.print_msg(opts, 1, msg)
n = uf.get_file().get_name()
t = uf.get_file().get_object_type()
stat_print_uf(opts, uf, n, t)
if opts.all:
user_list = uf.get_file().get_all_users()
for u in user_list:
uf = UserFile(uf.get_file(), u)
stat_print_uf(opts, uf, " ", " ")
except AuthzException, ae:
print ae
return ae.get_rc()
示例11: test_change_key
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import get_file [as 别名]
def test_change_key(self):
user1 = User(self.db)
name = "/file/name"
old_base = "/old/path/base"
fname = "/etc/group"
new_base = "/new/base/location/dir"
f = File.create_file(self.db, name, user1, old_base + fname, pynimbusauthz.object_type_s3)
self.assertEqual(old_base + fname, f.get_data_key(), "old value not euqal")
new_key = new_base + fname
f.set_data_key(new_key)
self.db.commit()
tst_new_key = f.get_data_key()
self.assertEqual(tst_new_key, new_key, "%s should equal %s" % (tst_new_key, new_key))
f2 = File.get_file(self.db, name, pynimbusauthz.object_type_s3)
tst_new_key = f2.get_data_key()
self.assertEqual(tst_new_key, new_key, "%s should equal %s" % (tst_new_key, new_key))
示例12: test_find_no_file
# 需要导入模块: from pynimbusauthz.objects import File [as 别名]
# 或者: from pynimbusauthz.objects.File import get_file [as 别名]
def test_find_no_file(self):
f = File.get_file_from_db_id(self.db, 1000)
self.assertEqual(f, None, "We should not have found that file")
f = File.get_file(self.db, "nofile", pynimbusauthz.object_type_s3)
self.assertEqual(f, None, "We should not have found that file")