diff --git a/helper/consts/replication.go b/helper/consts/replication.go new file mode 100644 index 000000000000..62bbcb363d1e --- /dev/null +++ b/helper/consts/replication.go @@ -0,0 +1,20 @@ +package consts + +type ReplicationState uint32 + +const ( + ReplicationDisabled ReplicationState = iota + ReplicationPrimary + ReplicationSecondary +) + +func (r ReplicationState) String() string { + switch r { + case ReplicationSecondary: + return "secondary" + case ReplicationPrimary: + return "primary" + } + + return "disabled" +} diff --git a/logical/logical.go b/logical/logical.go index 9234bfe6d69f..3b66fba51fdf 100644 --- a/logical/logical.go +++ b/logical/logical.go @@ -80,22 +80,3 @@ type Paths struct { // indicates that these paths should not be replicated LocalStorage []string } - -type ReplicationState uint32 - -const ( - ReplicationDisabled ReplicationState = iota - ReplicationPrimary - ReplicationSecondary -) - -func (r ReplicationState) String() string { - switch r { - case ReplicationSecondary: - return "secondary" - case ReplicationPrimary: - return "primary" - } - - return "disabled" -} diff --git a/logical/system_view.go b/logical/system_view.go index 836c865c2564..d769397dfcc9 100644 --- a/logical/system_view.go +++ b/logical/system_view.go @@ -1,6 +1,10 @@ package logical -import "time" +import ( + "time" + + "github.com/hashicorp/vault/helper/consts" +) // SystemView exposes system configuration information in a safe way // for logical backends to consume @@ -32,7 +36,7 @@ type SystemView interface { CachingDisabled() bool // ReplicationState indicates the state of cluster replication - ReplicationState() ReplicationState + ReplicationState() consts.ReplicationState } type StaticSystemView struct { @@ -42,7 +46,7 @@ type StaticSystemView struct { TaintedVal bool CachingDisabledVal bool Primary bool - ReplicationStateVal ReplicationState + ReplicationStateVal consts.ReplicationState } func (d StaticSystemView) DefaultLeaseTTL() time.Duration { @@ -65,6 +69,6 @@ func (d StaticSystemView) CachingDisabled() bool { return d.CachingDisabledVal } -func (d StaticSystemView) ReplicationState() ReplicationState { +func (d StaticSystemView) ReplicationState() consts.ReplicationState { return d.ReplicationStateVal } diff --git a/vault/core.go b/vault/core.go index 4221a9001685..f3ffcf5a8c91 100644 --- a/vault/core.go +++ b/vault/core.go @@ -23,6 +23,7 @@ import ( "github.com/hashicorp/go-multierror" "github.com/hashicorp/go-uuid" "github.com/hashicorp/vault/audit" + "github.com/hashicorp/vault/helper/consts" "github.com/hashicorp/vault/helper/errutil" "github.com/hashicorp/vault/helper/jsonutil" "github.com/hashicorp/vault/helper/logformat" @@ -310,7 +311,7 @@ type Core struct { // replicationState keeps the current replication state cached for quick // lookup - replicationState logical.ReplicationState + replicationState consts.ReplicationState } // CoreConfig is used to parameterize a core diff --git a/vault/dynamic_system_view.go b/vault/dynamic_system_view.go index e02a061ce397..80b663b951ad 100644 --- a/vault/dynamic_system_view.go +++ b/vault/dynamic_system_view.go @@ -3,6 +3,7 @@ package vault import ( "time" + "github.com/hashicorp/vault/helper/consts" "github.com/hashicorp/vault/logical" ) @@ -76,8 +77,8 @@ func (d dynamicSystemView) CachingDisabled() bool { } // Checks if this is a primary Vault instance. -func (d dynamicSystemView) ReplicationState() logical.ReplicationState { - var state logical.ReplicationState +func (d dynamicSystemView) ReplicationState() consts.ReplicationState { + var state consts.ReplicationState d.core.clusterParamsLock.RLock() state = d.core.replicationState d.core.clusterParamsLock.RUnlock()