예제 #1
0
def setup_application():
    config = get_config()
    if config is not None:
        return
    config = read_config_file()
    validate_config(config)
    set_config(config)
예제 #2
0
def main():
    _initialize_logging()
    # Read our configuration, and process errors from it.
    log = logging.getLogger('main')
    try:
        config = process_config()
    except (IOError, ValueError,):
        return '''Cannot find, open, or understand your config file.  Lacking options 
otherwise, it should be at:

/home/openmanage/openmanage/conf/agent_config.json

Run %s -h for help.''' % (sys.argv[0],)
    except StartupException as e:
        return str(e)

    set_config(config)
    lockfile = get_lock()
    # Moving along, open the database
    db_conn = psycopg2.connect(database=config['db_db'],
                               user=config['db_user'],
                               password=config['db_pass'],
                               host=config['db_host'])

    if config['rebuild_database']:
        log.info("DB repair requested, beginning rebuild")
        group_manager.run_db_repair(config, db_conn)
        log.info("DB repair complete")

        
    log.info("LDAP -> SpiderOak sync starting")
    group_manager.run_group_management(config, db_conn)
    
    release_lock(lockfile)
    return 0
예제 #3
0
def setup_application():
    config = get_config()
    if config is not None:
        return
    config = read_config_file()
    validate_config(config)
    set_config(config)
예제 #4
0
    def token_refresh(self):
        LOCK_TOKEN_REFRESH.acquire()

        try:
            data = {"refresh_token": DATA['config']['REFRESH_TOKEN'], 'Grant_Type': 'refresh_token'}
            post = requests.post(
                'https://api.aliyundrive.com/token/refresh',
                data=json.dumps(data),
                headers={
                    'content-type': 'application/json;charset=UTF-8'
                },
                verify=False,
                timeout=3
            )
            try:
                post_json = post.json()
                # 刷新配置中的token
                common.set_config('REFRESH_TOKEN', post_json['refresh_token'])

            except Exception as e:
                self.print('refresh_token已经失效', 'warn')
                return False

            DATA['access_token'] = post_json['access_token']
            self.headers = {
                'authorization': DATA['access_token'],
                'content-type': 'application/json;charset=UTF-8'
            }
            DATA['config']['REFRESH_TOKEN'] = post_json['refresh_token']
        finally:
            LOCK_TOKEN_REFRESH.release()
        return True
예제 #5
0
파일: isjtests.py 프로젝트: conyx/isjtests
def main():
    """
    Main function
    
    1) parse program options
    2) init logger module
    3) parse students list
    4) parse tasks
    5) send data to print or web interface module
    """
    # parse program params and XML configuration file
    (state, configuration) = parse_options()
    # print help
    if state == 1:
        print_help()
        return common.EXIT_OK
    # something got wrong
    elif state != 0 or configuration == None:
        return common.EXIT_ERROR_OPTIONS
    # config ok
    else:
        common.set_config(configuration)
    # init logger module
    state = logger.init()
    # something got wrong
    if state != 0:
        return common.EXIT_ERROR_LOGGER
    logger.print_msg("isjtests started")
    # parse students list
    students = read_students_list()
    # something got wrong
    if students == None or len(students) == 0:
        return common.EXIT_ERROR_STUDENTS
    # parse tasks
    tasks = taskparser.parse_all_tasks()
    # something got wrong
    if tasks == None or len(tasks) == 0:
        return common.EXIT_ERROR_TASKS
    # send data to interface module, wait for finish
    if configuration.get_mode() == "print":
        status = printface.serve(students, tasks)
    elif configuration.get_mode() == "web":
        status = webface.serve(students, tasks)
    # something got wrong
    if status != 0:
        return common.EXIT_ERROR_INTERFACE
    # everything ok
    return 0
예제 #6
0
def main():
    _initialize_logging()
    # Read our configuration, and process errors from it.
    log = logging.getLogger('main')
    try:
        config = process_config()
    except (
            IOError,
            ValueError,
    ):
        log.error("Broken / missing agent_config,json file. Aborting!")
        return '''Cannot find, open, or understand your config file.  Lacking options 
otherwise, it should be at:

/home/openmanage/openmanage/conf/agent_config.json

Run %s -h for help.''' % (sys.argv[0], )

    except (
            StartupException,
            NetKesConfigError,
    ) as e:
        log.error(str(e))
        return str(e)

    if not config['dir_uri']:
        return '''LDAP not configured. Exiting'''

    set_config(config)
    lockfile = get_lock()
    # Moving along, open the database
    db_conn = psycopg2.connect(database=config['db_db'],
                               user=config['db_user'],
                               password=config['db_pass'],
                               host=config['db_host'])

    if config['rebuild_database']:
        log.info("DB repair requested, beginning rebuild")
        group_manager.run_db_repair(config, db_conn)
        log.info("DB repair complete")

    log.info("LDAP -> SpiderOak sync starting")
    group_manager.run_group_management(config, db_conn)

    release_lock(lockfile)
    return 0
예제 #7
0
def main():
    _initialize_logging()
    log = logging.getLogger("main")
    config = process_config()
    set_config(config)

    db_conn = psycopg2.connect(database=config['db_db'],
                               user=config['db_user'],
                               password=config['db_pass'],
                               host=config['db_host'])

    # Try and catch using this tool alongside the LDAP user_source.
    try:
        import account_mgr.user_source.ldap_source
    except ImportError:
        # This is fine; if we can't import LDAP, that's the expected behavior.
        pass
    else:
        log.warn("LDAP module available, this may produce inconsistent state.")
        if 'force' not in config:
            log.error("--force option not provided, aborting.")
            return 1

    # Make sure we grab the password if that's required!
    if config['setpw'] and 'csvfile' not in config:
        print "grabbing password"
        config['password'] = _try_new_password()
        if config['password'] is None:
            log.error("Failed setting password, aborting.")
            return 1

    results = run_command(db_conn, config)
    if results is None:
        print results

    return 0
예제 #8
0
def main():
    _initialize_logging()
    log = logging.getLogger("main")
    config = process_config()
    set_config(config)

    db_conn = psycopg2.connect(database=config['db_db'],
                               user=config['db_user'],
                               password=config['db_pass'],
                               host=config['db_host'])

    # Try and catch using this tool alongside the LDAP user_source.
    try:
        import account_mgr.user_source.ldap_source
    except ImportError:
        # This is fine; if we can't import LDAP, that's the expected behavior.
        pass
    else:
        log.warn("LDAP module available, this may produce inconsistent state.")
        if 'force' not in config:
            log.error("--force option not provided, aborting.")
            return 1

    # Make sure we grab the password if that's required!
    if config['setpw'] and 'csvfile' not in config:
        print "grabbing password"
        config['password'] = _try_new_password()
        if config['password'] is None:
            log.error("Failed setting password, aborting.")
            return 1

    results = run_command(db_conn, config)
    if results is None:
        print results

    return 0