Adjust comments. Change DefaultSecurityManager to NopSecurityManager.

This commit is contained in:
Travis Turner 2017-10-31 13:56:58 -05:00
parent fc829b08e8
commit da0184f728
No known key found for this signature in database
GPG key ID: 7F08008DFD9314C9
3 changed files with 28 additions and 24 deletions

View file

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

View file

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

View file

@ -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() {
}