Exemplo n.º 1
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:
            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()
Exemplo n.º 2
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:
            u_pattern = args[0]
        else:
            u_pattern = ""

        if opts.bya:
            usa = User.find_alias(db_obj, u_pattern)
            users = []
            for ua in usa:
                users.append(ua.get_canonical_user())
        else:
            users = User.find_user(db_obj, u_pattern)

        if users == None:
            pynimbusauthz.print_msg(opts, 0, "No users in list")
            return 1

        for u in users:
            list_user(opts, u)

    except AuthzException, ae:
        print ae
        return ae.get_rc()
Exemplo n.º 3
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:
            u_pattern = args[0]
        else:
            u_pattern = ""

        if opts.bya:
            usa = User.find_alias(db_obj, u_pattern)
            users = []
            for ua in usa:
                users.append(ua.get_canonical_user())
        else:
            users = User.find_user(db_obj, u_pattern)

        if users == None:
            pynimbusauthz.print_msg(opts, 0, "No users in list")
            return 1

        for u in users:
            list_user(opts, u)

    except AuthzException, ae:
        print ae
        return ae.get_rc()
Exemplo n.º 4
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:
            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()
Exemplo n.º 5
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()
Exemplo n.º 6
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 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()
Exemplo n.º 7
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)

    except AuthzException, ae:
        print ae
        return ae.get_rc()
Exemplo n.º 8
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)

        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()
Exemplo n.º 9
0
def reset_users(nh, clean_pattern='%'):
    dbobj = pynimbusauthz.get_db_connection_string()
    users_to_delete = User.find_user_by_friendly(dbobj, clean_pattern)
    for user in users_to_delete:
        files = File.get_user_files(dbobj, user)
        for f in files:
            name = f.get_data_key()
            f.delete()
            # commit every file delete before removing the actual file
            dbobj.commit()
            pycb.config.bucket.delete_object(name)
        user.destroy_brutally()
        # commit after every user because otherwise the file delete inner
        # loop will commit in less obvious ways
        dbobj.commit()
Exemplo n.º 10
0
def reset_users(nh, clean_pattern='%'):
    dbobj = pynimbusauthz.get_db_connection_string()
    users_to_delete = User.find_user_by_friendly(dbobj, clean_pattern)
    for user in users_to_delete:
        files = File.get_user_files(dbobj, user)
        for f in files:
            name = f.get_data_key()
            f.delete()
            # commit every file delete before removing the actual file
            dbobj.commit()
            pycb.config.bucket.delete_object(name)
        user.destroy_brutally()
        # commit after every user because otherwise the file delete inner 
        # loop will commit in less obvious ways
        dbobj.commit()
Exemplo n.º 11
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)

        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()
Exemplo n.º 12
0
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
Exemplo n.º 13
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)

        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()
Exemplo n.º 14
0
def main(argv=sys.argv[1:]):

    try:
        repo_dir = argv[0]
        repo_dir = str(repo_dir).strip()
        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
Exemplo n.º 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) == 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()
Exemplo n.º 16
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 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()
Exemplo n.º 17
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()
Exemplo n.º 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)

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