Ejemplo n.º 1
0
def create_users(argvs):
    '''
    create little_finger access user
    :param argvs:
    :return:
    '''
    if '-f' in argvs:
        user_file  = argvs[argvs.index("-f") +1 ]
    else:
        print_err("invalid usage, should be:\ncreateusers -f <the new users file>",quit=True)

    source = yaml_parser(user_file)
    if source:
        for key,val in source.items():
            print(key,val)
            obj = models.UserProfile(username=key,password=val.get('password'))
            if val.get('groups'):
                groups = session.query(models.Group).filter(models.Group.name.in_(val.get('groups'))).all()
                if not groups:
                    print_err("none of [%s] exist in group table." % val.get('groups'),quit=True)
                obj.groups = groups
            if val.get('bind_hosts'):
                bind_hosts = common_filters.bind_hosts_filter(val)
                obj.bind_hosts = bind_hosts
            #print(obj)
            session.add(obj)
        session.commit()
Ejemplo n.º 2
0
def create_users(argvs):
    """
    create user
    :param argvs:
    :return:
    """
    if '-f' in argvs:
        user_file = argvs[argvs.index("-f") + 1]
    else:
        print_err("invalid usage, should be:\ncreateusers -f <the new users file>", logout=True)
        return

    source = yaml_parser(user_file)
    if source:
        logger.debug("source:\n%s" % source)
        for key, val in source.items():
            logger.debug("%s:%s" % (key, val))
            obj = models.UserProfile(username=key, password=val.get('password'))
            logger.info(obj)
            # if val.get('groups'):
            #     groups = session.query(models.Group).filter(models.Group.name.in_(val.get('groups'))).all()
            #     if not groups:
            #         print_err("none of [%s] exist in group table." % val.get('groups'),quit=True)
            #     obj.groups = groups
            # if val.get('bind_hosts'):
            #     bind_hosts = common_filters.bind_hosts_filter(val)
            #     obj.bind_hosts = bind_hosts
            # print(obj)
            session.add(obj)
        session.commit()
        logger.info("create user sucess!")
Ejemplo n.º 3
0
def create_users(argvs):
    '''
    create little_finger access user
    :param argvs:
    :return:
    '''
    # 输入的命令行参数是否含有'-f'字符串
    if '-f' in argvs:
        # 取出文件名
        user_file = argvs[argvs.index("-f") + 1]
    else:
        # 文件不存在时,输出错误信息
        print_err(
            "invalid usage, should be:\ncreateusers -f <the new users file>",
            quit=True)
    # 得到包含用户信息的字典.
    source = yaml_parser(user_file)
    if source:
        # 一个一个的将用户存入数据库中.
        for key, val in source.items():
            print(key, val)
            obj = models.UserProfile(username=key,
                                     password=val.get('password'))
            # if val.get('groups'):
            #     groups = session.query(models.Group).filter(models.Group.name.in_(val.get('groups'))).all()
            #     if not groups:
            #         print_err("none of [%s] exist in group table." % val.get('groups'),quit=True)
            #     obj.groups = groups
            # if val.get('bind_hosts'):
            #     bind_hosts = common_filters.bind_hosts_filter(val)
            #     obj.bind_hosts = bind_hosts
            #print(obj)
            session.add(obj)
        session.commit()
Ejemplo n.º 4
0
def create_users(argvs):
    '''创建堡垒机用户'''
    if '-f' in argvs:
        user_file = argvs[argvs.index("-f") + 1]
    else:
        print_err(
            "invalid usage, should be:\ncreateusers -f <the new users file>",
            quit=True)

    source = yaml_parser(user_file)
    if source:
        for key, val in source.items():
            print(key, val)
            obj = models.UserProfile(username=key,
                                     password=val.get('password'))

            session.add(obj)
        session.commit()