github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/apiserver/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 "github.com/juju/juju/apiserver/common" 9 "github.com/juju/juju/apiserver/facade" 10 "github.com/juju/juju/state" 11 ) 12 13 // This file contains untested shims to let us wrap state in a sensible 14 // interface and avoid writing tests that depend on mongodb. If you were 15 // to change any part of it so that it were no longer *obviously* and 16 // *trivially* correct, you would be Doing It Wrong. 17 18 func init() { 19 common.RegisterStandardFacade("Backups", 1, newAPI) 20 } 21 22 type stateShim struct { 23 *state.State 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 func newAPI(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*API, error) { 36 return NewAPI(&stateShim{st}, resources, authorizer) 37 }