diff --git a/command/agent.go b/command/agent.go index 1ed96e3ffb..5fa18f16bb 100644 --- a/command/agent.go +++ b/command/agent.go @@ -6,16 +6,11 @@ import ( "io" "net" "net/http" - "time" - "os" "sort" "strings" "sync" - - "github.com/kr/pretty" - "github.com/mitchellh/cli" - "github.com/posener/complete" + "time" "github.com/hashicorp/errwrap" log "github.com/hashicorp/go-hclog" @@ -33,9 +28,13 @@ import ( "github.com/hashicorp/vault/command/agent/sink" "github.com/hashicorp/vault/command/agent/sink/file" "github.com/hashicorp/vault/command/agent/sink/inmem" + "github.com/hashicorp/vault/helper/consts" gatedwriter "github.com/hashicorp/vault/helper/gated-writer" "github.com/hashicorp/vault/helper/logging" "github.com/hashicorp/vault/version" + "github.com/kr/pretty" + "github.com/mitchellh/cli" + "github.com/posener/complete" ) var _ cli.Command = (*AgentCommand)(nil) @@ -381,7 +380,7 @@ func (c *AgentCommand) Run(args []string) int { // Create a muxer and add paths relevant for the lease cache layer mux := http.NewServeMux() - mux.Handle("/v1/agent/cache-clear", leaseCache.HandleCacheClear(ctx)) + mux.Handle(consts.AgentPathCacheClear, leaseCache.HandleCacheClear(ctx)) mux.Handle("/", cache.Handler(ctx, cacheLogger, leaseCache, inmemSink)) diff --git a/command/agent/cache/cache_test.go b/command/agent/cache/cache_test.go index afd4b204ee..169cb69fe1 100644 --- a/command/agent/cache/cache_test.go +++ b/command/agent/cache/cache_test.go @@ -13,17 +13,17 @@ import ( "testing" "time" - "github.com/hashicorp/vault/command/agent/sink/mock" - "github.com/hashicorp/vault/logical" - "github.com/go-test/deep" hclog "github.com/hashicorp/go-hclog" kv "github.com/hashicorp/vault-plugin-secrets-kv" "github.com/hashicorp/vault/api" "github.com/hashicorp/vault/builtin/credential/userpass" + "github.com/hashicorp/vault/command/agent/sink/mock" + "github.com/hashicorp/vault/helper/consts" "github.com/hashicorp/vault/helper/logging" "github.com/hashicorp/vault/helper/namespace" vaulthttp "github.com/hashicorp/vault/http" + "github.com/hashicorp/vault/logical" "github.com/hashicorp/vault/vault" ) @@ -233,7 +233,7 @@ func TestCache_AutoAuthTokenStripping(t *testing.T) { // Create a muxer and add paths relevant for the lease cache layer mux := http.NewServeMux() - mux.Handle("/v1/agent/cache-clear", leaseCache.HandleCacheClear(ctx)) + mux.Handle(consts.AgentPathCacheClear, leaseCache.HandleCacheClear(ctx)) mux.Handle("/", Handler(ctx, cacheLogger, leaseCache, mock.NewSink("testid"))) server := &http.Server{ diff --git a/command/agent/cache_end_to_end_test.go b/command/agent/cache_end_to_end_test.go index df8bc1e72d..dfb8ca63c7 100644 --- a/command/agent/cache_end_to_end_test.go +++ b/command/agent/cache_end_to_end_test.go @@ -263,7 +263,7 @@ func TestCache_UsingAutoAuthToken(t *testing.T) { // Create a muxer and add paths relevant for the lease cache layer mux := http.NewServeMux() - mux.Handle("/v1/agent/cache-clear", leaseCache.HandleCacheClear(ctx)) + mux.Handle(consts.CacheClearPath, leaseCache.HandleCacheClear(ctx)) mux.Handle("/", cache.Handler(ctx, cacheLogger, leaseCache, inmemSink)) server := &http.Server{ diff --git a/helper/consts/agent.go b/helper/consts/agent.go new file mode 100644 index 0000000000..b62962e37e --- /dev/null +++ b/helper/consts/agent.go @@ -0,0 +1,5 @@ +package consts + +// AgentPathCacheClear is the path that the agent will use as its cache-clear +// endpoint. +const AgentPathCacheClear = "/agent/v1/cache-clear"