• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python db.DB类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pynimbusauthz.db.DB的典型用法代码示例。如果您正苦于以下问题:Python DB类的具体用法?Python DB怎么用?Python DB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DB类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: create_user

 def create_user(self, display_name, id, pw, opts):
     pycb.log(logging.INFO, "===== def create_user of cbAuthzSecurity.py")
     db_obj = DB(con_str=self.con_str)
     user = User(db_obj, friendly=display_name)
     user_alias = user.create_alias(id, "s3", display_name, alias_data=pw)
     db_obj.commit()
     db_obj.close()
开发者ID:xxy-php,项目名称:code,代码行数:7,代码来源:cbAuthzSecurity.py


示例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) != 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)
        db_obj.commit()
    except AuthzException, ae:
        print ae
        return ae.get_rc()
开发者ID:Annatara,项目名称:nimbus,代码行数:25,代码来源:touch.py


示例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()
开发者ID:Annatara,项目名称:nimbus,代码行数:32,代码来源:chmod.py


示例4: TestLsCli

class TestLsCli(unittest.TestCase):

    def setUp(self):
        (osf, self.fname) = tempfile.mkstemp()
        os.close(osf)
# os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql"
        os.environ['NIMBUS_AUTHZ_DB'] = self.fname
        pynimbusauthz.db.make_test_database(self.fname)
        self.db = DB(con_str=self.fname)
        self.user1 = User(self.db)
        self.name = "/file/name"
        self.data = "/etc/group"
        self.file1 = File.create_file(self.db, self.name, self.user1, self.data, pynimbusauthz.object_type_s3)
        self.uf = UserFile(self.file1)
        self.db.commit()

    def tearDown(self):
        self.db.close()
        os.remove(self.fname)

    def test_basic_ls(self):
        rc = pynimbusauthz.ls.main([])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        rc = pynimbusauthz.ls.main(["-t", pynimbusauthz.object_type_s3])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        rc = pynimbusauthz.ls.main([self.name[0:-1]])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))


    def test_fail_ls(self):
        rc = pynimbusauthz.ls.main(["-p", "nobucket", self.name[0:-1]])
        self.assertNotEqual(rc, 0, "CLI should return success %d" % (rc))
开发者ID:Annatara,项目名称:nimbus,代码行数:32,代码来源:test_ls.py


示例5: TestTouchCli

class TestTouchCli(unittest.TestCase):

    def setUp(self):
        (osf, self.fname) = tempfile.mkstemp()
        os.close(osf)
#        os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql"
        os.environ['NIMBUS_AUTHZ_DB'] = self.fname
        pynimbusauthz.db.make_test_database(self.fname)
        self.db = DB(con_str=self.fname)
        self.user1 = User(self.db)
        self.db.commit()

    def tearDown(self):
        self.db.close()
        os.remove(self.fname)

    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)

    def test_bucket_touch(self):
        fname = str(uuid.uuid1())
        data = str(uuid.uuid1())
        rc = pynimbusauthz.touch.main(["-t", pynimbusauthz.object_type_s3, 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)

    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)


    def test_bad_opts(self):
        bname = str(uuid.uuid1())
        fname = str(uuid.uuid1())
        data = str(uuid.uuid1())
        rc = pynimbusauthz.touch.main([bname, data])
        self.assertEqual(rc, 32, "CLI should return failure %d" % (rc))
        rc = pynimbusauthz.touch.main(["-p", bname, self.user1.get_id(), fname, data])
        self.assertEqual(rc, 33, "CLI should return failure %d" % (rc))
开发者ID:Annatara,项目名称:nimbus,代码行数:59,代码来源:test_touch.py


示例6: get_user_object_by_access_id

 def get_user_object_by_access_id(self, access_id):
     """Get a new connection every time this is called to make sure it is cleaned up"""
     db = DB(self._cumulus_db)
     user_alias = User.find_alias(db, access_id)
     if not user_alias:
         raise PhantomAWSException('InvalidClientTokenId')
     l = list(user_alias)
     db.close()
     if l < 1:
         raise PhantomAWSException('InvalidClientTokenId')
     return PhantomUserObject(access_id, l[0].get_data(), l[0].get_friendly_name())
开发者ID:lelou6666,项目名称:Phantom,代码行数:11,代码来源:cumulus_sqlalch.py


示例7: main

def main(argv=sys.argv[1:]):

    try:
        (o, args, p) = setup_options(argv)

        search_pattern = args[0]
        con_str = pycb.config.authzdb
        db = DB(con_str)
        user_list = User.find_user_by_friendly(db, search_pattern)
        for u in user_list:
            report_results(db, u, o)
        db.commit()

    except CLIError, clie:
        print clie
        return clie.get_rc()
开发者ID:oldpatricka,项目名称:nimbus,代码行数:16,代码来源:nimbus_list_users.py


示例8: 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)

        user_uu = None
        if len(args) == 1:
            user_uu = args[0]
        if opts.new:
            user = User(db_obj, user_uu, friendly=opts.friendlyname, create=True)
            pynimbusauthz.print_msg(opts, 0, "User %s added" % (user.get_id()))
        else:
            user = User(db_obj, user_uu) 
            pynimbusauthz.print_msg(opts, 0, "User %s" % (user.get_id()))

        if opts.alias != None:
            user_alias = user.get_alias(opts.alias, opts.type)
            if user_alias == None:
                user_alias = user.create_alias(opts.alias, opts.type, opts.friendlyname)
                pynimbusauthz.print_msg(opts, 0, "Creating new alias %s:%s" % (opts.type,opts.alias))
            if opts.genkey:
                data = pynimbusauthz.random_string_gen(42)
                pynimbusauthz.print_msg(opts, 0, "Key generated %s" % (data))
                user_alias.set_data(data)
            elif opts.setkey != None:
                data = opts.setkey
                user_alias.set_data(data)
                pynimbusauthz.print_msg(opts, 0, "updated the alias key")

        if opts.remove_alias != None:
            user_alias = user.get_alias(opts.remove_alias, opts.type)
            user_alias.remove()

        if opts.remove:
            pynimbusauthz.print_msg(opts, 1, "Removing user %s" % (user.get_id()))
            if opts.force:
                pynimbusauthz.print_msg(opts, 1, "Removing all references")
                user.destroy_brutally()
            else:
                user.destroy() 
        db_obj.commit()
    except AuthzException, ae:
        print ae
        return ae.get_rc()
开发者ID:Annatara,项目名称:nimbus,代码行数:47,代码来源:add_user.py


示例9: main

def main(argv=sys.argv[1:]):

    try:
        (o, args, p) = setup_options(argv)
        con_str = pycb.config.authzdb
        db = DB(con_str)

        o.emailaddr = args[0]
        create_user(o, db)
        report_results(o, db)
        db.close()
    except CLIError, clie:
        if DEBUG:
            traceback.print_exc(file=sys.stdout)
        
        print clie
        return clie.get_rc()
开发者ID:pauloricardomg,项目名称:nimbus,代码行数:17,代码来源:nimbus_new_user.py


示例10: 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
开发者ID:pauloricardomg,项目名称:nimbus,代码行数:17,代码来源:base_repo.py


示例11: __init__

 def __init__(self, alias_name, con_str):
     self.db_obj = DB(con_str=con_str)
     alias = User.find_alias(self.db_obj, alias_name, pynimbusauthz.alias_type_s3)
     a_list = list(alias)
     if len(a_list) < 1:
         raise cbException('AccessDenied')
     # pick the first one, hmmm XXX
     self.alias = a_list[0]
     self.user = self.alias.get_canonical_user()
开发者ID:oldpatricka,项目名称:nimbus,代码行数:9,代码来源:cbAuthzSecurity.py


示例12: setUp

    def setUp(self):
        (osf, self.fname) = tempfile.mkstemp()
        os.close(osf)
#        os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql"
        os.environ['NIMBUS_AUTHZ_DB'] = self.fname
        pynimbusauthz.db.make_test_database(self.fname)
        self.db = DB(con_str=self.fname)
        self.user1 = User(self.db)
        self.db.commit()
开发者ID:Annatara,项目名称:nimbus,代码行数:9,代码来源:test_rebase.py


示例13: setUp

    def setUp(self):
#        os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql"
        con = pynimbusauthz.db.make_test_database()
        self.db = DB(con=con)
        self.user1 = User(self.db)
        self.name = "/file/name"
        self.data = "/etc/group"
        self.file1 = File.create_file(self.db, self.name, self.user1, self.data, pynimbusauthz.object_type_s3)
        self.uf = UserFile(self.file1)
开发者ID:Annatara,项目名称:nimbus,代码行数:9,代码来源:userfile_test.py


示例14: 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)

        user = User(db_obj, args[0], create=False)

        if opts.quota != None:
            q = opts.quota
            if opts.quota == "UNLIMITED":
                q = User.UNLIMITED

            user.set_quota(q, object_type=opts.type)
        if opts.report:
            q = user.get_quota(object_type=opts.type)
            u = user.get_quota_usage(object_type=opts.type)

            if q != User.UNLIMITED:
                r = q - u

                rstr = pynimbusauthz.pretty_number(r)
                qstr = pynimbusauthz.pretty_number(q)
                ustr = pynimbusauthz.pretty_number(u)

                pynimbusauthz.print_msg(opts, 0, "%-10s %s" % ("Quota", qstr))
                pynimbusauthz.print_msg(opts, 0, "%-10s %s" % ("Usage", ustr))
                pynimbusauthz.print_msg(opts, 0, "%-10s %s" % ("Remaining", rstr))
                if r < 0:
                    pynimbusauthz.print_msg(opts, 0, "OVER LIMIT!")
                elif r == 0:
                    pynimbusauthz.print_msg(opts, 0, "At Limit")
                else:
                    p = (float(r) / float(q)) * 100.0
                    pynimbusauthz.print_msg(opts, 0, "%-10s %5.1f%%" % ("Available", p))
            else:
                pynimbusauthz.print_msg(opts, 0, "Quota UNLIMITED")

        db_obj.commit()
    except AuthzException, ae:
        print ae
        return ae.get_rc()
开发者ID:ketancmaheshwari,项目名称:nimbus,代码行数:44,代码来源:quota.py


示例15: setUp

 def setUp(self):
     (osf, self.fname) = tempfile.mkstemp()
     os.close(osf)
     #        os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql"
     os.environ["NIMBUS_AUTHZ_DB"] = self.fname
     pynimbusauthz.db.make_test_database(self.fname)
     self.db = DB(con_str=self.fname)
     self.user1 = User(self.db)
     self.name = "/file/name"
     self.data = "/etc/group"
     self.file1 = File.create_file(self.db, self.name, self.user1, self.data, pynimbusauthz.object_type_s3)
     self.uf = UserFile(self.file1)
     self.db.commit()
开发者ID:ketancmaheshwari,项目名称:nimbus,代码行数:13,代码来源:test_stat.py


示例16: 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)

        old_path = args[0]
        new_path = args[1]

        pattern = old_path + "%"

        files = list(File.find_files_from_data(db_obj, pattern))
        for f in files:
            old_key = f.get_data_key()
            new_key = old_key.replace(old_path, new_path, 1)
            f.set_data_key(new_key)
        db_obj.commit()
        print "done - %d files rebased" % len(files)

    except AuthzException, ae:
        print ae
        return ae.get_rc()
开发者ID:Annatara,项目名称:nimbus,代码行数:24,代码来源:rebase.py


示例17: TestUser

class TestUser(unittest.TestCase):

    def setUp(self):
#        os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql"
        con = pynimbusauthz.db.make_test_database()
        self.db = DB(con=con)
        self.user = User(self.db)

    def tearDown(self):
        self.user.destroy_brutally()
        self.db.close()

    def test_get_no_quota(self):
        q = self.user.get_quota()
        self.assertEqual(q, User.UNLIMITED)

    def test_set_quota(self):
        q = 100
        self.user.set_quota(q)
        qrc = self.user.get_quota()
        self.assertEqual(q, qrc)

    def test_get_no_usage(self):
        u = self.user.get_quota_usage()
        self.assertEqual(u, 0)

    def test_add_file_usage_one_file(self):
        size1 = 100
        name = "/file/name"
        data = "/etc/group"

        file1 = File.create_file(self.db, name, self.user, data, pynimbusauthz.object_type_s3, size=size1)
        self.db.commit()

        u = self.user.get_quota_usage()
        self.assertEqual(u, size1)

    def test_add_file_usage_many_files(self):
        size1 = 100
        name = "/file/name"
        data = "/etc/group"

        total = 0
        for i in range(0, 10):
            file1 = File.create_file(self.db, name+str(i), self.user, data, pynimbusauthz.object_type_s3, size=size1)
            total = total + size1
        self.db.commit()

        u = self.user.get_quota_usage()
        self.assertEqual(u, total)
开发者ID:Annatara,项目名称:nimbus,代码行数:50,代码来源:rebase_test.py


示例18: TestStatCli

class TestStatCli(unittest.TestCase):
    def setUp(self):
        (osf, self.fname) = tempfile.mkstemp()
        os.close(osf)
        #        os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql"
        os.environ["NIMBUS_AUTHZ_DB"] = self.fname
        pynimbusauthz.db.make_test_database(self.fname)
        self.db = DB(con_str=self.fname)
        self.user1 = User(self.db)
        self.name = "/file/name"
        self.data = "/etc/group"
        self.file1 = File.create_file(self.db, self.name, self.user1, self.data, pynimbusauthz.object_type_s3)
        self.uf = UserFile(self.file1)
        self.db.commit()

    def tearDown(self):
        self.db.close()
        os.remove(self.fname)

    def test_basic_stat(self):
        rc = pynimbusauthz.stat.main([self.name])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        rc = pynimbusauthz.stat.main(["-a", self.name])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))

    def test_bad_opts_stat(self):
        rc = pynimbusauthz.stat.main([])
        self.assertEqual(rc, 32, "CLI should return success %d" % (rc))
        rc = pynimbusauthz.stat.main(["nofile"])
        self.assertNotEqual(rc, 0, "CLI should return success %s" % (str(rc)))
        rc = pynimbusauthz.stat.main(["-p", "nobucket", self.name])
        self.assertNotEqual(rc, 0, "CLI should return success %d" % (rc))

    def test_basic_stat(self):
        user2 = User(self.db)
        self.db.commit()

        rc = pynimbusauthz.chmod.main([user2.get_id(), self.name, "Rrw"])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        rc = pynimbusauthz.stat.main([self.name])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        rc = pynimbusauthz.stat.main(["-a", self.name])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
开发者ID:ketancmaheshwari,项目名称:nimbus,代码行数:43,代码来源:test_stat.py


示例19: TestAddUserCli

class TestAddUserCli(unittest.TestCase):

    def setUp(self):
        (osf, self.fname) = tempfile.mkstemp()
        os.close(osf)
        os.environ['NIMBUS_AUTHZ_DB'] = self.fname
        pynimbusauthz.db.make_test_database(self.fname)
        self.db = DB(con_str=self.fname)

    def tearDown(self):
        self.db.close()
        os.remove(self.fname)

    def test_basic_adduser(self):
        uu = str(uuid.uuid1())
        rc = pynimbusauthz.add_user.main(["-n", uu])
        self.assertEqual(rc, 0, "CLI should return success")
        user = User(self.db, uu)
        rc = pynimbusauthz.add_user.main(["-r", uu])
        self.assertEqual(rc, 0, "CLI should return success")
        try:
            user = User(self.db, uu)
            self.fail("should have had an exception loading user")
        except:
            pass

    def test_basic_alias(self):
        user = User(self.db)
        uu = user.get_id()
        aname = "alias1"
        self.db.commit()
        rc = pynimbusauthz.add_user.main(["-a", aname, uu])
        self.assertEqual(rc, 0, "CLI should return success")
        ua = user.get_alias(aname, pynimbusauthz.alias_type_s3)
        self.assertNotEqual(ua, None, "alias not found")
        rc = pynimbusauthz.add_user.main(["-x", aname, uu])
        self.assertEqual(rc, 0, "CLI should return success")
        ua = user.get_alias(aname, pynimbusauthz.alias_type_s3)
        self.assertEqual(ua, None, "alias should not be found")

    def test_user_alias_remove(self):
        aname = str(uuid.uuid1())
        uu = str(uuid.uuid1())
        rc = pynimbusauthz.add_user.main(["-n", "-a", aname, uu])
        self.assertEqual(rc, 0, "CLI should return success")

        user = User(self.db, uu)
        ua = user.get_alias(aname, pynimbusauthz.alias_type_s3)

        rc = pynimbusauthz.add_user.main(["-x", aname, "-r", uu])
        self.assertEqual(rc, 0, "CLI should return success")

        try:
            user = User(self.db, uu)
            self.fail("should have had an exception loading user")
        except:
            pass
        try:
            ua = user.get_alias(aname, pynimbusauthz.alias_type_s3)
            self.fail("should have had an exception loading user")
        except:
            pass

    def test_set_key(self):
        aname = str(uuid.uuid1())
        uu = str(uuid.uuid1())
        rc = pynimbusauthz.add_user.main(["-n", "-a", aname, uu])
        self.assertEqual(rc, 0, "CLI should return success")
        rc = pynimbusauthz.add_user.main(["-g", "-a", aname, uu])
        self.assertEqual(rc, 0, "CLI should return success")
 
        key = str(uuid.uuid1())
        rc = pynimbusauthz.add_user.main(["-k", key, "-a", aname, uu])
        self.assertEqual(rc, 0, "CLI should return success")

        user = User(self.db, uu)
        ua = user.get_alias(aname, pynimbusauthz.alias_type_s3)
        self.db.commit()
        k2 = ua.get_data()
        self.assertEqual(k2, key)

    def test_default_new_user(self):
        rc = pynimbusauthz.add_user.main(["-n"])
        self.assertEqual(rc, 0, "CLI should return success %d"%(rc))

    def test_bad_args(self):
        uu = str(uuid.uuid1())
        rc = pynimbusauthz.add_user.main([])
        self.assertNotEqual(rc, 0, "CLI should not return success %d"%(rc))
        rc = pynimbusauthz.add_user.main(["-k", uu, uu])
        self.assertNotEqual(rc, 0, "CLI should not return success %d"%(rc))
        rc = pynimbusauthz.add_user.main(["-g", uu])
        self.assertNotEqual(rc, 0, "CLI should not return success %d"%(rc))

    def test_remove_force(self):
        aname = str(uuid.uuid1())
        uu = str(uuid.uuid1())
        rc = pynimbusauthz.add_user.main(["-n", "-a", aname, uu])
        self.assertEqual(rc, 0, "CLI should return success")

#.........这里部分代码省略.........
开发者ID:Annatara,项目名称:nimbus,代码行数:101,代码来源:test_add_user.py


示例20: TestChmodCli

class TestChmodCli(unittest.TestCase):

    def setUp(self):
        (osf, self.fname) = tempfile.mkstemp()
        os.close(osf)
#        os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql"
        os.environ['NIMBUS_AUTHZ_DB'] = self.fname
        pynimbusauthz.db.make_test_database(self.fname)
        self.db = DB(con_str=self.fname)
        self.user1 = User(self.db)
        self.name = "/file/name"
        self.data = "/etc/group"
        self.file1 = File.create_file(self.db, self.name, self.user1, self.data, pynimbusauthz.object_type_s3)
        self.uf = UserFile(self.file1)
        self.db.commit()

    def tearDown(self):
        self.db.close()
        os.remove(self.fname)

    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))

    def test_basic_chmod(self):
        uu = str(uuid.uuid1())
        new_perms = "WR"
        rc = pynimbusauthz.chmod.main([self.user1.get_id(), self.file1.get_name(), new_perms])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        self.validate_perms(new_perms)

    def test_type_chmod(self):
        uu = str(uuid.uuid1())
        new_perms = "WRr"
        rc = pynimbusauthz.chmod.main(["-t", self.file1.get_object_type(), self.user1.get_id(), self.file1.get_name(), new_perms])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        self.validate_perms(new_perms)

    def test_badopts(self):
        new_perms = "WR"

        rc = pynimbusauthz.chmod.main(["-t", self.file1.get_object_type(), self.user1.get_id()])
        self.assertEqual(rc, 32, "CLI should return success %d" % (rc))

        rc = pynimbusauthz.chmod.main([self.user1.get_id(), "notafile", new_perms])
        self.assertEqual(rc, 33, "CLI should return success %d" % (rc))
        rc = pynimbusauthz.chmod.main(["-t", self.file1.get_object_type(), "-p", "nobucket", self.user1.get_id(), self.file1.get_name(), new_perms])
        self.assertEqual(rc, 33, "CLI should return success %d" % (rc))

    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))
开发者ID:Annatara,项目名称:nimbus,代码行数:62,代码来源:test_chmod.py



注:本文中的pynimbusauthz.db.DB类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python objects.File类代码示例发布时间:2022-05-27
下一篇:
Python utils._函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap