github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/apiserver/statushistory/pruner.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package statushistory
     5  
     6  import (
     7  	"github.com/juju/juju/apiserver/common"
     8  	"github.com/juju/juju/apiserver/facade"
     9  	"github.com/juju/juju/apiserver/params"
    10  	"github.com/juju/juju/state"
    11  )
    12  
    13  func init() {
    14  	common.RegisterStandardFacade("StatusHistory", 2, NewAPI)
    15  }
    16  
    17  // API is the concrete implementation of the Pruner endpoint..
    18  type API struct {
    19  	st         *state.State
    20  	authorizer facade.Authorizer
    21  }
    22  
    23  // NewAPI returns an API Instance.
    24  func NewAPI(st *state.State, _ facade.Resources, auth facade.Authorizer) (*API, error) {
    25  	return &API{
    26  		st:         st,
    27  		authorizer: auth,
    28  	}, nil
    29  }
    30  
    31  // Prune endpoint removes status history entries until
    32  // only the ones newer than now - p.MaxHistoryTime remain and
    33  // the history is smaller than p.MaxHistoryMB.
    34  func (api *API) Prune(p params.StatusHistoryPruneArgs) error {
    35  	if !api.authorizer.AuthModelManager() {
    36  		return common.ErrPerm
    37  	}
    38  	return state.PruneStatusHistory(api.st, p.MaxHistoryTime, p.MaxHistoryMB)
    39  }