(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
+25
-15
@@ -69,13 +69,14 @@ const (
|
||||
// maxLineLength is the maximum width of any line.
|
||||
maxLineLength int = 78
|
||||
|
||||
envToken = "BOUNDARY_TOKEN"
|
||||
EnvTokenName = "BOUNDARY_TOKEN_NAME"
|
||||
EnvKeyringType = "BOUNDARY_KEYRING_TYPE"
|
||||
envRecoveryConfig = "BOUNDARY_RECOVERY_CONFIG"
|
||||
envSkipCacheDaemon = "BOUNDARY_SKIP_CACHE_DAEMON"
|
||||
envSkipClientAgent = "BOUNDARY_SKIP_CLIENT_AGENT"
|
||||
EnvClientAgentPort = "BOUNDARY_CLIENT_AGENT_LISTENING_PORT"
|
||||
envToken = "BOUNDARY_TOKEN"
|
||||
EnvTokenName = "BOUNDARY_TOKEN_NAME"
|
||||
EnvKeyringType = "BOUNDARY_KEYRING_TYPE"
|
||||
envRecoveryConfig = "BOUNDARY_RECOVERY_CONFIG"
|
||||
envSkipCacheDaemon = "BOUNDARY_SKIP_CACHE_DAEMON"
|
||||
envSkipClientAgent = "BOUNDARY_SKIP_CLIENT_AGENT"
|
||||
EnvClientAgentPort = "BOUNDARY_CLIENT_AGENT_LISTENING_PORT"
|
||||
EnvBoundaryClientAgentCliErrorOutput = "BOUNDARY_CLIENT_AGENT_CLI_ERROR_OUTPUT"
|
||||
|
||||
StoredTokenName = "HashiCorp Boundary Auth Token"
|
||||
)
|
||||
@@ -107,14 +108,15 @@ type Command struct {
|
||||
flagTLSServerName string
|
||||
flagTLSInsecure bool
|
||||
|
||||
flagFormat string
|
||||
FlagToken string
|
||||
FlagTokenName string
|
||||
FlagKeyringType string
|
||||
FlagRecoveryConfig string
|
||||
FlagOutputCurlString bool
|
||||
FlagSkipCacheDaemon bool
|
||||
FlagSkipClientAgent bool
|
||||
flagFormat string
|
||||
FlagToken string
|
||||
FlagTokenName string
|
||||
FlagKeyringType string
|
||||
FlagRecoveryConfig string
|
||||
FlagOutputCurlString bool
|
||||
FlagSkipCacheDaemon bool
|
||||
FlagSkipClientAgent bool
|
||||
FlagOutputClientAgentCliError bool
|
||||
|
||||
FlagClientAgentPort uint16
|
||||
|
||||
@@ -491,6 +493,14 @@ func (c *Command) FlagSet(bit FlagSetBit) *FlagSets {
|
||||
Usage: "Skips starting the caching daemon or sending the current used/retrieved token to the caching daemon.",
|
||||
})
|
||||
|
||||
f.BoolVar(&BoolVar{
|
||||
Name: "output-client-agent-cli-error",
|
||||
Target: &c.FlagOutputClientAgentCliError,
|
||||
Default: false,
|
||||
EnvVar: EnvBoundaryClientAgentCliErrorOutput,
|
||||
Usage: "Enables outputting CLI errors encountered for client-agent callbacks.",
|
||||
})
|
||||
|
||||
f.BoolVar(&BoolVar{
|
||||
Name: "skip-client-agent",
|
||||
Target: &c.FlagSkipClientAgent,
|
||||
|
||||
@@ -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