github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/facades/agent/machineactions/shim.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Copyright 2016 Cloudbase Solutions 3 // Licensed under the AGPLv3, see LICENCE file for details. 4 5 package machineactions 6 7 import ( 8 "gopkg.in/juju/names.v2" 9 10 "github.com/juju/juju/apiserver/common" 11 "github.com/juju/juju/apiserver/facade" 12 "github.com/juju/juju/apiserver/params" 13 "github.com/juju/juju/state" 14 ) 15 16 // NewExternalFacade is used for API registration. 17 func NewExternalFacade(st *state.State, res facade.Resources, auth facade.Authorizer) (*Facade, error) { 18 return NewFacade(backendShim{st}, res, auth) 19 } 20 21 type backendShim struct { 22 st *state.State 23 } 24 25 func (shim backendShim) ActionByTag(tag names.ActionTag) (state.Action, error) { 26 m, err := shim.st.Model() 27 if err != nil { 28 return nil, err 29 } 30 31 return m.ActionByTag(tag) 32 } 33 34 func (shim backendShim) FindEntity(tag names.Tag) (state.Entity, error) { 35 return shim.st.FindEntity(tag) 36 } 37 38 func (shim backendShim) TagToActionReceiverFn(findEntity func(names.Tag) (state.Entity, error)) func(string) (state.ActionReceiver, error) { 39 return common.TagToActionReceiverFn(findEntity) 40 } 41 42 func (shim backendShim) ConvertActions(ar state.ActionReceiver, fn common.GetActionsFn) ([]params.ActionResult, error) { 43 return common.ConvertActions(ar, fn) 44 }