github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/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/params" 9 "github.com/juju/juju/state" 10 ) 11 12 func init() { 13 common.RegisterStandardFacade("StatusHistory", 2, NewAPI) 14 } 15 16 // API is the concrete implementation of the Pruner endpoint.. 17 type API struct { 18 st *state.State 19 authorizer common.Authorizer 20 } 21 22 // NewAPI returns an API Instance. 23 func NewAPI(st *state.State, _ *common.Resources, auth common.Authorizer) (*API, error) { 24 return &API{ 25 st: st, 26 authorizer: auth, 27 }, nil 28 } 29 30 // Prune endpoint removes status history entries until 31 // only the N newest records per unit remain. 32 func (api *API) Prune(p params.StatusHistoryPruneArgs) error { 33 if !api.authorizer.AuthModelManager() { 34 return common.ErrPerm 35 } 36 return state.PruneStatusHistory(api.st, p.MaxLogsPerEntity) 37 }