github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/facades/client/backups/shim.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package backups 5 6 import ( 7 "github.com/juju/errors" 8 "gopkg.in/juju/names.v2" 9 10 "github.com/juju/juju/apiserver/facade" 11 "github.com/juju/juju/state" 12 ) 13 14 // This file contains untested shims to let us wrap state in a sensible 15 // interface and avoid writing tests that depend on mongodb. If you were 16 // to change any part of it so that it were no longer *obviously* and 17 // *trivially* correct, you would be Doing It Wrong. 18 19 // TODO - CAAS(ericclaudejones): This should contain state alone, model will be 20 // removed once all relevant methods are moved from state to model. 21 type stateShim struct { 22 *state.State 23 *state.Model 24 } 25 26 // MachineSeries implements backups.Backend 27 func (s *stateShim) MachineSeries(id string) (string, error) { 28 m, err := s.State.Machine(id) 29 if err != nil { 30 return "", errors.Trace(err) 31 } 32 return m.Series(), nil 33 } 34 35 // NewFacadeV2 provides the required signature for version 2 facade registration. 36 func NewFacadeV2(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*APIv2, error) { 37 model, err := st.Model() 38 if err != nil { 39 return nil, errors.Trace(err) 40 } 41 return NewAPIv2(&stateShim{st, model}, resources, authorizer) 42 } 43 44 // NewFacade provides the required signature for facade registration. 45 func NewFacade(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*API, error) { 46 model, err := st.Model() 47 if err != nil { 48 return nil, errors.Trace(err) 49 } 50 return NewAPI(&stateShim{st, model}, resources, authorizer) 51 } 52 53 // ControllerTag disambiguates the ControllerTag method pending further 54 // refactoring to separate model functionality from state functionality. 55 func (s *stateShim) ControllerTag() names.ControllerTag { 56 return s.State.ControllerTag() 57 } 58 59 // ModelTag disambiguates the ControllerTag method pending further refactoring 60 // to separate model functionality from state functionality. 61 func (s *stateShim) ModelTag() names.ModelTag { 62 return s.Model.ModelTag() 63 }