Skip to content

Commit

Permalink
feat: add very verbose logging to CLI API endpoint parsing (#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc authored Jun 7, 2022
1 parent 2f8d246 commit 12ce769
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions cli/util/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func GetAPIInfo(ctx *cli.Context, t lotus_repo.RepoType) (APIInfo, error) {
strma := ctx.String(f)
strma = strings.TrimSpace(strma)

if IsVeryVerbose {
_, _ = fmt.Fprintf(ctx.App.Writer, "extracted API endpoint %s from API flag %s\n", strma, f)
}
return APIInfo{Addr: strma}, nil
}

Expand All @@ -88,14 +91,22 @@ func GetAPIInfo(ctx *cli.Context, t lotus_repo.RepoType) (APIInfo, error) {
primaryEnv, fallbacksEnvs, deprecatedEnvs := EnvsForAPIInfos(t)
env, ok := os.LookupEnv(primaryEnv)
if ok {
if IsVeryVerbose {
_, _ = fmt.Fprintf(ctx.App.Writer,
"extracted API endpoint %s from primary environment variable %s\n", env, primaryEnv)
}
return ParseApiInfo(env), nil
}

for _, env := range deprecatedEnvs {
env, ok := os.LookupEnv(env)
envVal, ok := os.LookupEnv(env)
if ok {
log.Warnf("Using deprecated env(%s) value, please use env(%s) instead.", env, primaryEnv)
return ParseApiInfo(env), nil
if IsVeryVerbose {
_, _ = fmt.Fprintf(ctx.App.Writer,
"extracted API endpoint %s from deprecated environment variable %s\n", envVal, env)
}
return ParseApiInfo(envVal), nil
}
}

Expand Down Expand Up @@ -136,16 +147,24 @@ func GetAPIInfo(ctx *cli.Context, t lotus_repo.RepoType) (APIInfo, error) {
log.Warnf("Couldn't load CLI token, capabilities may be limited: %v", err)
}

if IsVeryVerbose {
_, _ = fmt.Fprintf(ctx.App.Writer, "extracted API endpoint %s from repo flag %s\n", ma, f)
}

return APIInfo{
Addr: ma.String(),
Token: token,
}, nil
}

for _, env := range fallbacksEnvs {
env, ok := os.LookupEnv(env)
envVal, ok := os.LookupEnv(env)
if ok {
return ParseApiInfo(env), nil
if IsVeryVerbose {
_, _ = fmt.Fprintf(ctx.App.Writer,
"extracted API endpoint %s from fallback environment variable %s\n", envVal, env)
}
return ParseApiInfo(envVal), nil
}
}

Expand Down Expand Up @@ -180,7 +199,7 @@ func GetBoostAPI(ctx *cli.Context, opts ...GetBoostOption) (api.Boost, jsonrpc.C
if options.PreferHttp {
u, err := url.Parse(addr)
if err != nil {
return nil, nil, fmt.Errorf("parsing miner api URL: %w", err)
return nil, nil, fmt.Errorf("parsing Boost API URL: %w", err)
}

switch u.Scheme {
Expand All @@ -194,7 +213,7 @@ func GetBoostAPI(ctx *cli.Context, opts ...GetBoostOption) (api.Boost, jsonrpc.C
}

if IsVeryVerbose {
_, _ = fmt.Fprintln(ctx.App.Writer, "using miner API v0 endpoint:", addr)
_, _ = fmt.Fprintln(ctx.App.Writer, "using Boost API endpoint:", addr)
}

return client.NewBoostRPCV0(ctx.Context, addr, headers)
Expand Down

0 comments on commit 12ce769

Please sign in to comment.