コード例 #1
0
    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()
コード例 #2
0
ファイル: cbAuthzSecurity.py プロジェクト: oldpatricka/nimbus
 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
コード例 #3
0
ファイル: chmod.py プロジェクト: Annatara/nimbus
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
0
 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
コード例 #5
0
ファイル: test_touch.py プロジェクト: Annatara/nimbus
 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)
コード例 #6
0
 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
0
ファイル: cbAuthzSecurity.py プロジェクト: xxy-php/code
 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
コード例 #8
0
ファイル: test_touch.py プロジェクト: Annatara/nimbus
    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)
コード例 #9
0
    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))
コード例 #10
0
    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()
コード例 #11
0
ファイル: ls.py プロジェクト: ws-tools/nimbus
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()
コード例 #12
0
ファイル: touch.py プロジェクト: oldpatricka/nimbus
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()
コード例 #13
0
ファイル: cbAuthzSecurity.py プロジェクト: oldpatricka/nimbus
    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
0
ファイル: ls.py プロジェクト: Annatara/nimbus
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()
コード例 #15
0
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()
コード例 #16
0
ファイル: file_test.py プロジェクト: ketancmaheshwari/nimbus
    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()
コード例 #17
0
    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)
コード例 #18
0
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()
コード例 #19
0
ファイル: chmod.py プロジェクト: ws-tools/nimbus
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()
コード例 #20
0
ファイル: stat.py プロジェクト: Annatara/nimbus
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()
コード例 #21
0
ファイル: file_test.py プロジェクト: ketancmaheshwari/nimbus
    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))
コード例 #22
0
ファイル: file_test.py プロジェクト: ketancmaheshwari/nimbus
 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")
コード例 #23
0
 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")