agent/caching: use const for cache-clear path (#6271)

This commit is contained in:
Calvin Leung Huang 2019-02-21 14:53:34 -08:00 committed by GitHub
parent 05d4f97882
commit 2e0bef841a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 12 deletions

View File

@ -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))

View File

@ -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{

View File

@ -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{

5
helper/consts/agent.go Normal file
View File

@ -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"