(clientagentcmd): plumb thru env var (#5123)
* (clientagentcmd): plumb thru env var
This commit is contained in:
1 parent
fe129b4268
commit
eb33649ded
3 files changed
+30
-33
No files matched your search
@@ -48,8 +48,8 @@ func addToken(ctx context.Context, apiClient *api.Client, port uint16) (*api.Res
|
||||
client.RetryWaitMin = 100 * time.Millisecond
|
||||
client.RetryWaitMax = 1500 * time.Millisecond
|
||||
|
||||
// Explicitly setting this to 1, since this runs after every command and we don't want any delays
|
||||
client.RetryMax = 1
|
||||
// Explicitly setting this to 0, since this runs after every command and we don't want any delays
|
||||
client.RetryMax = 0
|
||||
|
||||
req, err := retryablehttp.NewRequestWithContext(ctx, "POST", clientAgentUrl(port, "v1/tokens"),
|
||||
retryablehttp.ReaderFunc(func() (io.Reader, error) {
|
||||
|
||||
@@ -5,24 +5,11 @@ package clientagentcmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||
"github.com/hashicorp/boundary/internal/cmd/wrapper"
|
||||
)
|
||||
|
||||
var allowErrorOutput = false
|
||||
|
||||
const EnvBoundaryClientAgentCliErrorOutput = "BOUNDARY_CLIENT_AGENT_CLI_ERROR_OUTPUT"
|
||||
|
||||
func init() {
|
||||
errOutput := os.Getenv(EnvBoundaryClientAgentCliErrorOutput)
|
||||
if strings.ToLower(errOutput) == "true" {
|
||||
allowErrorOutput = true
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
if err := wrapper.RegisterSuccessfulCommandCallback("client-agent", hook); err != nil {
|
||||
panic(err)
|
||||
@@ -34,7 +21,7 @@ func hook(ctx context.Context, baseCmd *base.Command, token string) {
|
||||
return
|
||||
}
|
||||
client, err := baseCmd.Client()
|
||||
if err != nil && allowErrorOutput {
|
||||
if err != nil && baseCmd.FlagOutputClientAgentCliError {
|
||||
baseCmd.PrintCliError(err)
|
||||
return
|
||||
}
|
||||
@@ -42,10 +29,10 @@ func hook(ctx context.Context, baseCmd *base.Command, token string) {
|
||||
client.SetToken(token)
|
||||
}
|
||||
_, apiErr, err := addToken(ctx, client, baseCmd.FlagClientAgentPort)
|
||||
if err != nil && allowErrorOutput {
|
||||
if err != nil && baseCmd.FlagOutputClientAgentCliError {
|
||||
baseCmd.PrintCliError(err)
|
||||
}
|
||||
if apiErr != nil && allowErrorOutput {
|
||||
if apiErr != nil && baseCmd.FlagOutputClientAgentCliError {
|
||||
baseCmd.PrintApiError(apiErr, "sending token to client agent in the background")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user