(ctx)
Fate Flow Client
Fate Flow Client
Fate Flow Client
def flow_cli(ctx):
    """
    Fate Flow Client
    """
    ctx.ensure_object(dict)
    if ctx.invoked_subcommand == 'init':
        return

    with open(os.path.join(os.path.dirname(__file__), "settings.yaml"), "r") as fin:
        config = yaml.safe_load(fin)
    if not config.get('api_version'):
        raise ValueError('api_version in config is required')
    ctx.obj['api_version'] = config['api_version']

    is_server_conf_exist = False
    if config.get("server_conf_path"):
        conf_path = Path(config["server_conf_path"])
        is_server_conf_exist = conf_path.exists()

    if is_server_conf_exist:
        server_conf = yaml.safe_load(conf_path.read_text())["fateflow"]

        local_conf_path = conf_path.with_name(f"local.{conf_path.name}")
        if local_conf_path.exists():
            server_conf.update(yaml.safe_load(local_conf_path.read_text()).get("fateflow", {}))

        ctx.obj["ip"] = server_conf["host"]
        ctx.obj["http_port"] = server_conf["http_port"]
        ctx.obj["server_url"] = f"http://{ctx.obj['ip']}:{ctx.obj['http_port']}/{ctx.obj['api_version']}"

        if server_conf.get('http_app_key') and server_conf.get('http_secret_key'):
            ctx.obj['app_key'] = server_conf['http_app_key']
            ctx.obj['secret_key'] = server_conf['http_secret_key']
    elif config.get("ip") and config.get("port"):
        ctx.obj["ip"] = config["ip"]
        ctx.obj["http_port"] = int(config["port"])
        ctx.obj["server_url"] = f"http://{ctx.obj['ip']}:{ctx.obj['http_port']}/{config['api_version']}"

        if config.get('app_key') and config.get('secret_key'):
            ctx.obj['app_key'] = config['app_key']
            ctx.obj['secret_key'] = config['secret_key']
    else:
        raise ValueError("Invalid configuration file. Did you run 'flow init'?")

    ctx.obj["init"] = is_server_conf_exist or (config.get("ip") and config.get("port"))
def flow_cli ( ctx ) : ctx . ensure_object ( dict ) if ctx . invoked_subcommand == 'init' : return with open ( os . path . join ( os . path . dirname ( __file__ ) , "settings.yaml" ) , "r" ) as fin : config = yaml . safe_load ( fin ) if not config . get ( 'api_version' ) : raise ValueError ( 'api_version in config is required' ) ctx . obj [ 'api_version' ] = config [ 'api_version' ] is_server_conf_exist = False if config . get ( "server_conf_path" ) : conf_path = Path ( config [ "server_conf_path" ] ) is_server_conf_exist = conf_path . exists ( ) if is_server_conf_exist : server_conf = yaml . safe_load ( conf_path . read_text ( ) ) [ "fateflow" ] local_conf_path = conf_path . with_name ( f"local.{conf_path.name}" ) if local_conf_path . exists ( ) : server_conf . update ( yaml . safe_load ( local_conf_path . read_text ( ) ) . get ( "fateflow" , { } ) ) ctx . obj [ "ip" ] = server_conf [ "host" ] ctx . obj [ "http_port" ] = server_conf [ "http_port" ] ctx . obj [ "server_url" ] = f"http://{ctx.obj['ip']}:{ctx.obj['http_port']}/{ctx.obj['api_version']}" if server_conf . get ( 'http_app_key' ) and server_conf . get ( 'http_secret_key' ) : ctx . obj [ 'app_key' ] = server_conf [ 'http_app_key' ] ctx . obj [ 'secret_key' ] = server_conf [ 'http_secret_key' ] elif config . get ( "ip" ) and config . get ( "port" ) : ctx . obj [ "ip" ] = config [ "ip" ] ctx . obj [ "http_port" ] = int ( config [ "port" ] ) ctx . obj [ "server_url" ] = f"http://{ctx.obj['ip']}:{ctx.obj['http_port']}/{config['api_version']}" if config . get ( 'app_key' ) and config . get ( 'secret_key' ) : ctx . obj [ 'app_key' ] = config [ 'app_key' ] ctx . obj [ 'secret_key' ] = config [ 'secret_key' ] else : raise ValueError ( "Invalid configuration file. Did you run 'flow init'?" ) ctx . obj [ "init" ] = is_server_conf_exist or ( config . get ( "ip" ) and config . get ( "port" ) )