Skip to content

Commit

Permalink
Move ReplicationState to consts
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferai committed Feb 16, 2017
1 parent bc16792 commit e350a16
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 deletions.
20 changes: 20 additions & 0 deletions helper/consts/replication.go
Original file line number Diff line number Diff line change
@@ -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"
}
19 changes: 0 additions & 19 deletions logical/logical.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
12 changes: 8 additions & 4 deletions logical/system_view.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -32,7 +36,7 @@ type SystemView interface {
CachingDisabled() bool

// ReplicationState indicates the state of cluster replication
ReplicationState() ReplicationState
ReplicationState() consts.ReplicationState
}

type StaticSystemView struct {
Expand All @@ -42,7 +46,7 @@ type StaticSystemView struct {
TaintedVal bool
CachingDisabledVal bool
Primary bool
ReplicationStateVal ReplicationState
ReplicationStateVal consts.ReplicationState
}

func (d StaticSystemView) DefaultLeaseTTL() time.Duration {
Expand All @@ -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
}
3 changes: 2 additions & 1 deletion vault/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions vault/dynamic_system_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vault
import (
"time"

"github.com/hashicorp/vault/helper/consts"
"github.com/hashicorp/vault/logical"
)

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e350a16

Please sign in to comment.