mirror of
https://github.com/hashicorp/vault.git
synced 2026-06-03 22:02:19 -04:00
Remove global name/id. Make only cluster name configurable.
This commit is contained in:
parent
bae3e09071
commit
e5c61509d6
7 changed files with 46 additions and 103 deletions
|
|
@ -187,10 +187,7 @@ func (c *ServerCommand) Run(args []string) int {
|
|||
DisableMlock: config.DisableMlock,
|
||||
MaxLeaseTTL: config.MaxLeaseTTL,
|
||||
DefaultLeaseTTL: config.DefaultLeaseTTL,
|
||||
LocalClusterName: config.LocalClusterName,
|
||||
LocalClusterID: config.LocalClusterID,
|
||||
GlobalClusterName: config.GlobalClusterName,
|
||||
GlobalClusterID: config.GlobalClusterID,
|
||||
ClusterName: config.ClusterName,
|
||||
}
|
||||
|
||||
// Initialize the separate HA physical backend, if it exists
|
||||
|
|
|
|||
|
|
@ -34,11 +34,7 @@ type Config struct {
|
|||
DefaultLeaseTTL time.Duration `hcl:"-"`
|
||||
DefaultLeaseTTLRaw string `hcl:"default_lease_ttl"`
|
||||
|
||||
LocalClusterName string `hcl:"local_cluster_name"`
|
||||
LocalClusterID string `hcl:"local_cluster_id"`
|
||||
|
||||
GlobalClusterName string `hcl:"global_cluster_name"`
|
||||
GlobalClusterID string `hcl:"global_cluster_id"`
|
||||
ClusterName string `hcl:"cluster_name"`
|
||||
}
|
||||
|
||||
// DevConfig is a Config that is used for dev mode of Vault.
|
||||
|
|
@ -283,10 +279,7 @@ func ParseConfig(d string) (*Config, error) {
|
|||
"telemetry",
|
||||
"default_lease_ttl",
|
||||
"max_lease_ttl",
|
||||
"local_cluster_name",
|
||||
"local_cluster_id",
|
||||
"global_cluster_name",
|
||||
"global_cluster_id",
|
||||
"cluster_name",
|
||||
|
||||
// TODO: Remove in 0.6.0
|
||||
// Deprecated keys
|
||||
|
|
|
|||
|
|
@ -115,54 +115,37 @@ func getSysHealth(core *vault.Core, r *http.Request) (int, *HealthResponse, erro
|
|||
}
|
||||
|
||||
// Fetch the local cluster name and identifier
|
||||
var localClusterName, localClusterID string
|
||||
localCluster, err := core.Cluster(true)
|
||||
var clusterName, clusterID string
|
||||
cluster, err := core.Cluster()
|
||||
|
||||
// Don't set the cluster details in the health status when Vault is sealed
|
||||
if err != nil && err.Error() != "Vault is sealed" {
|
||||
return http.StatusInternalServerError, nil, err
|
||||
}
|
||||
if localCluster != nil {
|
||||
localClusterName = localCluster.Name
|
||||
localClusterID = localCluster.ID
|
||||
}
|
||||
|
||||
// Fetch the global cluster name and identifier
|
||||
var globalClusterName, globalClusterID string
|
||||
globalCluster, err := core.Cluster(false)
|
||||
|
||||
// Don't set the cluster details in the health status when Vault is sealed
|
||||
if err != nil && err.Error() != "Vault is sealed" {
|
||||
return http.StatusInternalServerError, nil, err
|
||||
}
|
||||
if globalCluster != nil {
|
||||
globalClusterName = globalCluster.Name
|
||||
globalClusterID = globalCluster.ID
|
||||
if cluster != nil {
|
||||
clusterName = cluster.Name
|
||||
clusterID = cluster.ID
|
||||
}
|
||||
|
||||
// Format the body
|
||||
body := &HealthResponse{
|
||||
Initialized: init,
|
||||
Sealed: sealed,
|
||||
Standby: standby,
|
||||
ServerTimeUTC: time.Now().UTC().Unix(),
|
||||
Version: version.GetVersion().String(),
|
||||
LocalClusterName: localClusterName,
|
||||
LocalClusterID: localClusterID,
|
||||
GlobalClusterName: globalClusterName,
|
||||
GlobalClusterID: globalClusterID,
|
||||
Initialized: init,
|
||||
Sealed: sealed,
|
||||
Standby: standby,
|
||||
ServerTimeUTC: time.Now().UTC().Unix(),
|
||||
Version: version.GetVersion().String(),
|
||||
ClusterName: clusterName,
|
||||
ClusterID: clusterID,
|
||||
}
|
||||
return code, body, nil
|
||||
}
|
||||
|
||||
type HealthResponse struct {
|
||||
Initialized bool `json:"initialized"`
|
||||
Sealed bool `json:"sealed"`
|
||||
Standby bool `json:"standby"`
|
||||
ServerTimeUTC int64 `json:"server_time_utc"`
|
||||
Version string `json:"version"`
|
||||
LocalClusterName string `json:"local_cluster_name"`
|
||||
LocalClusterID string `json:"local_cluster_id"`
|
||||
GlobalClusterName string `json:"global_cluster_name"`
|
||||
GlobalClusterID string `json:"global_cluster_id"`
|
||||
Initialized bool `json:"initialized"`
|
||||
Sealed bool `json:"sealed"`
|
||||
Standby bool `json:"standby"`
|
||||
ServerTimeUTC int64 `json:"server_time_utc"`
|
||||
Version string `json:"version"`
|
||||
ClusterName string `json:"cluster_name"`
|
||||
ClusterID string `json:"cluster_id"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,10 +31,8 @@ func TestSysHealth_get(t *testing.T) {
|
|||
testResponseBody(t, resp, &actual)
|
||||
expected["server_time_utc"] = actual["server_time_utc"]
|
||||
expected["version"] = actual["version"]
|
||||
expected["local_cluster_name"] = actual["local_cluster_name"]
|
||||
expected["local_cluster_id"] = actual["local_cluster_id"]
|
||||
expected["global_cluster_name"] = actual["global_cluster_name"]
|
||||
expected["global_cluster_id"] = actual["global_cluster_id"]
|
||||
expected["cluster_name"] = actual["cluster_name"]
|
||||
expected["cluster_id"] = actual["cluster_id"]
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Fatalf("bad: expected:%#v\nactual:%#v", expected, actual)
|
||||
}
|
||||
|
|
@ -56,10 +54,8 @@ func TestSysHealth_get(t *testing.T) {
|
|||
testResponseBody(t, resp, &actual)
|
||||
expected["server_time_utc"] = actual["server_time_utc"]
|
||||
expected["version"] = actual["version"]
|
||||
expected["local_cluster_name"] = actual["local_cluster_name"]
|
||||
expected["local_cluster_id"] = actual["local_cluster_id"]
|
||||
expected["global_cluster_name"] = actual["global_cluster_name"]
|
||||
expected["global_cluster_id"] = actual["global_cluster_id"]
|
||||
expected["cluster_name"] = actual["cluster_name"]
|
||||
expected["cluster_id"] = actual["cluster_id"]
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Fatalf("bad: expected:%#v\nactual:%#v", expected, actual)
|
||||
}
|
||||
|
|
@ -90,10 +86,8 @@ func TestSysHealth_customcodes(t *testing.T) {
|
|||
|
||||
expected["server_time_utc"] = actual["server_time_utc"]
|
||||
expected["version"] = actual["version"]
|
||||
expected["local_cluster_name"] = actual["local_cluster_name"]
|
||||
expected["local_cluster_id"] = actual["local_cluster_id"]
|
||||
expected["global_cluster_name"] = actual["global_cluster_name"]
|
||||
expected["global_cluster_id"] = actual["global_cluster_id"]
|
||||
expected["cluster_name"] = actual["cluster_name"]
|
||||
expected["cluster_id"] = actual["cluster_id"]
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Fatalf("bad: expected:%#v\nactual:%#v", expected, actual)
|
||||
}
|
||||
|
|
@ -119,10 +113,8 @@ func TestSysHealth_customcodes(t *testing.T) {
|
|||
testResponseBody(t, resp, &actual)
|
||||
expected["server_time_utc"] = actual["server_time_utc"]
|
||||
expected["version"] = actual["version"]
|
||||
expected["local_cluster_name"] = actual["local_cluster_name"]
|
||||
expected["local_cluster_id"] = actual["local_cluster_id"]
|
||||
expected["global_cluster_name"] = actual["global_cluster_name"]
|
||||
expected["global_cluster_id"] = actual["global_cluster_id"]
|
||||
expected["cluster_name"] = actual["cluster_name"]
|
||||
expected["cluster_id"] = actual["cluster_id"]
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Fatalf("bad: expected:%#v\nactual:%#v", expected, actual)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@ func (c *Core) setupCluster() error {
|
|||
}
|
||||
|
||||
// Generate a clusterID
|
||||
var err error
|
||||
clusterID, err := uuid.GenerateUUID()
|
||||
if err != nil {
|
||||
c.logger.Printf("[ERR] core: failed to generate cluster identifier: %v", err)
|
||||
|
|
|
|||
|
|
@ -4,19 +4,11 @@ import "testing"
|
|||
|
||||
func TestCluster(t *testing.T) {
|
||||
c, _, _ := TestCoreUnsealed(t)
|
||||
cluster, err := c.Cluster(true)
|
||||
cluster, err := c.Cluster()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cluster == nil || cluster.Name == "" || cluster.ID == "" {
|
||||
t.Fatalf("local cluster information missing: cluster:%#v", cluster)
|
||||
}
|
||||
|
||||
cluster, err = c.Cluster(false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cluster == nil || cluster.Name == "" || cluster.ID == "" {
|
||||
t.Fatalf("global cluster information missing: cluster:%#v", cluster)
|
||||
t.Fatalf("cluster information missing: cluster:%#v", cluster)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -219,11 +219,7 @@ type Core struct {
|
|||
// cachingDisabled indicates whether caches are disabled
|
||||
cachingDisabled bool
|
||||
|
||||
localClusterName string
|
||||
localClusterID string
|
||||
|
||||
globalClusterName string
|
||||
globalClusterID string
|
||||
clusterName string
|
||||
}
|
||||
|
||||
// CoreConfig is used to parameterize a core
|
||||
|
|
@ -259,13 +255,7 @@ type CoreConfig struct {
|
|||
|
||||
MaxLeaseTTL time.Duration `json:"max_lease_ttl" structs:"max_lease_ttl" mapstructure:"max_lease_ttl"`
|
||||
|
||||
LocalClusterName string `json:"local_cluster_name" structs:"local_cluster_name" mapstructure:"local_cluster_name"`
|
||||
|
||||
LocalClusterID string `json:"local_cluster_id" structs:"local_cluster_id" mapstructure:"local_cluster_id"`
|
||||
|
||||
GlobalClusterName string `json:"global_cluster_name" structs:"global_cluster_name" mapstructure:"global_cluster_name"`
|
||||
|
||||
GlobalClusterID string `json:"global_cluster_id" structs:"global_cluster_id" mapstructure:"global_cluster_id"`
|
||||
ClusterName string `json:"cluster_name" structs:"cluster_name" mapstructure:"cluster_name"`
|
||||
}
|
||||
|
||||
// NewCore is used to construct a new core
|
||||
|
|
@ -335,21 +325,18 @@ func NewCore(conf *CoreConfig) (*Core, error) {
|
|||
|
||||
// Setup the core
|
||||
c := &Core{
|
||||
advertiseAddr: conf.AdvertiseAddr,
|
||||
physical: conf.Physical,
|
||||
seal: conf.Seal,
|
||||
barrier: barrier,
|
||||
router: NewRouter(),
|
||||
sealed: true,
|
||||
standby: true,
|
||||
logger: conf.Logger,
|
||||
defaultLeaseTTL: conf.DefaultLeaseTTL,
|
||||
maxLeaseTTL: conf.MaxLeaseTTL,
|
||||
cachingDisabled: conf.DisableCache,
|
||||
localClusterName: conf.LocalClusterName,
|
||||
localClusterID: conf.LocalClusterID,
|
||||
globalClusterName: conf.GlobalClusterName,
|
||||
globalClusterID: conf.GlobalClusterID,
|
||||
advertiseAddr: conf.AdvertiseAddr,
|
||||
physical: conf.Physical,
|
||||
seal: conf.Seal,
|
||||
barrier: barrier,
|
||||
router: NewRouter(),
|
||||
sealed: true,
|
||||
standby: true,
|
||||
logger: conf.Logger,
|
||||
defaultLeaseTTL: conf.DefaultLeaseTTL,
|
||||
maxLeaseTTL: conf.MaxLeaseTTL,
|
||||
cachingDisabled: conf.DisableCache,
|
||||
clusterName: conf.ClusterName,
|
||||
}
|
||||
|
||||
if conf.HAPhysical != nil && conf.HAPhysical.HAEnabled() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue