From da0184f7282bb82c17f88f279e15687f7ae077e6 Mon Sep 17 00:00:00 2001 From: Travis Turner Date: Tue, 31 Oct 2017 13:56:58 -0500 Subject: [PATCH] Adjust comments. Change DefaultSecurityManager to NopSecurityManager. --- cluster.go | 28 ++++++++++++++-------------- handler.go | 10 +++++++--- security_manager.go | 14 +++++++------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/cluster.go b/cluster.go index a746a509f..8860d8405 100644 --- a/cluster.go +++ b/cluster.go @@ -186,7 +186,7 @@ func NewCluster() *Cluster { closing: make(chan struct{}), LogOutput: os.Stderr, - prefect: &DefaultSecurityManager{}, + prefect: &NopSecurityManager{}, } } @@ -228,20 +228,20 @@ func (c *Cluster) NodeSet() []URI { } func (c *Cluster) setState(state string) { - if c.State != state { //only on new state, perform routing change - switch state { - case ClusterStateResizing: - c.prefect.SetRestricted() - case ClusterStateNormal: - c.prefect.SetNormal() - // Don't change routing for these new states - // ClusterStateStarting - // ResizeJobStateRunning - // ResizeJobStateDone - // ResizeJobStateAborted - - } + // Ignore cases where the state hasn't changed. + if state == c.State { + return } + + switch state { + case ClusterStateResizing: + c.prefect.SetRestricted() + case ClusterStateNormal: + c.prefect.SetNormal() + // Don't change routing for these states: + // - ClusterStateStarting + } + c.State = state } diff --git a/handler.go b/handler.go index 808680a54..55b6e91d9 100644 --- a/handler.go +++ b/handler.go @@ -95,25 +95,29 @@ func NewHandler() *Handler { return handler } -// BuildRouters creates a Gorilla Mux http routers for both normal and restricted enpoints. +// BuildRouters creates Gorilla Mux http routers for both normal and restricted endpoints. func BuildRouters(handler *Handler) { + // Normal router. router := mux.NewRouter() loadCommon(router, handler) loadNormal(router, handler) handler.NormalRouter = router + + // Restricted router. router = mux.NewRouter() loadCommon(router, handler) loadRestricted(router, handler) handler.RestrictedRouter = router + handler.SetNormal() } -// SetNormal a method of the SecurityManager interface which provides normal URI routing +// SetNormal is a method of the SecurityManager interface which provides normal URI routing. func (h *Handler) SetNormal() { h.Router = h.NormalRouter } -// SetRestricted a method of the SecurityManager interface which provides restricted URI routing +// SetRestricted is a method of the SecurityManager interface which provides restricted URI routing. func (h *Handler) SetRestricted() { h.Router = h.RestrictedRouter } diff --git a/security_manager.go b/security_manager.go index 88022de03..2acf82986 100644 --- a/security_manager.go +++ b/security_manager.go @@ -1,22 +1,22 @@ package pilosa // SecurityManager provides the ability to limit access to restricted endpoints -// during cluster configuration +// during cluster configuration. type SecurityManager interface { SetRestricted() SetNormal() } -// DefaultSecurityManager provides a no-op implimentation of the SecurityManager interface -type DefaultSecurityManager struct { +// NopSecurityManager provides a no-op implementation of the SecurityManager interface. +type NopSecurityManager struct { } -// SetRestricted no-op -func (sdm *DefaultSecurityManager) SetRestricted() { +// SetRestricted no-op. +func (sdm *NopSecurityManager) SetRestricted() { } -// SetNormal no-op -func (sdm *DefaultSecurityManager) SetNormal() { +// SetNormal no-op. +func (sdm *NopSecurityManager) SetNormal() { }