github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/facades/controller/actionpruner/pruner.go (about)

     1  // Copyright 2017 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package actionpruner
     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  type API struct {
    14  	*common.ModelWatcher
    15  	st         *state.State
    16  	model      *state.Model
    17  	authorizer facade.Authorizer
    18  }
    19  
    20  func NewAPI(st *state.State, r facade.Resources, auth facade.Authorizer) (*API, error) {
    21  	m, err := st.Model()
    22  	if err != nil {
    23  		return nil, err
    24  	}
    25  
    26  	return &API{
    27  		ModelWatcher: common.NewModelWatcher(m, r, auth),
    28  		st:           st,
    29  		authorizer:   auth,
    30  	}, nil
    31  }
    32  
    33  func (api *API) Prune(p params.ActionPruneArgs) error {
    34  	if !api.authorizer.AuthController() {
    35  		return common.ErrPerm
    36  	}
    37  
    38  	return state.PruneActions(api.st, p.MaxHistoryTime, p.MaxHistoryMB)
    39  }